Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Document-Processing-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,7 @@
<a href="/document-processing/pdf/conversions/html-to-pdf/net/Convert-HTML-to-PDF-in-GCP">Google Cloud Platform (GCP)</a>
<ul>
<li>
<a href="/document-processing/pdf/pdf-library/net/Convert-HTML-to-PDF-in-Google-App-Engine">Google App Engine</a>
<a href="/document-processing/pdf/conversions/html-to-pdf/net/Convert-HTML-to-PDF-in-Google-App-Engine">Google App Engine</a>
</li>
</ul>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ documentation: UG

In PDF, hyperlinks can be added to allow the users to navigate to another part of PDF file, web page or any other external content. Essential<sup>&reg;</sup> PDF provides support for all these types of hyperlink.

To quickly get started with working with hyperlinks in PDF documents using the Syncfusion<sup>&reg;</sup> PDF library for .NET, refer to this video tutorial:
{% youtube "https://youtu.be/g6HhVg2Fbd8?si=1WFL_6RCfRQvZhKb" %}

## Working with Web navigation

You can navigate to specified URL from a PDF document by using the [PdfTextWebLink](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Interactive.PdfTextWebLink.html) class.
Expand Down
130 changes: 130 additions & 0 deletions Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,136 @@ doc.Close(True)

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Images/Paginate-an-image-in-PDF-document).

## Clipping and graphics state

