diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 7e5ded547..17fb69c6c 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -2612,7 +2612,7 @@ Google Cloud Platform (GCP)
diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-HyperLinks.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-HyperLinks.md index c1c7ea535..332504196 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-HyperLinks.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-HyperLinks.md @@ -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® PDF provides support for all these types of hyperlink. +To quickly get started with working with hyperlinks in PDF documents using the Syncfusion® 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. diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md index c95dee8ba..4d004d4f8 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md @@ -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. diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Portfolio.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Portfolio.md index 63960b248..3e6d717a8 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Portfolio.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Portfolio.md @@ -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 %} @@ -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 @@ -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 @@ -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. @@ -106,7 +147,9 @@ You can download a complete working sample from [GitHub](https://github.com/Sync ## Extracting file from PDF Portfolio -The Essential® 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 %} @@ -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); @@ -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); @@ -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 diff --git a/Document-Processing/Word/Word-Processor/javascript-es6/ribbon.md b/Document-Processing/Word/Word-Processor/javascript-es6/ribbon.md index 6b8f4d3ec..8ff607b34 100644 --- a/Document-Processing/Word/Word-Processor/javascript-es6/ribbon.md +++ b/Document-Processing/Word/Word-Processor/javascript-es6/ribbon.md @@ -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' @@ -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'