This example demonstrates how to draw an image in a PDF document and apply a clipping region using the [SetClip](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html#methods) method. Clipping restricts drawing to a defined area, allowing partial rendering of content. The code also uses [Save](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html#methods) and [Restore](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html#methods) methods of [PdfGraphics](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html) to manage the graphics state, enabling temporary clipping and restoring the full drawing area afterward.

{% tabs %}

{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Program.cs" %}

using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;

// Create a new PDF document
using (PdfDocument document = new PdfDocument())
{
// Add a page to the document
PdfPage page = document.Pages.Add();
// Get the graphics object for the page
PdfGraphics graphics = page.Graphics;
// Open the image file as a stream
using FileStream imageStream = new FileStream(Path.GetFullPath("Input.png"), FileMode.Open, FileAccess.Read);
// Load the image from the stream
PdfBitmap image = new PdfBitmap(imageStream);

// Save the current graphics state (to restore later)
PdfGraphicsState state = graphics.Save();

// Define a rectangular clipping region
RectangleF clipRect = new RectangleF(50, 50, 200, 100);
graphics.SetClip(clipRect);

// Draw the image — only the part within the clipping region will be visible
graphics.DrawImage(image, new RectangleF(40, 60, 150, 80));

// Restore the graphics state to remove the clipping region
graphics.Restore(state);
// Draw the image again — this time the full image will be visible
graphics.DrawImage(image, new RectangleF(60, 160, 150, 80));

// Save the PDF document
document.Save("Output.pdf");
}

{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}

using System.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;

// Create a new PDF document
using (PdfDocument document = new PdfDocument())
{
// Add a page to the document
PdfPage page = document.Pages.Add();
// Get the graphics object for the page
PdfGraphics graphics = page.Graphics;
// Open the image file as a stream
using FileStream imageStream = new FileStream(Path.GetFullPath("Input.png"), FileMode.Open, FileAccess.Read);
// Load the image from the stream
PdfBitmap image = new PdfBitmap(imageStream);

// Save the current graphics state (to restore later)
PdfGraphicsState state = graphics.Save();

// Define a rectangular clipping region
RectangleF clipRect = new RectangleF(50, 50, 200, 100);
graphics.SetClip(clipRect);

// Draw the image — only the part within the clipping region will be visible
graphics.DrawImage(image, new RectangleF(40, 60, 150, 80));

// Restore the graphics state to remove the clipping region
graphics.Restore(state);
// Draw the image again — this time the full image will be visible
graphics.DrawImage(image, new RectangleF(60, 160, 150, 80));

// Save the PDF document
document.Save("Output.pdf");
}

{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}

Imports System.Drawing
Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics

' Create a new PDF document
Using document As New PdfDocument()
' Add a page to the document
Dim page As PdfPage = document.Pages.Add()

' Get the graphics object for the page
Dim graphics As PdfGraphics = page.Graphics

' Open the image file as a stream
Using imageStream As New FileStream(Path.GetFullPath("Input.png"), FileMode.Open, FileAccess.Read)
' Load the image from the stream
Dim image As New PdfBitmap(imageStream)

' Save the current graphics state (to restore later)
Dim state As PdfGraphicsState = graphics.Save()

' Define a rectangular clipping region
Dim clipRect As New RectangleF(50, 50, 200, 100)
graphics.SetClip(clipRect)

' Draw the image — only the part within the clipping region will be visible
graphics.DrawImage(image, New RectangleF(40, 60, 150, 80))

' Restore the graphics state to remove the clipping region
graphics.Restore(state)

' Draw the image again — this time the full image will be visible
graphics.DrawImage(image, New RectangleF(60, 160, 150, 80))
End Using

' Save the PDF document
document.Save("Output.pdf")
End Using

{% endhighlight %}

{% endtabs %}

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Images/Clipping-and-graphics-state/.NET).

## Applying transparency and rotation to the image

You can add transparency and rotation to the image using [SetTransparency](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html#Syncfusion_Pdf_Graphics_PdfGraphics_SetTransparency_System_Single_) and [RotateTransform](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html#Syncfusion_Pdf_Graphics_PdfGraphics_RotateTransform_System_Single_) methods of [PdfGraphics](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html) respectively. This is explained in the below code snippet.
Expand Down
140 changes: 111 additions & 29 deletions Document-Processing/PDF/PDF-Library/NET/Working-with-Portfolio.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ PDF Portfolios allows the user to bring together content from a variety of sourc

## Creating a PDF portfolio

You can create a portfolio using [PdfPortfolioInformation](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.PdfPortfolioInformation.html) class and attach a variety of documents using [PdfAttachment](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Interactive.PdfAttachment.html) class. The following code example illustrates this.
A PDF portfolio enables the embedding of multiple files within a single PDF container, with each file represented as a **PdfAttachment**. Attachments can include metadata such as file name, description, creation and modification dates, MIME type, and a relationship type. Use the [PdfAttachment](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Interactive.PdfAttachment.html) class to define each embedded file, while portfolio behavior such as specifying a startup document is configured through the documents [PdfPortfolioInformation](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.PdfPortfolioInformation.html).

The following code example illustrates this.

{% tabs %}

Expand All @@ -28,11 +30,23 @@ document.PortfolioInformation = new PdfPortfolioInformation();
//Set the view mode of the portfolio
document.PortfolioInformation.ViewMode = PdfPortfolioViewMode.Tile;

//Create the attachment
FileStream pdfStream = new FileStream("CorporateBrochure.pdf", FileMode.Open, FileAccess.Read);
// Create a new PDF attachment using the file stream
PdfAttachment pdfFile = new PdfAttachment("CorporateBrochure.pdf", pdfStream);
// Set the name of the attachment file
pdfFile.FileName = "CorporateBrochure.pdf";
//Set the startup document to view
// Provide a description for the attachment
pdfFile.Description = "This is a PDF document";
// Set the creation date of the attachment
pdfFile.CreationDate = DateTime.Now;
// Specify the MIME type of the attachment (important for identifying file type)
pdfFile.MimeType = "application/pdf";
// Optionally, set the modification date if needed
pdfFile.ModificationDate = DateTime.Now;
// Optionally, set the relationship (e.g., "Data", "Source", etc.)
pdfFile.Relationship = PdfAttachmentRelationship.Unspecified;
// Add the attachment to the document's attachment collection
document.Attachments.Add(pdfFile);
// Set this attachment as the startup document in the PDF portfolio
document.PortfolioInformation.StartupDocument = pdfFile;

//Add the attachment to the document
Expand All @@ -57,10 +71,23 @@ document.PortfolioInformation = new PdfPortfolioInformation();
//Set the view mode of the portfolio
document.PortfolioInformation.ViewMode = PdfPortfolioViewMode.Tile;

//Create the attachment
PdfAttachment pdfFile = new PdfAttachment("CorporateBrochure.pdf");
// Create a new PDF attachment using the file stream
PdfAttachment pdfFile = new PdfAttachment("CorporateBrochure.pdf", pdfStream);
// Set the name of the attachment file
pdfFile.FileName = "CorporateBrochure.pdf";
//Set the startup document to view
// Provide a description for the attachment
pdfFile.Description = "This is a PDF document";
// Set the creation date of the attachment
pdfFile.CreationDate = DateTime.Now;
// Specify the MIME type of the attachment (important for identifying file type)
pdfFile.MimeType = "application/pdf";
// Optionally, set the modification date if needed
pdfFile.ModificationDate = DateTime.Now;
// Optionally, set the relationship (e.g., "Data", "Source", etc.)
pdfFile.Relationship = PdfAttachmentRelationship.Unspecified;
// Add the attachment to the document's attachment collection
document.Attachments.Add(pdfFile);
// Set this attachment as the startup document in the PDF portfolio
document.PortfolioInformation.StartupDocument = pdfFile;

//Add the attachment to the document
Expand All @@ -85,13 +112,27 @@ document.PortfolioInformation = New PdfPortfolioInformation()
'Set the view mode of the portfolio
document.PortfolioInformation.ViewMode = PdfPortfolioViewMode.Tile

'Create the attachment
Dim pdfFile As New PdfAttachment("CorporateBrochure.pdf")
' Load the PDF file stream to be attached
Dim pdfStream As New FileStream("CorporateBrochure.pdf", FileMode.Open, FileAccess.Read)

' Create a new PDF attachment using the file stream
Dim pdfFile As New PdfAttachment("CorporateBrochure.pdf", pdfStream)
' Set the name of the attachment file
pdfFile.FileName = "CorporateBrochure.pdf"
'Set the startup document to view
' Provide a description for the attachment
pdfFile.Description = "This is a PDF document"
' Set the creation date of the attachment
pdfFile.CreationDate = DateTime.Now
' Specify the MIME type of the attachment (important for identifying file type)
pdfFile.MimeType = "application/pdf"
' Optionally, set the modification date if needed
pdfFile.ModificationDate = DateTime.Now
' Optionally, set the relationship (e.g., "Data", "Source", etc.)
pdfFile.Relationship = PdfAttachmentRelationship.Unspecified
' Set this attachment as the startup document in the PDF portfolio
document.PortfolioInformation.StartupDocument = pdfFile

'Add the attachment to the document
' Add the attachment to the document's attachment collection
document.Attachments.Add(pdfFile)

'Save and close the document.
Expand All @@ -106,7 +147,9 @@ You can download a complete working sample from [GitHub](https://github.com/Sync

## Extracting file from PDF Portfolio

The Essential<sup>&reg;</sup> PDF provides support for extracting the files from the PDF Portfolio using [Attachments](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Parsing.PdfLoadedDocument.html#Syncfusion_Pdf_Parsing_PdfLoadedDocument_Attachments) property of [PdfLoadedDocument](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Parsing.PdfLoadedDocument.html) class and saving the files to the disk. The following code sample shows the steps to extract files from PDF Portfolio.
Files embedded in a PDF portfolio can be extracted using the [Attachments](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Parsing.PdfLoadedDocument.html#Syncfusion_Pdf_Parsing_PdfLoadedDocument_Attachments) property of the [PdfLoadedDocument](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Parsing.PdfLoadedDocument.html) class. Each attachment can be accessed, read, and saved to disk. Metadata such as file name and MIME type can also be retrieved during the extraction process.

The following code demonstrates how to iterate through the attachments in a PDF portfolio.

{% tabs %}

Expand All @@ -118,15 +161,28 @@ using Syncfusion.Pdf.Parsing;
//Load an existing PDF document
PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf");

//Iterate the attachments
// Iterate through all attachments in the PDF document
foreach (PdfAttachment attachment in document.Attachments)
{
//Extract the attachment and save to the disk
FileStream s = new FileStream(attachment.FileName, FileMode.Create);
s.Write(attachment.Data, 0, attachment.Data.Length);
s.Dispose();
// Create a file stream to save the attachment to disk using its original file name
using (FileStream s = new FileStream(attachment.FileName, FileMode.Create))
{
// Write the attachment data to the file
s.Write(attachment.Data, 0, attachment.Data.Length);
}
// Retrieve the MIME type of the attachment (e.g., application/pdf, image/png)
string mimeType = attachment.MimeType;
Console.WriteLine($"Saved: {attachment.FileName}, MIME Type: {mimeType}");
// Optional: Access additional metadata if needed
DateTime creationDate = attachment.CreationDate;
DateTime modificationDate = attachment.ModificationDate;
string description = attachment.Description;
PdfAttachmentRelationship relationship = attachment.Relationship;
// Log or use the metadata as needed
Console.WriteLine($"Description: {description}");
Console.WriteLine($"Created on: {creationDate}, Modified on: {modificationDate}");
Console.WriteLine($"Relationship: {relationship}");
}

//Save and close the document.
document.Save("Sample.pdf");
document.Close(true);
Expand All @@ -141,15 +197,28 @@ using Syncfusion.Pdf.Parsing;
//Load an existing PDF document
PdfLoadedDocument document = new PdfLoadedDocument("Sample.pdf");

//Iterate the attachments
// Iterate through all attachments in the PDF document
foreach (PdfAttachment attachment in document.Attachments)
{
//Extract the attachment and save to the disk
FileStream s = new FileStream(attachment.FileName, FileMode.Create);
s.Write(attachment.Data, 0, attachment.Data.Length);
s.Dispose();
// Create a file stream to save the attachment to disk using its original file name
using (FileStream s = new FileStream(attachment.FileName, FileMode.Create))
{
// Write the attachment data to the file
s.Write(attachment.Data, 0, attachment.Data.Length);
}
// Retrieve the MIME type of the attachment (e.g., application/pdf, image/png)
string mimeType = attachment.MimeType;
Console.WriteLine($"Saved: {attachment.FileName}, MIME Type: {mimeType}");
// Optional: Access additional metadata if needed
DateTime creationDate = attachment.CreationDate;
DateTime modificationDate = attachment.ModificationDate;
string description = attachment.Description;
PdfAttachmentRelationship relationship = attachment.Relationship;
// Log or use the metadata as needed
Console.WriteLine($"Description: {description}");
Console.WriteLine($"Created on: {creationDate}, Modified on: {modificationDate}");
Console.WriteLine($"Relationship: {relationship}");
}

//Save and close the document
document.Save("Output.pdf");
document.Close(true);
Expand All @@ -164,12 +233,25 @@ Imports Syncfusion.Pdf.Parsing
'Load the PDF document
Dim document As New PdfLoadedDocument("Sample.pdf")

'Iterate the attachments
' Iterate through all attachments in the PDF document
For Each attachment As PdfAttachment In document.Attachments
'Extracting the attachment and saving into the local disk
Dim s As New FileStream(attachment.FileName, FileMode.Create)
s.Write(attachment.Data, 0, attachment.Data.Length)
s.Dispose()
' Create a file stream to save the attachment to disk using its original file name
Using s As New FileStream(attachment.FileName, FileMode.Create)
' Write the attachment data to the file
s.Write(attachment.Data, 0, attachment.Data.Length)
End Using
' Retrieve the MIME type of the attachment (e.g., application/pdf, image/png)
Dim mimeType As String = attachment.MimeType
Console.WriteLine($"Saved: {attachment.FileName}, MIME Type: {mimeType}")
' Optional: Access additional metadata if needed
Dim creationDate As DateTime = attachment.CreationDate
Dim modificationDate As DateTime = attachment.ModificationDate
Dim description As String = attachment.Description
Dim relationship As PdfAttachmentRelationship = attachment.Relationship
' Log or use the metadata as needed
Console.WriteLine($"Description: {description}")
Console.WriteLine($"Created on: {creationDate}, Modified on: {modificationDate}")
Console.WriteLine($"Relationship: {relationship}")
Next

'Save and close the document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { DocumentEditorContainer, Ribbon } from '@syncfusion/ej2-documenteditor'

DocumentEditorContainer.Inject(Ribbon);
// Initialize the Document Editor Container with Ribbon mode enabled
var container = new ej.documenteditor.DocumentEditorContainer({
let container: DocumentEditorContainer = new DocumentEditorContainer({
enableToolbar: true,
toolbarMode: 'Ribbon', // Options: 'Ribbon' or 'Toolbar'
height: '590px'
Expand All @@ -57,7 +57,7 @@ import { DocumentEditorContainer, Ribbon } from '@syncfusion/ej2-documenteditor'

DocumentEditorContainer.Inject(Ribbon);
// Initialize the Document Editor Container with Ribbon mode enabled
var container = new ej.documenteditor.DocumentEditorContainer({
let container: DocumentEditorContainer = new DocumentEditorContainer({
enableToolbar: true,
toolbarMode: 'Ribbon', // Options: 'Ribbon' or 'Toolbar'
ribbonLayout: 'Classic', // Options: 'Simplified' or 'Classic'
Expand Down