From 0f04bc7c896e0c67b9ae915c0c9c7b1b4704ada9 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Wed, 8 Oct 2025 12:19:51 +0530 Subject: [PATCH 1/5] 985863-ug: UG documentation feedback for PDF library- Part 2 --- .../NET/Working-with-DigitalSignature.md | 1120 ++++++++++------- 1 file changed, 690 insertions(+), 430 deletions(-) diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-DigitalSignature.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-DigitalSignature.md index df6b82859..381688a3e 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-DigitalSignature.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-DigitalSignature.md @@ -20,6 +20,11 @@ The following code example explains how to add a digital signature to the PDF do {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Add-a-digital-signature-to-the-PDF-document/.NET/Add-a-digital-signature-to-the-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Creates a new PDF document. PdfDocument document = new PdfDocument(); //Adds a new page. @@ -44,23 +49,20 @@ signature.Reason = "I am author of this document."; //Draws the signature image. signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; +//Save the document +document.Save("Output.pdf"); //Close the document. document.Close(true); -//Defining the ContentType for PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Adds a new page @@ -90,6 +92,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Security + 'Creates a new PDF document Dim document As New PdfDocument() 'Adds a new page @@ -129,6 +136,11 @@ The following code example illustrates how to add a digital signature in the PDF {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Add-a-digital-signature-to-the-PDF-document/.NET/Add-a-digital-signature-to-the-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Adds a new page @@ -153,23 +165,20 @@ signature.Reason = "I am author of this document."; //Draws the signature image signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +document.Save("Output.pdf"); +//Close the document. document.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Adds a new page @@ -201,6 +210,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Security + 'Creates a new PDF document Dim document As New PdfDocument() 'Adds a new page @@ -238,9 +252,14 @@ You can add a digital signature to an existing document as follows. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the page PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; @@ -255,23 +274,21 @@ signatureField.Signature.Reason = "I am author of this document"; //Adds the field loadedDocument.Form.Fields.Add(signatureField); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +loadedDocument.Save("Output.pdf"); +//Close the document. loadedDocument.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} - + +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Loads the PDF document with signature field PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the page @@ -295,6 +312,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Loads the PDF document with signature field Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Gets the page @@ -328,6 +351,12 @@ The following code example illustrates how to add digital signature in a PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Add-digital-signature-using-X509Certificate2/.NET/Add-digital-signature-using-X509Certificate2/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Adds a new page @@ -351,25 +380,21 @@ signature.Reason = "I am author of this document."; //Draws the signature image signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -document.Save(stream); -//If the position is not set to '0', then the PDF will be empty -stream.Position = 0; -//Close the document +//Save the document +document.Save("Output.pdf"); +//Close the document. document.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Adds a new page @@ -401,6 +426,12 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Security +Imports System.Security.Cryptography.X509Certificates + 'Creates a new PDF document Dim document As New PdfDocument() 'Adds a new page @@ -442,9 +473,12 @@ You can load the signature field from the existing PDF document using [PdfLoaded {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Signing-an-existing-PDF-document/.NET/Signing-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the first page of the document PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; //Gets the first signature field of the PDF document @@ -455,23 +489,19 @@ FileStream certificateStream = new FileStream("PDF.pfx", FileMode.Open, FileAcce PdfCertificate certificate = new PdfCertificate(certificateStream, "password123"); field.Signature = new PdfSignature(loadedDocument, page, certificate, "Signature", field); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +loadedDocument.Save("Output.pdf"); +//Close the document. loadedDocument.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Loads a PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the first page of the document @@ -492,6 +522,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Loads a PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Gets the first page of the document @@ -522,9 +556,12 @@ You can load the signature field from an existing PDF document using [PdfLoadedS {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the first page of the document PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; //Gets the first signature field of the PDF document @@ -535,23 +572,19 @@ FileStream certificateStream = new FileStream("PDF.pfx", FileMode.Open, FileAcce PdfCertificate certificate = new PdfCertificate(certificateStream, "password123"); field.Signature = new PdfSignature(loadedDocument, page, certificate, "Signature", field); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +loadedDocument.Save("Output.pdf"); +//Close the document. loadedDocument.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Loads a PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the first page of the document @@ -573,7 +606,11 @@ loadedDocument.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Loads a PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Gets the first page of the document @@ -606,43 +643,44 @@ The following code example demonstrates how to check if a signature field is sig {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Check-If-PDF-Is-Signed/.NET/Check-If-PDF-Is-Signed/Program.cs" %} -// Open the signed PDF file for reading -using (FileStream inputFileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read)) -{ - // Load the PDF document - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); +using Syncfusion.Pdf.Parsing; - // Check if the document contains a form with fields - if (loadedDocument.Form == null || loadedDocument.Form.Fields.Count == 0) - { - Console.WriteLine("No signature fields found in the document."); - } - else +// Load the PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); + +// Check if the document contains a form with fields +if (loadedDocument.Form == null || loadedDocument.Form.Fields.Count == 0) +{ + Console.WriteLine("No signature fields found in the document."); +} +else +{ + // Iterate through all fields in the form + foreach (PdfLoadedField field in loadedDocument.Form.Fields) { - // Iterate through all fields in the form - foreach (PdfLoadedField field in loadedDocument.Form.Fields) + // Check if the field is a signature field + PdfLoadedSignatureField signatureField = field as PdfLoadedSignatureField; + if (signatureField != null) { - // Check if the field is a signature field - PdfLoadedSignatureField signatureField = field as PdfLoadedSignatureField; - if (signatureField != null) - { - // Determine whether the signature field is signed or not - string status = signatureField.IsSigned ? "Signed" : "UnSigned"; + // Determine whether the signature field is signed or not + string status = signatureField.IsSigned ? "Signed" : "UnSigned"; - // Output the result for each signature field - Console.WriteLine("Signature Field " + signatureField.Name + " is: " + status); - } + // Output the result for each signature field + Console.WriteLine("Signature Field " + signatureField.Name + " is: " + status); } } - - // Close the document - loadedDocument.Close(true); } +// Close the document +loadedDocument.Close(true); + + {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} + using Syncfusion.Pdf.Parsing; + // Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -675,7 +713,9 @@ using (FileStream inputFileStream = new FileStream("Input.pdf", FileMode.Open, F {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - + +Imports Syncfusion.Pdf.Parsing + ' Load the PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf") @@ -721,19 +761,22 @@ The following code example shows how to sign the PDF document from an external s {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Externally-sign-a-PDF-document/.NET/Externally-sign-a-PDF-document/Program.cs" %} -//Get the stream from the document -FileStream documentStream = new FileStream("PDF_Succinctly.pdf ", FileMode.Open, FileAccess.Read); -//Load the existing PDF document -PdfLoadedDocument document = new PdfLoadedDocument(documentStream); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography; +using System.Security.Cryptography.Pkcs; +using System.Security.Cryptography.X509Certificates; + +//Load the PDF document +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Creates a digital signature PdfSignature signature = new PdfSignature(document, document.Pages[0], null, "DigitalSignature"); signature.ComputeHash += Signature_ComputeHash; -//Save the PDF document to stream -MemoryStream ms = new MemoryStream(); -document.Save(ms); -//Close the PDF document +//Save the document +document.Save("Output.pdf"); +//Close the document. document.Close(true); private static void Signature_ComputeHash1(object sender, PdfSignatureEventArgs ars) @@ -758,6 +801,12 @@ private static void Signature_ComputeHash1(object sender, PdfSignatureEventArgs {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography; +using System.Security.Cryptography.Pkcs; +using System.Security.Cryptography.X509Certificates; //Load existing PDF document PdfLoadedDocument document = new PdfLoadedDocument("PDF_Succinctly.pdf"); @@ -792,6 +841,12 @@ void Signature_ComputeHash(object sender, PdfSignatureEventArgs arguments) {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports System.Security.Cryptography +Imports System.Security.Cryptography.Pkcs +Imports System.Security.Cryptography.X509Certificates + 'Load existing PDF document Dim document As PdfLoadedDocument = New PdfLoadedDocument("PDF_Succinctly.pdf") 'Creates a digital signature @@ -827,16 +882,21 @@ End Sub You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Digital%20Signature/Externally-sign-a-PDF-document/). ### Externally sign the PDF document using IPdfExternalSigner + The following code example shows how to sign the PDF document from external signature using [IPdfExternalSigner](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Security.IPdfExternalSigner.html). {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Externally-sign-the-PDF-document-using-IPdfExternalSigner/.NET/Externally-sign-the-PDF-document/Program.cs" %} -//Get the stream from the document -FileStream documentStream = new FileStream("Input.pdf ", FileMode.Open, FileAccess.Read); -//Load the existing PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using Syncfusion.Drawing; +using System.Security.Cryptography.X509Certificates; +using System.Security.Cryptography; + +//Load the PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Creates a digital signature. PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], null, "Signature"); @@ -853,18 +913,10 @@ List certificates = new List(); certificates.Add(new X509Certificate2(Convert.FromBase64String(PublicCert))); signature.AddExternalSigner(externalSignature, certificates, null); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +loadedDocument.Save("Output.pdf"); +//Close the document. loadedDocument.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); //Create the external signer class and sign the document hash. class ExternalSigner : IPdfExternalSigner @@ -907,6 +959,12 @@ class ExternalSigner : IPdfExternalSigner {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Drawing; +using System.Security.Cryptography.X509Certificates; +using System.Security.Cryptography; + //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -966,6 +1024,12 @@ class ExternalSigner : IPdfExternalSigner {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports System.Security.Cryptography +Imports System.Drawing +Imports System.Security.Cryptography.X509Certificates + 'Load an existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") @@ -1036,11 +1100,18 @@ The following example illustrates the process of adding timestamps to a PDF docu {% highlight c# tabtitle="C# [Cross-platform]" %} -// Get the stream from the input PDF document. -FileStream documentStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using Syncfusion.Drawing; +using System.Security.Cryptography.X509Certificates; +using System.Security.Cryptography; +using Org.BouncyCastle.Tsp; +using System.Net; +using System.Text; +using Org.BouncyCastle.Math; -// Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); +//Load the PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Create a digital signature for the first page of the document. PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], null, "Signature"); @@ -1058,12 +1129,8 @@ List certificates = new List(); certificates.Add(new X509Certificate2(Convert.FromBase64String(PublicCert))); signature.AddExternalSigner(externalSignature, certificates, null); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} +//Save the document +loadedDocument.Save("Output.pdf"); //Close the document. loadedDocument.Close(true); @@ -1071,6 +1138,16 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using Syncfusion.Drawing; +using System.Security.Cryptography.X509Certificates; +using System.Security.Cryptography; +using Org.BouncyCastle.Tsp; +using System.Net; +using System.Text; +using Org.BouncyCastle.Math; + //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -1098,6 +1175,16 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports Syncfusion.Drawing +Imports System.Security.Cryptography.X509Certificates +Imports System.Security.Cryptography +Imports Org.BouncyCastle.Tsp +Imports System.Net +Imports System.Text +Imports Org.BouncyCastle.Math + 'Load an existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") @@ -1388,11 +1475,15 @@ You can create a Long Term validation (LTV) when signing PDF documents externall {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Create-LTV-when-signing-PDF-documents-externally/.NET/Create-LTV-when-signing-PDF-documents-externally/Program.cs" %} - //Get the stream from the document. - FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); + using Syncfusion.Pdf; + using Syncfusion.Pdf.Parsing; + using Syncfusion.Pdf.Security; + using System.Security.Cryptography; + using System.Security.Cryptography.Pkcs; + using System.Security.Cryptography.X509Certificates; - //Load an existing PDF document. - PdfLoadedDocument document = new PdfLoadedDocument(documentStream); + //Load the PDF document + PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the page of the existing PDF document. PdfLoadedPage loadedPage = document.Pages[0] as PdfLoadedPage; @@ -1403,14 +1494,13 @@ You can create a Long Term validation (LTV) when signing PDF documents externall //Hook up the ComputeHash event. signature.ComputeHash += Signature_ComputeHash; - //Save the document into stream - MemoryStream stream = new MemoryStream(); - document.Save(stream); + //Save the document. + document.Save("SignedDocument.pdf"); //Close the document document.Close(true); - //Load an existing PDF stream.. - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream); + //Load an existing PDF stream. + PdfLoadedDocument loadedDocument = new PdfLoadedDocument("SignedDocument.pdf"); //Gets the first signature field of the PDF document PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; @@ -1422,12 +1512,9 @@ You can create a Long Term validation (LTV) when signing PDF documents externall //Create LTV with your public certificates. pdfSignature.CreateLongTermValidity(new List { x509 }); - //Save the PDF document - MemoryStream ms = new MemoryStream(); - loadedDocument.Save(ms); - //If the position is not set to '0' then the PDF will be empty - ms.Position = 0; - //Close the document + //Save the document + loadedDocument.Save("Output.pdf"); + //Close the document. loadedDocument.Close(true); void Signature_ComputeHash(object sender, PdfSignatureEventArgs ars) @@ -1454,6 +1541,13 @@ You can create a Long Term validation (LTV) when signing PDF documents externall {% highlight c# tabtitle="C# [Windows-specific]" %} + using Syncfusion.Pdf; + using Syncfusion.Pdf.Parsing; + using Syncfusion.Pdf.Security; + using System.Security.Cryptography; + using System.Security.Cryptography.Pkcs; + using System.Security.Cryptography.X509Certificates; + //Load an existing PDF document. PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); @@ -1467,12 +1561,12 @@ You can create a Long Term validation (LTV) when signing PDF documents externall signature.ComputeHash += Signature_ComputeHash; //Save the document. - document.Save("SignedDocument"); + document.Save("SignedDocument.pdf"); //Close the document document.Close(true); //Load an existing PDF stream.. - PdfLoadedDocument loadedDocument = new PdfLoadedDocument("SignedDocument"); + PdfLoadedDocument loadedDocument = new PdfLoadedDocument("SignedDocument.pdf"); //Gets the first signature field of the PDF document PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; @@ -1512,6 +1606,13 @@ You can create a Long Term validation (LTV) when signing PDF documents externall {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + Imports Syncfusion.Pdf + Imports Syncfusion.Pdf.Parsing + Imports Syncfusion.Pdf.Security + Imports System.Security.Cryptography + Imports System.Security.Cryptography.Pkcs + Imports System.Security.Cryptography.X509Certificates + ' Load an existing PDF document. Dim document As New PdfLoadedDocument("Input.pdf") @@ -1583,6 +1684,10 @@ The following code example shows how to sign a PDF document with LTA using [Time {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Sign_PDF_with_LTA/.NET/Sign_PDF_with_LTA/Program.cs" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using Syncfusion.Pdf; + //Load existing PDF document. FileStream documentStream1 = new FileStream("PDF_Succinctly.pdf", FileMode.Open, FileAccess.Read); PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream1); @@ -1599,13 +1704,12 @@ signature.TimeStampServer = new TimeStampServer(new Uri("http://timestamping.ens signature.EnableLtv = true; //Save the PDF document. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +loadedDocument.Save("LTV_document.pdf"); //Close the document. loadedDocument.Close(true); //Load existing PDF document. -PdfLoadedDocument ltDocument = new PdfLoadedDocument(stream); +PdfLoadedDocument ltDocument = new PdfLoadedDocument("LTV_document.pdf"); //Load the existing PDF page. PdfLoadedPage lpage = ltDocument.Pages[0] as PdfLoadedPage; @@ -1613,22 +1717,19 @@ PdfLoadedPage lpage = ltDocument.Pages[0] as PdfLoadedPage; PdfSignature timeStamp = new PdfSignature(lpage, "timestamp"); timeStamp.TimeStampServer = new TimeStampServer(new Uri("http://timestamping.ensuredca.com")); -//Save and close the PDF document. -MemoryStream stream1 = new MemoryStream(); -ltDocument.Save(stream1); +//Save the document +ltDocument.Save("Output.pdf"); //Close the document. ltDocument.Close(true); -//Defining the ContentType for pdf file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream1, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using Syncfusion.Pdf; + //Load existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("PDF_Succinctly.pdf"); //Load digital ID with password. @@ -1663,6 +1764,10 @@ ltDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports Syncfusion.Pdf + 'Loads a PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("PDF_Succinctly.pdf") 'Load digital ID with password. @@ -1717,6 +1822,11 @@ The following code example shows how to create a PDF digital signature using the {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Sign_PDF_Windows_Certificate/.NET/Sign_PDF_Windows_Certificate/Program.cs" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using Syncfusion.Pdf; +using System.Security.Cryptography.X509Certificates; + //Initialize the Windows store. X509Store store = new X509Store("MY", StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); @@ -1726,8 +1836,7 @@ X509Certificate2Collection fcollection = (X509Certificate2Collection)collection. X509Certificate2 digitalID = collection[0]; //Load existing PDF document. -FileStream documentStream = new FileStream("PDF_Succinctly.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("PDF_Succinctly.pdf"); //Load X509Certificate2. PdfCertificate certificate = new PdfCertificate(digitalID); @@ -1737,22 +1846,20 @@ PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0 signature.Settings.CryptographicStandard = CryptographicStandard.CADES; signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA512; -//Save the PDF document. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document +loadedDocument.Save("Output.pdf"); //Close the document. loadedDocument.Close(true); -//Defining the ContentType for pdf file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using Syncfusion.Pdf; +using System.Security.Cryptography.X509Certificates; + //Initialize the Windows store. X509Store store = new X509Store("MY", StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); @@ -1781,6 +1888,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports Syncfusion.Pdf +Imports System.Security.Cryptography.X509Certificates + 'Initialize the Windows store. Dim store As X509Store = New X509Store("MY", StoreLocation.CurrentUser) store.Open(OpenFlags.[ReadOnly] Or OpenFlags.OpenExistingOnly) @@ -1820,6 +1932,11 @@ Refer to the following code sample. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Adding-a-signature-validation-appearance-in-a-PDF/.NET/Adding-a-signature-validation-appearance-in-a-PDF/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Adds a new page @@ -1846,23 +1963,20 @@ signature.Reason = "I am author of this document."; //Draws the signature image signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +document.Save("Output.pdf"); +//Close the document. document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Add a new page @@ -1893,6 +2007,11 @@ document.Close( true ); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Security + 'Creates a new PDF document Dim document As New PdfDocument() 'Adds a new page @@ -1934,6 +2053,11 @@ Essential® PDF allows you to add timestamp in the digital signatu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Adding-a-timestamp-in-digital-signature-of-PDF/.NET/Adding-a-timestamp-in-digital-signature-of-PDF/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Adds a new page @@ -1960,23 +2084,20 @@ signature.Reason = "I am author of this document."; //Draws the signature image signature.Appearance.Normal.Graphics.DrawImage(image, 0, 0); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +document.Save("Output.pdf"); +//Close the document. document.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Adds a new page @@ -2011,6 +2132,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Security + 'Creates a new PDF document Dim document As New PdfDocument() 'Adds a new page @@ -2052,6 +2178,9 @@ You can add timestamp to the PDF document using [TimeStampServer](https://help.s {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Adding-a-timestamp-to-PDF-document/.NET/Adding-a-timestamp-to-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Security; + //Create a new pdf document PdfDocument document = new PdfDocument(); //Adds a new page @@ -2062,23 +2191,18 @@ PdfSignature signature = new PdfSignature(page, "Signature"); //Add the time stamp by using the server URI signature.TimeStampServer = new TimeStampServer(new Uri("http://syncfusion.digistamp.com"), "user", "123456"); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +document.Save("Output.pdf"); +//Close the document. document.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Security; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a new page @@ -2097,6 +2221,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Security + 'Creates a new PDF document Dim document As New PdfDocument() 'Adds a new page @@ -2125,9 +2252,12 @@ You can add timestamp to the existing PDF document using [TimeStampServer](https {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Adding-a-timestamp-to-an-existing-PDF/.NET/Adding-a-timestamp-to-an-existing-PDF/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the page PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; @@ -2136,23 +2266,19 @@ PdfSignature signature = new PdfSignature(page, "Signature"); //Add the time stamp by using the server URI signature.TimeStampServer = new TimeStampServer(new Uri("http://syncfusion.digistamp.com"), "user", "123456"); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +loadedDocument.Save("Output.pdf"); +//Close the document. loadedDocument.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Add a new page @@ -2172,6 +2298,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Security + 'Load the PDF document Dim document As New PdfLoadedDocument("Input.pdf") 'Gets the first page of the document @@ -2209,9 +2339,11 @@ You can get the above certificate details from an existing signed PDF document u {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Retrieve-certificate-details-from-an-existing-PDF/.NET/Retrieve-certificate-details-from-an-existing-PDF/Program.cs" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the signature field PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; @@ -2236,6 +2368,9 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the existing signed PDF PdfLoadedDocument loadedDocument = new PdfLoadedDocument("SignedDocument.pdf"); //Load the PDF form @@ -2268,6 +2403,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Load the existing signed PDF Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("../../Signed.pdf") 'Load the PDF form @@ -2314,6 +2452,11 @@ The following code example explains how to create LTV PDF using [EnableLtv](http {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Program.cs" %} + using Syncfusion.Drawing; + using Syncfusion.Pdf; + using Syncfusion.Pdf.Graphics; + using Syncfusion.Pdf.Parsing; + using Syncfusion.Pdf.Security; //Creates a new PDF document. PdfDocument document = new PdfDocument(); @@ -2333,14 +2476,12 @@ The following code example explains how to create LTV PDF using [EnableLtv](http signature.Settings.CryptographicStandard = CryptographicStandard.CADES; signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA256; - //Save the document into stream - MemoryStream stream = new MemoryStream(); - document.Save(stream); + document.Save("SignedDocument.pdf"); //Close the document document.Close(true); //Load an existing PDF stream. - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream); + PdfLoadedDocument loadedDocument = new PdfLoadedDocument("SignedDocument.pdf"); //Gets the first signature field of the PDF document PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; @@ -2349,11 +2490,9 @@ The following code example explains how to create LTV PDF using [EnableLtv](http //Enable LTV on Signature. pdfSignature.EnableLtv = true; - //Save the document into stream - MemoryStream ms = new MemoryStream(); - loadedDocument.Save(ms); - stream.ms = 0; - //Close the document + //Save the document + loadedDocument.Save("Output.pdf"); + //Close the document. loadedDocument.Close(true); @@ -2361,6 +2500,12 @@ The following code example explains how to create LTV PDF using [EnableLtv](http {% highlight c# tabtitle="C# [Windows-specific]" %} + using System.Drawing; + using Syncfusion.Pdf; + using Syncfusion.Pdf.Graphics; + using Syncfusion.Pdf.Parsing; + using Syncfusion.Pdf.Security; + //Creates a new PDF document. PdfDocument document = new PdfDocument(); @@ -2402,6 +2547,12 @@ The following code example explains how to create LTV PDF using [EnableLtv](http {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + Imports System.Drawing + Imports Syncfusion.Pdf + Imports Syncfusion.Pdf.Graphics + Imports Syncfusion.Pdf.Parsing + Imports Syncfusion.Pdf.Security + ' Creates a new PDF document. Dim document As New PdfDocument() @@ -2459,6 +2610,11 @@ The following code example explains how to add a digital signature with [cryptog {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Adding-a-digital-signature-with-CAdES-format/.NET/Adding-a-digital-signature-with-CAdES-format/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a new page @@ -2487,23 +2643,20 @@ signature.Reason = "I am author of this document."; //Draws the signature image signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +document.Save("Output.pdf"); +//Close the document. document.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Adds a new page @@ -2537,6 +2690,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Security + 'Creates a new PDF document Dim document As New PdfDocument() 'Adds a new page @@ -2589,6 +2747,11 @@ The following code example explains how to add a digital signature with various {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Add-digital-signature-with-digest-algorithm/.NET/Add-digital-signature-with-digest-algorithm/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a new page @@ -2617,23 +2780,20 @@ signature.Reason = "I am author of this document."; //Draws the signature image signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save the document +document.Save("Output.pdf"); +//Close the document. document.Close(true); -//Defining the ContentType for pdf file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a new page @@ -2667,6 +2827,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Security + 'Creates a new PDF document Dim document As New PdfDocument() 'Adds a new page @@ -2722,11 +2887,12 @@ The following code example explains how to validate the digitally signed PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Validate-the-digitally-signed-PDF-signature/.NET/Validate-the-digitally-signed-PDF-signature/Program.cs" %} -// Load the input PDF document stream from the specified file path -FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; -// Load the signed PDF document using the stream -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); +// Load the signed PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Retrieve the first signature field from the PDF form PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; @@ -2856,11 +3022,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} -// Load the input PDF document stream from the specified file path -FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; -// Load the signed PDF document using the stream -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); +// Load the signed PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Retrieve the first signature field from the PDF form PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; @@ -2990,11 +3157,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Load the input PDF document stream from the specified file path -Dim documentStream As New FileStream(Path.GetFullPath("Data/Input.pdf"), FileMode.Open, FileAccess.Read) +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports System.Security.Cryptography.X509Certificates ' Load the signed PDF document using the stream -Dim loadedDocument As New PdfLoadedDocument(documentStream) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") ' Retrieve the first signature field from the PDF form Dim signatureField As PdfLoadedSignatureField = TryCast(loadedDocument.Form.Fields(0), PdfLoadedSignatureField) @@ -3127,10 +3295,12 @@ The following code example explains how to validate all the signatures in digita {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Validate-all-signatures-in-digitally-signed-PDF/.NET/Validate-all-signatures-in-digitally-signed-PDF/Program.cs" %} -//Get the stream from the document -FileStream documentStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -//Load an existing signed PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + +//Load the PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //X509Certificate2Collection to check the signer's identity using root certificates X509Certificate2Collection collection = new X509Certificate2Collection(); @@ -3153,6 +3323,10 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + //Load an existing signed PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -3173,6 +3347,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports System.Security.Cryptography.X509Certificates + 'Load an existing signed PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") @@ -3205,6 +3383,9 @@ This example shows how to validate and identify different types of digital signa {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Get the stream from the document FileStream documentStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); // Load the signed PDF document @@ -3278,6 +3459,9 @@ for (int i = form.Fields.Count - 1; i >= 0; i--) {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + // Load the signed PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Signed PDF.pdf"); @@ -3349,6 +3533,9 @@ for (int i = form.Fields.Count - 1; i >= 0; i--) {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + ' Load the signed PDF document Dim loadedDocument As New PdfLoadedDocument("Signed PDF.pdf") @@ -3420,10 +3607,14 @@ Steps for deferred signing: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/refs/heads/master/Digital%20Signature/Deferred-signing-in-PDF-document/.NET/Deferred-signing-in-PDF-document/Program.cs" %} -//Get the stream from the document. -FileStream documentStream = new FileStream("PDF_Succinctly.pdf ", FileMode.Open, FileAccess.Read); -//Load an existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography; +using System.Security.Cryptography.X509Certificates; + +//Load the PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Creates a digital signature. PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], null, "Signature"); @@ -3439,17 +3630,10 @@ System.Collections.Generic.List certificates = new System.Coll certificates.Add(new X509Certificate2(Convert.FromBase64String(PublicCert))); signature.AddExternalSigner(externalSignature, certificates, null); -//Save the document. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -//Close the PDF document. +//Save the document +loadedDocument.Save("Output.pdf"); +//Close the document. loadedDocument.Close(true); -//Defining the ContentType for a PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); void DeferredSign() { @@ -3542,6 +3726,12 @@ class ExternalSigner : IPdfExternalSigner {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography; +using System.Security.Cryptography.X509Certificates; + //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("PDF_Succinctly.pdf"); @@ -3655,6 +3845,11 @@ class ExternalSigner : IPdfExternalSigner {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports System.Security.Cryptography + 'Load an existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("PDF_Succinctly.pdf") @@ -3770,6 +3965,10 @@ The following code sample shows how to add the estimated size of the signature i {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Adding-the-estimated-size-of-the-signature/.NET/Adding-the-estimated-size-of-the-signature/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Security; + //Creating a new PDF Document. PdfDocument document = new PdfDocument(); //Adding a new page to the PDF document. @@ -3784,25 +3983,19 @@ signature.Bounds = new Rectangle(10, 20, 400, 200); //Sets the estimated size of the signature. signature.EstimatedSignatureSize = 20000; -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document into stream. -document.Save(stream); -//If the position is not set to '0,' then the PDF will be empty. -stream.Position = 0; +//Save the document +document.Save("Output.pdf"); //Close the document. document.Close(true); -//Defining the ContentType for a PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Security; + //Creating a new PDF Document. PdfDocument document = new PdfDocument(); //Adding a new page to the PDF document. @@ -3825,6 +4018,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Creating a new PDF Document. Dim document As PdfDocument = New PdfDocument() 'Adding a new page to the PDF document. @@ -3862,10 +4059,13 @@ Steps for deferred signing: {% highlight c# tabtitle="C# [Cross-platform]" %} -//Get the stream from a document. -FileStream documentStream = new FileStream("PDF_Succinctly.pdf ", FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + //Load an existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("PDF_Succinctly.pdf"); //Creates a digital signature. PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], null, "Signature"); @@ -3881,16 +4081,9 @@ System.Collections.Generic.List certificates = new System.Coll signature.AddExternalSigner(externalSignature, certificates, null); //Save a document. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -//Close a PDF document. +loadedDocument.Save("EmptySignature.pdf"); +//Close a document. loadedDocument.Close(true); -//Defining the ContentType for a PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); //Create an external signer with a signed hash message. IPdfExternalSigner externalSigner = new ExternalSigner("SHA1"); @@ -3899,8 +4092,8 @@ System.Collections.Generic.List publicCertificates = new Syste publicCertificates.Add(new X509Certificate2(Convert.FromBase64String(PublicCert))); //Create an output file stream. -MemoryStream outputFileStream = new MemoryStream(); -// Get the stream from a document. +MemoryStream outputFileStream = new MemoryStream(); +//Get the stream from a document. FileStream inputFileStream = new FileStream("EmptySignature.pdf", FileMode.Open, FileAccess.Read); string pdfPassword = string.Empty; //Deferred signing without PKCS7 encoding. @@ -3960,6 +4153,11 @@ class ExternalSigner : IPdfExternalSigner {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("PDF_Succinctly.pdf"); @@ -4049,6 +4247,11 @@ class ExternalSigner : IPdfExternalSigner {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports System.Security.Cryptography.X509Certificates + 'Load an existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("PDF_Succinctly.pdf") @@ -4147,47 +4350,46 @@ The following code example illustrates how to draw text/images in a digital appe {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Draw-text-or-images-in-the-signature-appearance/.NET/Draw-text-or-images-in-the-signature-appearance/Program.cs" %} -//Create a new PDF document. +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + +//Creates a new PDF document. PdfDocument document = new PdfDocument(); -//Add a new page. +//Adds a new page. PdfPageBase page = document.Pages.Add(); //Create PDF graphics for the page. PdfGraphics graphics = page.Graphics; -//Create a certificate instance from a PFX file with a private key. -FileStream certificateStream = new FileStream("PDF.pfx", FileMode.Open, FileAccess.Read); -PdfCertificate pdfCert = new PdfCertificate(certificateStream, "password123"); -//Create a digital signature. +//Creates a certificate instance from PFX file with private key. +PdfCertificate pdfCert = new PdfCertificate(@"PDF.pfx", "password123"); +//Creates a digital signature. PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature"); -//Set an image for signature field. -FileStream imageStream = new FileStream("signature.jpg", FileMode.Open, FileAccess.Read); -//Set an image for signature field. -PdfBitmap signatureImage = new PdfBitmap(imageStream); -//Set the signature information. -signature.Bounds = new RectangleF(new PointF(0, 0), signatureImage.PhysicalDimension); +//Sets an image for signature field. +PdfBitmap signatureImage = new PdfBitmap(@"signature.png"); +//Sets signature information. +signature.Bounds = new RectangleF(0,0,200,100); signature.ContactInfo = "johndoe@owned.us"; signature.LocationInfo = "Honolulu, Hawaii"; signature.Reason = "I am author of this document."; -//Create appearance for the digital signature. +//Create appearance for the digital siganture. signature.Appearance.Normal.Graphics.DrawImage(signatureImage, signature.Bounds); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; +//Save the document. +document.Save("DigitalSignature.pdf"); //Close the document. document.Close(true); -//Define the ContentType for pdf file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Create a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Creates a new PDF document. PdfDocument document = new PdfDocument(); //Adds a new page. @@ -4218,6 +4420,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Security + 'Create a new PDF document. Dim document As New PdfDocument() 'Add a new page. @@ -4257,11 +4464,11 @@ Added support for LTV validation and getting CRL and OCSP embedded details from {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Get-LTV-information/.NET/Get-LTV-information/Program.cs" %} -//Gets the stream from the document -FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; -//Loads an existing signed PDF document -PdfLoadedDocument document = new PdfLoadedDocument(documentStream); +//Load the PDF document +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); // Gets the signature field PdfLoadedSignatureField signatureField = document.Form.Fields[0] as PdfLoadedSignatureField; @@ -4292,11 +4499,11 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} -//Gets the stream from the document -FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; -//Loads an existing signed PDF document -PdfLoadedDocument document = new PdfLoadedDocument(documentStream); +//Load the PDF document +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); // Gets the signature field PdfLoadedSignatureField signatureField = document.Form.Fields[0] as PdfLoadedSignatureField; @@ -4327,11 +4534,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Gets the stream from the document -Dim documentStream As New FileStream(Path.GetFullPath("Data/Input.pdf"), FileMode.Open, FileAccess.Read) +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security ' Loads an existing signed PDF document -Dim document As New PdfLoadedDocument(documentStream) +Dim document As New PdfLoadedDocument("Input.pdf") ' Gets the signature field Dim signatureField As PdfLoadedSignatureField = TryCast(document.Form.Fields(0), PdfLoadedSignatureField) @@ -4372,11 +4579,11 @@ Added support to customize revocation validation using [PdfSignatureValidationOp {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Customized-revocation-validation/.NET/Customized-revocation-validation/Program.cs" %} -//Gets the stream from the document -FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; -//Loads an existing signed PDF document -PdfLoadedDocument document = new PdfLoadedDocument(documentStream); +//Load the PDF document +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); // Gets the signature field PdfLoadedSignatureField signatureField = document.Form.Fields[0] as PdfLoadedSignatureField; @@ -4407,11 +4614,11 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} -//Gets the stream from the document -FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; -//Loads an existing signed PDF document -PdfLoadedDocument document = new PdfLoadedDocument(documentStream); +//Load the PDF document +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); // Gets the signature field PdfLoadedSignatureField signatureField = document.Form.Fields[0] as PdfLoadedSignatureField; @@ -4442,6 +4649,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + ' Gets the stream from the document Dim documentStream As New FileStream(Path.GetFullPath("Data/Input.pdf"), FileMode.Open, FileAccess.Read) @@ -4484,32 +4694,26 @@ The following code example illustrates how to remove existing digital signatures {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Remove_existing_digital_signature_from_PDF/.NET/Remove_existing_digital_signature_from_PDF/Program.cs" %} +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the signature field from PDF form field collection. PdfLoadedSignatureField signatureField = pdfLoadedDocument.Form.Fields[0] as PdfLoadedSignatureField; //Remove signature field from form field collection. pdfLoadedDocument.Form.Fields.Remove(signatureField); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -pdfLoadedDocument.Save(stream); -stream.Position = 0; -//Close the document. +//Save and close the PDF document. +pdfLoadedDocument.Save("RemoveDigital.pdf"); pdfLoadedDocument.Close(true); -//Defining the ContentType for PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document. PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -4526,6 +4730,8 @@ pdfLoadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing + 'Load an existing PDF document. Dim pdfLoadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") @@ -4552,12 +4758,13 @@ The following code snippet illustrates how to sign a PDF document without showin {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Sign-PDF-without-showing-digital-signature/.NET/Sign-PDF-without-showing-digital-signature/Program.cs" %} -//Get stream from an existing PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + +//Load an existing PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load digital ID with password. -FileStream certificateStream = new FileStream("PDF.pfx", FileMode.Open, FileAccess.Read); -PdfCertificate certificate = new PdfCertificate(certificateStream, "password123"); +PdfCertificate certificate = new PdfCertificate(@"PDF.pfx", "password123"); //Create a signature with loaded digital ID. PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], certificate, "DigitalSignature"); @@ -4568,23 +4775,17 @@ signature.Certificated = true; //Allow the form fill and and comments. signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.AllowComments; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document. -document.Close(true); -//Defining the ContentType for pdf file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); +//Save and close the PDF document. +loadedDocument.Save("Certifying.pdf"); +loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load digital ID with password. @@ -4607,6 +4808,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Load an existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Load digital ID with password. @@ -4639,9 +4843,11 @@ The following code snippet illustrates how to retrieve digital signature informa {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Retrieve-digital-signature-information-from-PDF/.NET/Retrieve-digital-signature-information-from-PDF/Program.cs" %} -//Get stream from an existing PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + +//Load the PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the signature field from PdfLoadedDocument form field collection. PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; @@ -4661,6 +4867,9 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -4682,6 +4891,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Load an existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") @@ -4715,23 +4927,25 @@ N> It is recommended to use licensed assemblies or registered license keys in yo {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/refs/heads/master/Digital%20Signature/Multiple-digital-signature/.NET/Multiple-digital-signature/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream("SignatureFields.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using Syncfusion.Pdf; + +//Load an existing PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the first page of the document. PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; //Get the first signature field of the PDF document. PdfLoadedSignatureField signatureField1 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; -//Creates a certificate. -FileStream certificateStream1 = new FileStream("PDF.pfx", FileMode.Open, FileAccess.Read); -PdfCertificate certificate1 = new PdfCertificate(certificateStream1, "password123"); -//Add signature to the signature field. +//Create a certificate instance from a PFX file with a private key. +PdfCertificate certificate1 = new PdfCertificate("PDF.pfx", "password123"); +//Add a signature to the signature field. signatureField1.Signature = new PdfSignature(loadedDocument, page, certificate1, "Signature", signatureField1); -//Get the image as a stream. -FileStream imageStream = new FileStream("Student Signature.jpg", FileMode.Open, FileAccess.Read); -PdfBitmap signatureImage = new PdfBitmap(imageStream); -//Draw an image in signature appearance. +//Set an image for the signature field. +PdfBitmap signatureImage = new PdfBitmap(@"Student Signature.jpg"); +//Insert an image in the signature appearance. signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, 90, 20); //Save the document into the stream. @@ -4745,33 +4959,28 @@ PdfLoadedPage loadedPage = signedDocument.Pages[0] as PdfLoadedPage; //Get the first signature field of the PDF document. PdfLoadedSignatureField signatureField2 = signedDocument.Form.Fields[1] as PdfLoadedSignatureField; -//Add the signature to the signature field. -signatureField1.Signature = new PdfSignature(signedDocument, loadedPage, certificate1, "Signature", signatureField2); -//Load the image as a stream. -FileStream imageStream1 = new FileStream("Teacher Signature.png", FileMode.Open, FileAccess.Read); -PdfBitmap signatureImage1 = new PdfBitmap(imageStream1); -//Draw the image in signature appearance. -signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage1, 0, 0, 90, 20); - -//Saving the PDF to the MemoryStream. -MemoryStream signedStream = new MemoryStream(); -signedDocument.Save(signedStream); -//Set the position as '0'. -signedStream.Position = 0; -//Close the documents. +//Add a signature to the signature field. +signatureField2.Signature = new PdfSignature(signedDocument, loadedPage, certificate1, "Signature", signatureField2); +//Set an image for the signature field. +PdfBitmap signatureImage1 = new PdfBitmap(@"Teacher Signature.png"); +//Draw an image in the signature appearance. +signatureField2.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage1, 0, 0, 90, 20); + +//Save the PDF document. +signedDocument.Save("Multiple_signature.pdf"); +//Close the PDF documents. signedDocument.Close(true); loadedDocument.Close(true); -//Defining the ContentType for a pdf file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Multiple_Signature.pdf"; -//Create the FileContentResult object by using the file contents, content type, and file name. -return File(signedStream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using Syncfusion.Pdf; + //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the first page of the document. @@ -4816,6 +5025,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports Syncfusion.Pdf + 'Load an existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the first page of the document. @@ -4869,9 +5083,12 @@ The following code example illustrates how to retrieve revocation certificate in {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Retrieve-revocation-certificate-information/.NET/Retrieve-revocation-certificate-information/Program.cs" %} -//Load an existing signed PDF document. -FileStream documentStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + +//Load the PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get signature field. PdfLoadedSignatureField loadedSignatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; @@ -4920,6 +5137,10 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + //Load an existing signed PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -4970,6 +5191,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports System.Security.Cryptography.X509Certificates + 'Load an existing signed PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") @@ -5030,9 +5255,10 @@ The following code example illustrates how to retrieve signed revision informati {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Retrieve-signed-revision-information/.NET/Retrieve-signed-revision-information/Program.cs" %} -//Load an existing PDF document. -FileStream inputStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(inputStream); +using Syncfusion.Pdf.Parsing; + +//Load an existing PDF document +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the document revisions. PdfRevision[] revisions = document.Revisions; foreach (PdfRevision rev in revisions) @@ -5046,11 +5272,12 @@ PdfLoadedSignatureField field = document.Form.Fields[0] as PdfLoadedSignatureFie int revisionIndex = field.Revision; //Close the document. document.Close(true); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the document revisions. @@ -5071,6 +5298,8 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing + 'Load an existing PDF document. Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the document revisions. @@ -5100,9 +5329,12 @@ The following code example illustrates how to retrieve revocation certificate in {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Retrieve-revocation-certificate-information-from-digital-signature-embed-timestamp/.NET/Program.cs" %} -//Load an existing PDF document. -FileStream inputStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(inputStream); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + +//Load an existing PDF document +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Gets the signature field. PdfLoadedSignatureField signatureField = document.Form.Fields[0] as PdfLoadedSignatureField; //Validates signature and gets the validation result. @@ -5116,6 +5348,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + //Load an existing PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Gets the signature field. @@ -5131,6 +5367,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports System.Security.Cryptography.X509Certificates + 'Load an existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Gets the signature field. @@ -5156,15 +5396,17 @@ Utilize the **GetImages** method within the [PdfLoadedSignatureField](https://he {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Get-images-from-the-existing-signed-signature-field/.NET/Get-images-from-the-existing-signed-signature-field/Program.cs" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF file. -FileStream fileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument ldoc = new PdfLoadedDocument(fileStream); +PdfLoadedDocument ldoc = new PdfLoadedDocument("Input.pdf"); //Get the existing signed signature field. PdfLoadedSignatureField loadedSignature = ldoc.Form.Fields[0] as PdfLoadedSignatureField; -//Get the image streams. -Stream[] imageStreams = loadedSignature.GetImages(); -for (int i = 0; i < imageStreams.Length; i++) { - File.WriteAllBytes("Output" + i.ToString() + ".jpg", (imageStreams[i] as MemoryStream).ToArray()); +//Get the image. +Image[] images = loadedSignature.GetImages(); +for (int i = 0; i < images.Length; i++) { + images[i].Save("Image" + i.ToString() + ".jpg", ImageFormat.Png); } //Close a PDF document. ldoc.Close(true); @@ -5173,6 +5415,9 @@ ldoc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF file. PdfLoadedDocument ldoc = new PdfLoadedDocument("Input.pdf"); //Get the existing signed signature field. @@ -5189,6 +5434,9 @@ ldoc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Interactive + 'Load an existing PDF file. Dim fileStream As FileStream = New FileStream("Input.pdf", FileMode.Open, FileAccess.Read) Dim ldoc As PdfLoadedDocument = New PdfLoadedDocument(fileStream) @@ -5218,6 +5466,10 @@ Effortlessly Integrate **signature and timestamp** certificates into the Documen {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + //Loads an existing document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Gets the signature field @@ -5248,6 +5500,10 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; +using System.Security.Cryptography.X509Certificates; + //Gets the stream from the document FileStream documentStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); //Loads an existing signed PDF document @@ -5280,6 +5536,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security +Imports System.Security.Cryptography.X509Certificates + 'Loads an existing signed PDF document Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Gets the signature field From 04eb8c4a16a025abf6325d09bd80c5361b9e415f Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Wed, 8 Oct 2025 15:07:36 +0530 Subject: [PATCH 2/5] 985863-ug: Added two md files. --- .../NET/Working-with-Document-Conversions.md | 370 ++++++++++++------ .../PDF-Library/NET/Working-with-Document.md | 334 +++++++++++----- 2 files changed, 490 insertions(+), 214 deletions(-) diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Document-Conversions.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Document-Conversions.md index 5e3be7eb7..b97659453 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Document-Conversions.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Document-Conversions.md @@ -89,28 +89,33 @@ For ASP.NET Core and Xamarin applications {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Document%20conversion/Word-to-PDF/Converting-Word-to-PDF-document/.NET/Converting-Word-to-PDF-document/Program.cs" %} -// Open the file as Stream. -FileStream docStream = new FileStream(@"Template.docx", FileMode.Open, FileAccess.Read); -//Loads file stream into Word document. -WordDocument wordDocument = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic); -//Instantiation of DocIORenderer for Word to PDF conversion. -DocIORenderer render = new DocIORenderer(); -//Converts Word document into PDF document. -PdfDocument pdfDocument = render.ConvertToPDF(wordDocument); -//Releases all resources used by the Word document and DocIO Renderer objects. -render.Dispose(); -wordDocument.Dispose(); - -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); -//Close the document. +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using Syncfusion.Pdf; + +//Load an existing Word document. +WordDocument wordDocument = new WordDocument("Template.docx", FormatType.Docx); +//Initialize chart to image converter for converting charts during Word to pdf conversion. +wordDocument.ChartToImageConverter = new ChartToImageConverter(); +//Create an instance of DocToPDFConverter. +DocToPDFConverter converter = new DocToPDFConverter(); +//Convert Word document into PDF document. +PdfDocument pdfDocument = converter.ConvertToPDF(wordDocument); + +//Save the PDF file. +pdfDocument.Save("WordtoPDF.pdf"); +//Close the instance of document objects. pdfDocument.Close(true); +wordDocument.Close(); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using Syncfusion.Pdf; + //Load an existing Word document. WordDocument wordDocument = new WordDocument("Template.docx", FormatType.Docx); //Initialize chart to image converter for converting charts during Word to pdf conversion. @@ -131,6 +136,10 @@ wordDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.DocIO.DLS +Imports Syncfusion.DocIORenderer +Imports Syncfusion.Pdf + 'Load an existing Word document Dim wordDocument As New WordDocument("Template.docx", FormatType.Docx) 'Initialize chart to image converter for converting charts during Word to pdf conversion @@ -175,6 +184,13 @@ Essential® DocIO allows you to customize the Word to PDF conversi {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocToPDFConverter; +using Syncfusion.OfficeChart; +using Syncfusion.OfficeChartToImageConverter; +using Syncfusion.Pdf; + //Loads an existing Word document. WordDocument wordDocument = new WordDocument("Sample_Image.docx", FormatType.Docx); //Initialize chart to image converter for converting charts during Word to pdf conversion. @@ -203,6 +219,13 @@ wordDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.DocIO +Imports Syncfusion.DocIO.DLS +Imports Syncfusion.DocToPDFConverter +Imports Syncfusion.OfficeChart +Imports Syncfusion.OfficeChartToImageConverter +Imports Syncfusion.Pdf + 'Loads an existing Word document Dim wordDocument As New WordDocument("Sample_Image.docx", FormatType.Docx) 'Initialize chart to image converter for converting charts during Word to pdf conversion @@ -250,29 +273,32 @@ The following code illustrates how to convert a workbook to PDF Document using [ {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Document%20conversion/Excel-to-PDF/Convert-workbook-to-PDF-document/.NET/Convert-workbook-to-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; + using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; //Load the document. - FileStream excelStream = new FileStream("ExcelToPDF.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); //Convert Excel document into PDF document. PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Save the PDF document to stream. - Stream stream = new FileStream("ExcelToPDF.pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); - //Dispose the stream. - excelStream.Dispose(); - stream.Dispose(); + //Save the PDF file. + pdfDocument.Save("ExcelToPDF.pdf"); } {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; + using(ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; @@ -293,6 +319,10 @@ using(ExcelEngine excelEngine = new ExcelEngine()) {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.XlsIO +Imports Syncfusion.XlsIORenderer + Using excelEngine As ExcelEngine = New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Excel2013 @@ -322,30 +352,36 @@ The following code shows how to convert a particular sheet to PDF Document using {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Document%20conversion/Excel-to-PDF/Converting-a-worksheet-to-PDF-document/.NET/Converting-a-worksheet-to-PDF-document/Program.cs" %} -using (ExcelEngine excelEngine = new ExcelEngine()) +using Syncfusion.Pdf; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; + +Using(ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; - FileStream excelStream = new FileStream("ExcelToPDF.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); - IWorksheet worksheet = workbook.Worksheets[0]; - - //Initialize XlsIO renderer. - XlsIORenderer renderer = new XlsIORenderer(); - //Convert Excel document into PDF document. - PdfDocument pdfDocument = renderer.ConvertToPDF(worksheet); - - //Saving the PDF to the MemoryStream. - Stream stream = new FileStream("ExcelToPDF.pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); - //Dispose the stream. - excelStream.Dispose(); - stream.Dispose(); + application.DefaultVersion = ExcelVersion.Excel2013; + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic); + IWorksheet sheet = workbook.Worksheets[0]; + + //convert the sheet to PDF. + ExcelToPdfConverter converter = new ExcelToPdfConverter(sheet); + //Initialize PDF document. + PdfDocument pdfDocument= new PdfDocument(); + //Convert Excel document into PDF document. + pdfDocument = converter.Convert(); + + //Save the PDF file. + pdfDocument.Save("ExcelToPDF.pdf"); } {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; + Using(ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; @@ -368,6 +404,10 @@ Using(ExcelEngine excelEngine = new ExcelEngine()) {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.XlsIO +Imports Syncfusion.XlsIORenderer + Using excelEngine As ExcelEngine = New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Excel2013 @@ -399,31 +439,37 @@ The following code snippet shows how to create an individual PDF document for ea {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Document%20conversion/Excel-to-PDF/Creating-individual-PDF-document-for-each-worksheet/.NET/Program.cs" %} -using (ExcelEngine excelEngine = new ExcelEngine()) +using Syncfusion.Pdf; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; + +Using(ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; - FileStream excelStream = new FileStream("ExcelToPDF.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); - - //Initialize XlsIO renderer. - XlsIORenderer renderer = new XlsIORenderer(); + application.DefaultVersion = ExcelVersion.Excel2013; + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic); + //Create a new PDF document. - PdfDocument pdfDocument = new PdfDocument(); + PdfDocument pdfDocument = new PdfDocument(); foreach (IWorksheet sheet in workbook.Worksheets) { - pdfDocument = renderer.ConvertToPDF(sheet); - + //Open the Excel document to Convert. + ExcelToPdfConverter converter = new ExcelToPdfConverter(sheet); + pdfDocument = converter.Convert(); + //Save the PDF file. - Stream stream = new FileStream(sheet.Name+".pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); - stream.Dispose(); + pdfDocument.Save(sheet.Name +".pdf"); + converter.Dispose(); } - excelStream.Dispose(); } {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; + Using(ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; @@ -448,6 +494,10 @@ Using(ExcelEngine excelEngine = new ExcelEngine()) {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.XlsIO +Imports Syncfusion.XlsIORenderer + Using excelEngine As ExcelEngine = New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Excel2013 @@ -480,29 +530,39 @@ To preserve the charts during Excel to PDF conversion, you should initialize the {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Document%20conversion/Excel-to-PDF/Converting-Excel-with-chart-to-PDF-document/.NET/Converting-Excel-with-chart-to-PDF-document/Program.cs" %} -using (ExcelEngine excelEngine = new ExcelEngine()) +using Syncfusion.Pdf; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; + +Using(ExcelEngine excelEngine = new ExcelEngine()) { - IApplication application = excelEngine.Excel; - //Initialize XlsIO renderer. - XlsIORenderer renderer = new XlsIORenderer(); - //Load the document as stream. - FileStream excelStream = new FileStream("chart.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Excel2013; + //Instantiating the ChartToImageConverter and assigning the ChartToImageConverter instance of XlsIO application. + application.ChartToImageConverter = new ChartToImageConverter(); + //Tuning chart image quality. + application.ChartToImageConverter.ScalingMode = ScalingMode.Best; + IWorkbook workbook = application.Workbooks.Open("chart.xlsx"); + IWorksheet worksheet = workbook.Worksheets[0]; - //Convert Excel document with charts into PDF document. - PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); + //Open the Excel document to Convert. + ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook); - //Save the PDF document. - Stream stream = new FileStream("ExcelToPDF.pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); - //Dispose the stream. - excelStream.Dispose(); - stream.Dispose(); + //Initialize PDF document. + PdfDocument pdfDocument = new PdfDocument(); + //Convert Excel document into PDF document. + pdfDocument = converter.Convert(); + //Save the PDF file. + pdfDocument.Save("ExcelToPDF.pdf"); } {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; + Using(ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; @@ -529,6 +589,10 @@ Using(ExcelEngine excelEngine = new ExcelEngine()) {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.XlsIO +Imports Syncfusion.XlsIORenderer + Using excelEngine As ExcelEngine = New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Excel2013 @@ -640,31 +704,33 @@ For ASP.NET Core and Xamarin applications {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Document%20conversion/RTF-to-PDF/Convert-RTF-to-PDF-document/.NET/Convert-RTF-to-PDF-document/Program.cs" %} -//Open the file as Stream -FileStream docStream = new FileStream(@"Input.rtf", FileMode.Open, FileAccess.Read); -//Loads file stream into Word document -WordDocument wordDocument = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic); -//Instantiation of DocIORenderer for Word to PDF conversion -DocIORenderer render = new DocIORenderer(); -//Converts Word document into PDF document -PdfDocument pdfDocument = render.ConvertToPDF(wordDocument); - -//Releases all resources used by the Word document and DocIO Renderer objects -render.Dispose(); -wordDocument.Dispose(); - -//Save the document into stream -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); -//Close the document +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using Syncfusion.Pdf; + +//Load an existing RTF document. +WordDocument rtfDocument = new WordDocument("Input.rtf"); +//Create an instance of DocToPDFConverter. +DocToPDFConverter converter = new DocToPDFConverter(); +//Convert Word document into PDF document. +PdfDocument pdfDocument = converter.ConvertToPDF(rtfDocument); + +//Save the PDF file. +pdfDocument.Save("RTFToPDF.pdf"); +//Close the instance of document objects. pdfDocument.Close(true); +rtfDocument.Close(); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using Syncfusion.Pdf; + //Load an existing RTF document. -WordDocument rtfDocument = new WordDocument(inputFileName); +WordDocument rtfDocument = new WordDocument("Input.rtf"); //Create an instance of DocToPDFConverter. DocToPDFConverter converter = new DocToPDFConverter(); //Convert Word document into PDF document. @@ -681,6 +747,10 @@ rtfDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.DocIO.DLS +Imports Syncfusion.DocIORenderer +Imports Syncfusion.Pdf + 'Load an existing Word document Dim rtfDocument As New WordDocument(inputFileName) 'Create an instance of DocToPDFConverter @@ -718,6 +788,12 @@ Essential® DocIO allows you to customize the RTF to PDF conversio {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.DocIO.DLS; +using Syncfusion.DocToPDFConverter; +using Syncfusion.Pdf; +using System; +using System.Collections.Generic; + //Loads an existing Word document WordDocument rtfDocument = new WordDocument(inputFileName); //create an instance of DocToPDFConverter - responsible for Word to PDF conversion @@ -741,6 +817,12 @@ rtfDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.DocIO.DLS +Imports Syncfusion.DocToPDFConverter +Imports Syncfusion.Pdf +Imports System +Imports System.Collections.Generic + 'Loads an existing Word document Dim rtfDocument As New WordDocument(inputFileName) 'create an instance of DocToPDFConverter - responsible for Word to PDF conversion @@ -777,26 +859,28 @@ The code snippet to illustrate the same is given below. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Document%20conversion/TIFF-to-PDF/Converting-multipage-TIFF-to-PDF-document/.NET/Converting-multipage-TIFF-to-PDF-document/Program.cs" %} -//Create a new PDF document -PdfDocument document = new PdfDocument(); +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; -//Load the multi frame TIFF image from the disk -FileStream imageStream = new FileStream("image.tiff", FileMode.Open, FileAccess.Read); -PdfTiffImage tiffImage = new PdfTiffImage(imageStream); +//Create a PDF document +PdfDocument pdfDocument = new PdfDocument(); + +//Load multi frame TIFF image +PdfBitmap tiffImage = new PdfBitmap("image.tiff"); //Get the frame count int frameCount = tiffImage.FrameCount; //Access each frame and draw into the page for (int i = 0; i < frameCount; i++) { + tiffImage.ActiveFrame = i; //Add a section to the PDF document - PdfSection section = document.Sections.Add(); + PdfSection section = pdfDocument.Sections.Add(); //Set page margins section.PageSettings.Margins.All = 0; - tiffImage.ActiveFrame = i; //Create a PDF unit converter instance PdfUnitConvertor converter = new PdfUnitConvertor(); //Convert to point - Syncfusion.Drawing.SizeF size = converter.ConvertFromPixels(tiffImage.PhysicalDimension, PdfGraphicsUnit.Point); + SizeF size = converter.ConvertFromPixels(tiffImage.PhysicalDimension, PdfGraphicsUnit.Point); //Set page orientation section.PageSettings.Orientation = (size.Width > size.Height) ? PdfPageOrientation.Landscape : PdfPageOrientation.Portrait; //Set page size @@ -804,20 +888,20 @@ for (int i = 0; i < frameCount; i++) //Add a page to the section PdfPage page = section.Pages.Add(); //Draw TIFF image into the PDF page - page.Graphics.DrawImage(tiffImage, Syncfusion.Drawing.PointF.Empty, size); + page.Graphics.DrawImage(tiffImage, PointF.Empty, size); } -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -document.Save(stream); -//Close the document -document.Close(true); +//Save and close the document +pdfDocument.Save("Sample.pdf"); +pdfDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; + //Create a PDF document PdfDocument pdfDocument = new PdfDocument(); @@ -855,6 +939,9 @@ pdfDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf + 'Create a PDF document Dim pdfDocument As New PdfDocument() @@ -910,6 +997,11 @@ Refer the below code snippet to draw a single frame monochrome TIFF image with J {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using System; +using System.Collections.Generic; + //Create a PDF document PdfDocument pdfDocument = new PdfDocument(); //Add a page @@ -930,6 +1022,11 @@ pdfDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf +Imports System +Imports System.Collections.Generic + 'Create a PDF document Dim pdfDocument As New PdfDocument() 'Add a page @@ -966,28 +1063,29 @@ The below code illustrates how to convert XPS to PDF. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Document%20conversion/Converting-XPS-to-PDF-document/.NET/Converting-XPS-to-PDF-document/Program.cs" %} -//Initialize XPS to PDF converter. +using Syncfusion.Pdf; +using Syncfusion.XPS; + +//Create converter class XPSToPdfConverter converter = new XPSToPdfConverter(); -//Open the XPS file as stream. -FileStream fileStream = new FileStream("Input.xps", FileMode.Open, FileAccess.ReadWrite); -//Convert the XPS to PDF. -PdfDocument document = converter.Convert(fileStream); - -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document into stream. -document.Save(stream); -//Close the documents. +//Convert the XPS to PDF +PdfDocument document = converter.Convert("Input.xps"); + +//Save and close the document +document.Save("Sample.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.XPS; + //Create converter class XPSToPdfConverter converter = new XPSToPdfConverter(); //Convert the XPS to PDF -PdfDocument document = converter.Convert(xpsFileName); +PdfDocument document = converter.Convert("Input.xps"); //Save and close the document document.Save("Sample.pdf"); @@ -997,10 +1095,13 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.XPS + 'Create converter class Dim converter As New XPSToPdfConverter() 'Convert the XPS to PDF -Dim document As PdfDocument = converter.Convert(xpsFileName) +Dim document As PdfDocument = converter.Convert("Input.xps") 'Save and close the document document.Save("Sample.pdf") @@ -1220,6 +1321,9 @@ The following code snippet illustrates how to convert PDF page into image using {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.PdfToImageConverter; +using System.IO; + //Initialize PDF to Image converter. PdfToImageConverter imageConverter = new PdfToImageConverter(); //Load the PDF document as a stream @@ -1227,13 +1331,16 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R imageConverter.Load(inputStream); //Convert PDF to Image. Stream outputStream = imageConverter.Convert(0, false, false); -MemoryStream stream = outputStream as MemoryStream; -return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Jpeg, "sample.jpeg"); +Bitmap image = new Bitmap(outputStream); +image.Save("sample.png"); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.PdfToImageConverter; +using System.IO; + //Initialize PDF to Image converter. PdfToImageConverter imageConverter = new PdfToImageConverter(); //Load the PDF document as a stream @@ -1248,6 +1355,9 @@ image.Save("sample.png"); {% endhighlight %} {% highlight vb tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.PdfToImageConverter +Imports System.IO + 'Initialize PDF to Image converter. Dim imageConverter As PdfToImageConverter = New PdfToImageConverter() 'Load the PDF document as a stream @@ -1279,6 +1389,9 @@ The [HTML to PDF converter library](https://www.syncfusion.com/document-processi {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Convert URL to PDF @@ -1292,6 +1405,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Convert URL to PDF @@ -1305,6 +1421,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + ' Initialize HTML to PDF converter Dim htmlConverter As New HtmlToPdfConverter() @@ -1330,20 +1449,24 @@ The [HTML to PDF converter library](https://www.syncfusion.com/document-processi {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); -//Convert URL to PDF document. +//Convert a SVG file to PDF with HTML converter PdfDocument document = htmlConverter.Convert("inputSVG.svg"); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -//Close the document +//Save and close the PDF document +document.Save("SVGToPDF.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Convert a SVG file to PDF with HTML converter @@ -1356,6 +1479,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize HTML to PDF converter Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() 'Convert a SVG file to PDF with HTML converter @@ -1366,4 +1492,4 @@ document.Close(True) {% endhighlight %} -{% endtabs %} + {% endtabs %} diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Document.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Document.md index 2557aa4ba..75759e9e7 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Document.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Document.md @@ -17,6 +17,9 @@ You can choose the standard or custom page size when you add a page to the PDF d {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Create-a-PDF-document-with-standard-page-size/.NET/Create-a-PDF-document-with-standard-page-size/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); // Set the page size. @@ -31,10 +34,8 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -42,6 +43,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); // Set the page size. @@ -65,6 +69,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf + 'Create a new PDF document. Dim document As New PdfDocument() 'Set the page size. @@ -96,6 +103,9 @@ You can create a PDF document with custom page size in [PdfPageSettings Size](ht {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Create-a-PDF-document-with-custom-page-size/.NET/Create-a-PDF-document-with-custom-page-size/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); // Set the custom page size. @@ -110,10 +120,8 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -121,6 +129,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); // Set the custom page size. @@ -144,6 +155,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf + 'Create a new PDF document. Dim document As New PdfDocument() 'Set the custom page size. @@ -175,6 +189,9 @@ You can change page orientation from portrait to landscape, through [PdfPageOrie {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Change-the-page-orientation-from-portrait-to-landscape/.NET/Change-the-page-orientation-from-portrait-to-landscape/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); // Set the page size. @@ -191,10 +208,8 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -202,6 +217,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); // Set the page size. @@ -227,6 +245,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf + 'Create a new PDF document. Dim document As New PdfDocument() ' Set the page size. @@ -262,6 +283,10 @@ You can also change orientation by setting the rotation angle using [PdfPageRota {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Rotate_PDF_based_on_angle/.NET/Rotate_PDF_based_on_angle/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); // Set the page size. @@ -278,10 +303,8 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -289,6 +312,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); // Set the page size. @@ -314,6 +341,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document. Dim document As New PdfDocument() 'Set the page size. @@ -349,6 +380,10 @@ PDF sections are parts of the PDF document, which may contain one or more pages {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Create_sections_in_PDF_document/.NET/Create_sections_in_PDF_document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a section to PDF document. @@ -363,10 +398,8 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -374,6 +407,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a section to PDF document. @@ -397,6 +434,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document. Dim document As New PdfDocument() 'Add a section to PDF document. @@ -436,6 +477,8 @@ The following code snippet illustrates how to print a PDF document. {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.PdfViewer; + PdfDocumentView viewer = new PdfDocumentView(); //Load the PDF document viewer.Load("Input.pdf"); @@ -456,6 +499,8 @@ viewer.Dispose(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.PdfViewer + Dim viewer As New PdfDocumentView() 'Load the PDF document viewer.Load("Input.pdf") @@ -486,6 +531,10 @@ The following code snippet illustrates how to set PDF document information. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Add_PDF_document_properties/.NET/Add_PDF_document_properties/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); @@ -506,10 +555,8 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -517,6 +564,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); @@ -546,6 +597,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document. Dim document As New PdfDocument() @@ -583,9 +638,10 @@ To read and modify the document [DocumentInformation](https://help.syncfusion.co {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Change_existing_PDF_properties/.NET/Change_existing_PDF_properties/Program.cs" %} -//Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf.Parsing; + +//Load a existing PDF document +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Modify document information. document.DocumentInformation.Author = "Syncfusion"; @@ -595,10 +651,8 @@ document.DocumentInformation.Keywords = "PDF"; document.DocumentInformation.Subject = "Document information DEMO"; document.DocumentInformation.Title = "Essential PDF Sample"; -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -606,7 +660,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} -//Create a new PDF document. +using Syncfusion.Pdf.Parsing; + +//Load a existing PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Modify document information. @@ -626,7 +682,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create a new PDF document. +Imports Syncfusion.Pdf.Parsing + +'Load a existing PDF document Dim document As New PdfLoadedDocument("Input.pdf") 'Modify document information. @@ -656,9 +714,10 @@ To remove specific details from the existing document information, use the **Rem {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Remove-specific-keys-from-the-existing-document-information/.NET/Program.cs" %} +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Remove the document information properties. document.DocumentInformation.Remove("Title"); @@ -670,10 +729,8 @@ document.DocumentInformation.Remove("Producer"); document.DocumentInformation.Remove("ModDate"); document.DocumentInformation.Remove("CreationDate"); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document into stream. -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -681,6 +738,8 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document. PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); @@ -703,6 +762,8 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing + 'Load an existing PDF document. Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") @@ -735,19 +796,18 @@ The Essential® PDF supports incremental update for PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Perform-incremental-update-for-the-PDF-document/.NET/Perform-incremental-update-for-the-PDF-document/Program.cs" %} -//Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Disable the incremental update loadedDocument.FileStructure.IncrementalUpdate = false; //Set the compression level loadedDocument.Compression = PdfCompressionLevel.Best; -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Output.pdf"); //Close the document. loadedDocument.Close(true); @@ -755,6 +815,9 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -772,6 +835,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf + 'Load the PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf") @@ -801,6 +867,10 @@ You can hide the menu bar and toolbar by enabling [HideMenubar](https://help.syn {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Create_PDF_with_viewer_preference/.NET/Create_PDF_with_viewer_preference/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -819,10 +889,8 @@ document.ViewerPreferences.HideToolbar = true; //Shows user interface elements in the document's window (such as scroll bars and navigation controls). document.ViewerPreferences.HideWindowUI = false; -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -830,6 +898,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -857,6 +929,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf +Imports System.Drawing + 'Create a new PDF document. Dim document As New PdfDocument() 'Add a page to the document. @@ -892,6 +968,9 @@ You can also allow the reader application to initially display the bookmarks, th {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Create-PDF-with-display-of-specific-panel/.NET/Create-PDF-with-display-of-specific-panel/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -906,9 +985,8 @@ graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Dra //Show the attachments panel. document.ViewerPreferences.PageMode = PdfPageMode.UseAttachments; -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -916,6 +994,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -939,6 +1020,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf + 'Create a new PDF document. Dim document As New PdfDocument() 'Add a page to the document. @@ -978,6 +1062,10 @@ The following code sample illustrates how to create a PDF document in multi-thre {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + IEnumerable works = Enumerable.Range(0, 100); Parallel.ForEach(works, index => GeneratePDF(index)); @@ -1010,6 +1098,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + Dim works As IEnumerable(Of Integer) = Enumerable.Range(0, 100) Parallel.ForEach(works, Sub(index) GeneratePDF(index)) Private Sub GeneratePDF(ByVal index As Integer) @@ -1046,6 +1138,11 @@ To modify the existing PDF document in multi-threading environment [EnableThread {% tabs %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + IEnumerable works = Enumerable.Range(0, 100); Parallel.ForEach(works, index => GeneratePDF(index)); @@ -1075,6 +1172,11 @@ doc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing + Dim works As IEnumerable(Of Integer) = Enumerable.Range(0, 100) Parallel.ForEach(works, Sub(index) GeneratePDF(index)) Private Sub GeneratePDF(ByVal index As Integer) @@ -1115,6 +1217,10 @@ The following code snippet explains how to have uniform resource naming in a PDF {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Create_PDF_with_Uniform_Resouce_Naming/.NET/Create_PDF_with_Uniform_Resouce_Naming/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Disable unique resource naming PdfDocument.EnableUniqueResourceNaming = false; @@ -1139,16 +1245,19 @@ PdfFont font3 = new PdfCjkStandardFont(PdfCjkFontFamily.HeiseiMinchoW3, 20); //Draw the text graphics.DrawString("こんにちは世界", font3, PdfBrushes.Blue, new PointF(50, 150)); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -//Close the document +//Save the document. +doc.Save("Output.pdf"); +//Close the document. doc.Close(true); {%endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Disable unique resource naming PdfDocument.EnableUniqueResourceNaming = false; @@ -1180,6 +1289,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Disable unique resource naming PdfDocument.EnableUniqueResourceNaming = False @@ -1222,9 +1335,11 @@ Enabling this property will optimize the memory but difference in time occurs ba {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Manage_memory_while_appending_PDF_document/.NET/Manage_memory_while_appending_PDF_document/Program.cs" %} -//Load an existing PDF document -FileStream docStream = new FileStream("file1.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + +//Load an existing PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create a new PDF document PdfDocument document = new PdfDocument(); @@ -1234,17 +1349,18 @@ document.EnableMemoryOptimization = true; //Append the document with source document document.Append(loadedDocument); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -//Close the documents -document.Close(true); +//Save the document. +loadedDocument.Save("Output.pdf"); +//Close the document. loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("file1.pdf"); @@ -1265,6 +1381,10 @@ loadedDocument.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load an existing PDF document Dim loadedDocument As New PdfLoadedDocument("file1.pdf") @@ -1293,10 +1413,13 @@ Syncfusion PDF Library provides support to check whether the existing PDF docume {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Find_corrupted_PDF_document/.NET/Find_corrupted_PDF_document/Program.cs" %} + +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using System.Text; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -//Create a new instance for the PDF analyzer -PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(docStream); +PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer("Input.pdf"); //Get the syntax errors SyntaxAnalyzerResult result = analyzer.AnalyzeSyntax(); @@ -1321,6 +1444,10 @@ analyzer.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using System.Text; + //Create a new instance for the PDF analyzer PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer("Input.pdf"); @@ -1347,6 +1474,10 @@ analyzer.Close(); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Create a new instance for the PDF analyzer Dim analyzer As PdfDocumentAnalyzer = New PdfDocumentAnalyzer("Input.pdf") @@ -1379,6 +1510,9 @@ Refer to the following code sample to achieve the same, {% tabs %} {% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.Pdf.Parsing; + //Load an existing document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf"); //Embed all the non-embedded fonts. @@ -1393,6 +1527,9 @@ loadedDocument.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf.Parsing + //Load an existing document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("input.pdf") // Embed all the non-embedded fonts. @@ -1415,6 +1552,8 @@ The Essential® PDF allows you to get or set the [BaseUri](https:/ {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Add_BaseUri_in_the_PDF_document/.NET/Add_BaseUri_in_the_PDF_document/Program.cs" %} +using Syncfusion.Pdf; + //Create a new instance of the PdfDocument class. PdfDocument document = new PdfDocument(); //Set the Base URI. @@ -1423,14 +1562,15 @@ document.BaseUri = "https://www.syncfusion.com/"; PdfPage page = document.Pages.Add(); //Save the document. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +document.Save("Output.pdf"); //Close the document. document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; + //Create a new instance of the PdfDocument class. PdfDocument document = new PdfDocument(); //Set the Base URI. @@ -1446,6 +1586,9 @@ document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf.Parsing + 'Create a new instance of the PdfDocument class. Dim document As PdfDocument = New PdfDocument() 'Set the Base URI. @@ -1467,17 +1610,21 @@ The following code example illustrates the retrieval of [BaseUri](https://help.s {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Retrieve_BaseUri_from_the_existing_PDF/.NET/Retrieve_BaseUri_from_the_existing_PDF/Program.cs" %} -//Load the PDF document as file stream. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -//Load a PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf.Parsing; + +//Load an existing PDF document. +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the Base URI. string baseUri = document.BaseUri; //Close the document. document.Close(true); + {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} + +using Syncfusion.Pdf.Parsing; + //Load an existing document. PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); @@ -1488,6 +1635,9 @@ document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf.Parsing + 'Load an existing document. Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the Base URI. @@ -1507,6 +1657,10 @@ Essential® PDF enables you to track the save progress through the {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Document/Create-a-PDF-document-with-save-progress/.NET/PDF-document-with-save-progress/Program.cs" %} + using Syncfusion.Pdf.Graphics; + using Syncfusion.Pdf; + using Syncfusion.Drawing; + // Create a new PDF document. PdfDocument document = new PdfDocument(); @@ -1529,13 +1683,8 @@ Essential® PDF enables you to track the save progress through the // Subscribe to the SaveProgress event. document.SaveProgress += new PdfDocument.ProgressEventHandler(document_SaveProgress); - // Create a file stream to save the PDF document. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - // Save the PDF document to the file stream. - document.Save(outputFileStream); - } - + //Save the document. + document.Save("Output.pdf"); // Close the document. document.Close(true); @@ -1551,6 +1700,10 @@ Essential® PDF enables you to track the save progress through the {% highlight c# tabtitle="C# [Windows-specific]" %} + using Syncfusion.Pdf.Graphics; + using Syncfusion.Pdf; + using System.Drawing; + // Create a new PDF document. PdfDocument document = new PdfDocument(); // Add multiple pages to the document. @@ -1567,12 +1720,8 @@ Essential® PDF enables you to track the save progress through the } // Subscribe to the SaveProgress event. document.SaveProgress += new PdfDocument.ProgressEventHandler(document_SaveProgress); - // Create a file stream to save the PDF document. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - // Save the PDF document to the file stream. - document.Save(outputFileStream); - } + //Save the document. + document.Save("Output.pdf"); // Close the document. document.Close(true); @@ -1587,6 +1736,10 @@ Essential® PDF enables you to track the save progress through the {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + Imports Syncfusion.Pdf.Graphics + Imports Syncfusion.Pdf + Imports Syncfusion.Drawing + Module Program Sub Main() ' Create a new PDF document. @@ -1604,11 +1757,8 @@ Essential® PDF enables you to track the save progress through the Next ' Subscribe to the SaveProgress event. AddHandler document.SaveProgress, AddressOf document_SaveProgress - ' Create a file stream to save the PDF document. - Using outputFileStream As New FileStream(Path.GetFullPath("../../../Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite) - ' Save the PDF document to the file stream. - document.Save(outputFileStream) - End Using + ' Save the document. + document.Save("Output.pdf") ' Close the document. document.Close(True) End Sub From 8b5061c73938863d27347cc07b1d7daeff775c03 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Wed, 8 Oct 2025 18:31:40 +0530 Subject: [PATCH 3/5] 985863-ug: Modified 3 md files. --- .../NET/Working-with-Flow-Layout.md | 76 +++++++++--- .../NET/Working-with-Headers-and-Footers.md | 35 ++++-- .../NET/Working-with-HyperLinks.md | 114 ++++++++++++++---- 3 files changed, 179 insertions(+), 46 deletions(-) diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Flow-Layout.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Flow-Layout.md index 5a5e0eb6d..3bceda99c 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Flow-Layout.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Flow-Layout.md @@ -90,11 +90,11 @@ PdfDocument pdfDocument = render.ConvertToPDF(wordDocument); render.Dispose(); wordDocument.Dispose(); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); -//Close the documents. +//Save and close the PDF document. +pdfDocument.Save("Output.pdf"); pdfDocument.Close(true); +//Close the document. +wordDocument.Close(); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} @@ -180,6 +180,11 @@ You can create PDF document with text and image using the following code snippet {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" %} + +using Syncfusion.Pdf; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocToPDFConverter; + //A new document is created. WordDocument document = new WordDocument(); //Adding a new section to the document. @@ -230,15 +235,18 @@ PdfDocument pdfDocument = render.ConvertToPDF(document); render.Dispose(); document.Dispose(); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); -//Close the documents. +//Saves the PDF file. +pdfDocument.Save("Sample.pdf"); pdfDocument.Close(true); +document.Close(); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocToPDFConverter; + //A new document is created. WordDocument document = new WordDocument(); //Adding a new section to the document. @@ -293,6 +301,11 @@ document.Close(); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.DocIO.DLS +Imports Syncfusion.DocToPDFConverter +Imports Syncfusion.Pdf + 'A new document is created Dim document As New WordDocument() 'Adding a new section to the document @@ -355,6 +368,11 @@ You can create PDF document with simple table using the following code snippet. {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" %} + +using Syncfusion.Pdf; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocToPDFConverter; + //Creates a new Word document. WordDocument wordDocument = new WordDocument(); //Adding a new section to the document. @@ -424,15 +442,19 @@ PdfDocument pdfDocument = render.ConvertToPDF(wordDocument); render.Dispose(); wordDocument.Dispose(); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); -//Close the documents. +//Save and close the PDF document. +pdfDocument.Save("Output.pdf"); pdfDocument.Close(true); +//Close the document. +wordDocument.Close(); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocToPDFConverter; + //Creates a new Word document. WordDocument wordDocument = new WordDocument(); //Adding a new section to the document. @@ -508,6 +530,11 @@ wordDocument.Close(); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.DocIO.DLS +Imports Syncfusion.DocToPDFConverter +Imports Syncfusion.Pdf + 'Creates a new Word document Dim wordDocument As New WordDocument() 'Adding a new section to the document @@ -593,7 +620,13 @@ Syncfusion Essential® PDF supports creating a PDF document with f The following code snippet explains how to create a PDF document with image, paragraph text, header text, a line below the header text, and a table using flow model. {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C#" [Cross-platform] %} + +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Grid; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -650,15 +683,20 @@ grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable5DarkAccent5); //Draw the table in page, below the line with a height gap of 20. grid.Draw(page, new PointF(0, layoutResult.Bounds.Bottom + 20)); -//Saving the PDF to the MemoryStream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the PDF document. +document.Save("Output.pdf"); //Close the instance of PdfDocument. document.Close(true); + {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Grid; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -722,6 +760,12 @@ document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Grid + 'Create a new PDF document Dim document As PdfDocument = New PdfDocument 'Add a page to the document diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Headers-and-Footers.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Headers-and-Footers.md index dd22c7e57..ad0b75ad9 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Headers-and-Footers.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Headers-and-Footers.md @@ -22,6 +22,10 @@ The below code snippet explains how to draw the page numbers in footer using aut {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Header%20and%20Footer/Adding-an-automatic-field-in-header-and-footer/.NET/Adding-an-automatic-field-in-header-and-footer/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document @@ -52,16 +56,18 @@ compositeField.Draw(footer.Graphics, new PointF(470, 40)); //Add the footer template at the bottom. pdfDocument.Template.Bottom = footer; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); -//Closes the document. +//Save and close the document. +pdfDocument.Save("Output.pdf"); pdfDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document @@ -98,6 +104,10 @@ pdfDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document. Dim pdfDocument As New PdfDocument() 'Add a page to the PDF document. @@ -146,6 +156,10 @@ The example below illustrates how to implement a dynamic footer that updates uni {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Header%20and%20Footer/Adding-dynamic-headers-and-footers-in-PDF/.NET/Adding-dynamic-headers-and-footers-in-PDF/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + // Create a new PDF document. PdfDocument document = new PdfDocument(); @@ -213,10 +227,7 @@ PdfPage firstPage = document.Pages.Add(); textElement.Draw(firstPage, new PointF(0, headerHeight)); // Save and close the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) -{ - document.Save(outputFileStream); -} +document.Save("Output.pdf"); document.Close(true); // Add header and footer to every page. @@ -249,6 +260,10 @@ static void PageAddedHandler(object sender, PageAddedEventArgs e) {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + // Create a new PDF document. PdfDocument document = new PdfDocument(); @@ -349,6 +364,10 @@ static void PageAddedHandler(object sender, PageAddedEventArgs e) {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + ' Create a new PDF document. Dim document As New PdfDocument() 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 2a18cf994..ee5922abf 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-HyperLinks.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-HyperLinks.md @@ -11,7 +11,7 @@ In PDF, hyperlinks can be added to allow the users to navigate to another part o ## 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. +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. Please refer the below code snippet for navigating to the web page. @@ -19,6 +19,11 @@ Please refer the below code snippet for navigating to the web page. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Hyperlinks/Navigate-to-specific-URL-from-a-PDF-document/.NET/Navigate-to-specific-URL-from-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -37,9 +42,8 @@ textLink.Font = font; //Draw the hyperlink in PDF page. textLink.DrawTextWebLink(page, new PointF(10, 40)); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -47,6 +51,11 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -74,6 +83,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document. Dim document As New PdfDocument() 'Add a page to the document. @@ -109,9 +122,14 @@ To add a web hyperlink to an existing document, please refer the below code snip {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Hyperlinks/Add-a-web-hyperlink-to-an-existing-PDF-document/.NET/Add-a-web-hyperlink-to-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the page. PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Create the font. @@ -128,9 +146,8 @@ textLink.Font = font; //Draw the hyperlink in loaded page graphics. textLink.DrawTextWebLink(loadedPage.Graphics, new PointF(10, 40)); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Output.pdf"); //Close the document. loadedDocument.Close(true); @@ -138,6 +155,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"Filename.pdf"); //Load the page. @@ -165,6 +188,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing + 'Load the existing PDF document. Dim loadedDocument As New PdfLoadedDocument("fileName.pdf") 'Load the page. @@ -202,6 +230,11 @@ To allow the users to navigate to any other part of the same document, [PdfDocum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Hyperlinks/Add-the-hyperlink-for-internal-document-navigation/.NET/Add-the-hyperlink-for-internal-document-navigation/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Create a new page. @@ -228,9 +261,8 @@ documentLinkAnnotation.Destination.Zoom = 5; //Add this annotation to a new page. page.Annotations.Add(documentLinkAnnotation); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -238,6 +270,11 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Create a new page. @@ -273,6 +310,10 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document. Dim document As New PdfDocument() 'Create a new page. @@ -316,9 +357,14 @@ To add a [PdfDocumentLinkAnnotation](https://help.syncfusion.com/cr/document-pro {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Hyperlinks/Internal-document-navigation-to-an-existing-PDF/.NET/Internal-document-navigation-to-an-existing-PDF/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("fileName.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the page. PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Create a new rectangle. @@ -337,9 +383,8 @@ documentLinkAnnotation.Destination.Location = new PointF(10, 0); //Add this annotation to respective page. loadedPage.Annotations.Add(documentLinkAnnotation); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Output.pdf"); //Close the document. loadedDocument.Close(true); @@ -347,6 +392,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"fileName.pdf"); //Load the page. @@ -376,6 +427,11 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing + 'Load the existing PDF document. Dim loadedDocument As New PdfLoadedDocument("fileName.pdf") 'Load the page. @@ -417,6 +473,9 @@ Please refer the below code snippet for navigating to external documents. {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create the PDF document. PdfDocument document = new PdfDocument(); //Creates a new page. @@ -429,9 +488,8 @@ PdfFileLinkAnnotation fileLinkAnnotation = new PdfFileLinkAnnotation(bounds, fil //Add this annotation to a page. page.Annotations.Add(fileLinkAnnotation); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -439,6 +497,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create the PDF document. PdfDocument document = new PdfDocument(); //Creates a new page. @@ -460,6 +521,9 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + 'Create the PDF document Dim document As New PdfDocument() 'Creates a new page and adds it as the last page of the document @@ -495,7 +559,10 @@ To open a file in relative path, the [PdfLaunchAction](https://help.syncfusion.c {% endhighlight %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C#" [Windows-specific] %} + +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; //Create a new PDF document. PdfDocument document = new PdfDocument(); @@ -520,7 +587,10 @@ document.Close(); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET" [Windows-specific] %} + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive 'Create a new PDF document Dim document As New PdfDocument() From 1bb765bb9fffb842b0d213e8bb5ac0c901b309ab Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Thu, 9 Oct 2025 13:30:01 +0530 Subject: [PATCH 4/5] 985863-ug: Updated four files. --- .../NET/Working-with-Image-Extraction.md | 54 +++++- .../PDF-Library/NET/Working-with-Images.md | 177 +++++++++++++----- .../NET/Working-with-JavaScript.md | 83 ++++---- .../PDF-Library/NET/Working-with-Layers.md | 174 ++++++----------- 4 files changed, 272 insertions(+), 216 deletions(-) diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Image-Extraction.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Image-Extraction.md index c1e9a3cf1..ee399f432 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Image-Extraction.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Image-Extraction.md @@ -15,9 +15,12 @@ Refer to the following code snippet to extract the images from a PDF page. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Image%20Extraction/Extract-images-from-a-PDF-pages/.NET/Extract-images-from-a-PDF-pages/Program.cs" %} -//Load an existing PDF -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Exporting; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the first page PdfPageBase pageBase = loadedDocument.Pages[0]; @@ -30,8 +33,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Exporting; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the first page PdfPageBase pageBase = loadedDocument.Pages[0]; @@ -44,8 +51,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Exporting +Imports Syncfusion.Pdf.Parsing + 'Load an existing PDF -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Load the first page Dim pageBase As PdfPageBase = loadedDocument.Pages(0) @@ -72,9 +83,13 @@ Refer to the following code snippet to extract the image info from a PDF page. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Image%20Extraction/Extract-the-image-info-from-a-PDF-page/.NET/Extract-the-image-info-from-a-PDF-page/Program.cs" %} -//Load an existing PDF -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Exporting; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the first page PdfPageBase pageBase = loadedDocument.Pages[0]; @@ -87,8 +102,13 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Exporting; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the first page PdfPageBase pageBase = loadedDocument.Pages[0]; @@ -101,8 +121,13 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Exporting +Imports Syncfusion.Pdf.Parsing + 'Load an existing PDF -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Load the first page Dim pageBase As PdfPageBase = loadedDocument.Pages(0) @@ -125,6 +150,9 @@ The following code example illustrates how to extract images from an entire PDF {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Image%20Extraction/Extract-images-from-PDF-documents/.NET/Extract-images-from-PDF-documents/Program.cs" %} +using Syncfusion.Pdf.Parsing; +using System.IO; + //Get stream from an existing PDF document. FileStream inputStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); //Initialize the PDF document extractor. @@ -144,6 +172,9 @@ documentExtractor.Dispose(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using System.IO; + //Get stream from an existing PDF document. FileStream inputStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); //Initialize the PDF document extractor. @@ -163,6 +194,9 @@ documentExtractor.Dispose(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports System.IO + 'Get stream from an existing PDF document. Dim inputStream As FileStream = New FileStream("Input.pdf", FileMode.Open, FileAccess.Read) 'Initialize the PDF document extractor. 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 33c5f9f79..38ca465a8 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md @@ -34,6 +34,9 @@ The following code snippet shows how to add a file from disk to the PDF document {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Images/Insert-image-in-a-new-PDF-document/.NET/Insert-image-in-a-new-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document @@ -47,10 +50,8 @@ PdfBitmap image = new PdfBitmap(imageStream); //Draw the image graphics.DrawImage(image, 0, 0); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -doc.Save(stream); +//Save the document +doc.Save("Output.pdf"); //Close the document doc.Close(true); @@ -58,6 +59,9 @@ doc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document @@ -79,6 +83,9 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document Dim doc As New PdfDocument() 'Add a page to the document @@ -110,9 +117,12 @@ You can also add images into an existing PDF document using the below code snipp {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Images/Insert-image-in-an-existing-PDF-document/.NET/Insert-image-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument doc = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf"); //Get first page from document PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage; @@ -124,10 +134,8 @@ PdfBitmap image = new PdfBitmap(imageStream); //Draw the image graphics.DrawImage(image, 0, 0); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -doc.Save(stream); +//Save the document +doc.Save("Output.pdf"); //Close the document doc.Close(true); @@ -135,6 +143,10 @@ doc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load a PDF document PdfLoadedDocument doc = new PdfLoadedDocument("input.pdf"); //Get first page from document @@ -156,6 +168,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing + 'Load a PDF document Dim doc As New PdfLoadedDocument("input.pdf") 'Get first page from document @@ -182,9 +198,12 @@ To add image from stream, use the below code snippet. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Images/Insert-image-in-an-existing-PDF-document/.NET/Insert-image-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument doc = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf"); //Get first page from document PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage; @@ -196,10 +215,8 @@ PdfBitmap image = new PdfBitmap(imageStream); //Draw the image graphics.DrawImage(image, 0, 0); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -doc.Save(stream); +//Save the document +doc.Save("Output.pdf"); //Close the document doc.Close(true); @@ -207,6 +224,10 @@ doc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load a PDF document PdfLoadedDocument doc = new PdfLoadedDocument("input.pdf"); //Get first page from document @@ -230,6 +251,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing + 'Load a PDF document Dim doc As New PdfLoadedDocument("input.pdf") 'Get first page from document @@ -278,6 +303,10 @@ The following code illustrate this, {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using System.Drawing; + //Create a PDF Document PdfDocument doc = new PdfDocument(); //Add pages to the document @@ -304,6 +333,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Create a PDF Document Dim doc As New PdfDocument() 'Add pages to the document @@ -342,6 +375,9 @@ The following code illustrate shows how to add a mask to TIFF image. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Images/Add-a-mask-to-TIFF-image/.NET/Add-a-mask-to-TIFF-image/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a PDF document PdfDocument doc = new PdfDocument(); //Add pages to the document @@ -360,9 +396,8 @@ image.Mask = mask; graphics.DrawImage(image, 0, 0); ///Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -doc.Save(stream); +//Save the document +doc.Save("Output.pdf"); //Close the document doc.Close(true); @@ -370,6 +405,9 @@ doc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a PDF document PdfDocument doc = new PdfDocument(); //Add pages to the document @@ -394,6 +432,9 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a PDF document Dim doc As New PdfDocument() 'Add pages to the document @@ -430,9 +471,11 @@ Essential® PDF allows you to replace images in an existing docume {% highlight c# tabtitle="C# [Cross-platform]" %} -//Load an existing PDF document. -FileStream pdfStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(pdfStream); +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create an image instance. FileStream imageStream = new FileStream(Path.GetFullPath("Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read); @@ -440,9 +483,8 @@ PdfBitmap bmp = new PdfBitmap(imageStream); //Replace the first image in the page loadedDocument.Pages[0].ReplaceImage(0, bmp); -MemoryStream stream = new MemoryStream(); -//Save the document as stream -loadedDocument.Save(stream); +//Save the document +loadedDocument.Save("Output.pdf"); //Close the document loadedDocument.Close(true); @@ -450,6 +492,9 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load the PDF document PdfLoadedDocument doc = new PdfLoadedDocument(@"image.pdf"); //Create an image instance @@ -466,6 +511,9 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Graphics + 'Load the PDF document Dim doc As New PdfLoadedDocument("image.pdf") 'Create an image instance @@ -492,6 +540,9 @@ You can allow a large image to paginate across multiple pages in the PDF documen {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Images/Paginate-an-image-in-PDF-document/.NET/Paginate-an-image-in-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create Document PdfDocument doc = new PdfDocument(); //Add new page @@ -507,17 +558,17 @@ format.Layout = PdfLayoutType.Paginate; //Draw image image.Draw(page, 20, 400, format); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -doc.Save(stream); -//Close the document +//Save the PDF +doc.Save("output.pdf"); doc.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create Document PdfDocument doc = new PdfDocument(); //Add new page @@ -540,6 +591,9 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create Document Dim doc As New PdfDocument() 'Add new page @@ -572,6 +626,9 @@ You can add transparency and rotation to the image using [SetTransparency](https {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Images/Add-transparancy-and-rotation-to-the-image/.NET/Add-transparancy-and-rotation-to-the-image/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create Document PdfDocument doc = new PdfDocument(); //Add a new page @@ -594,17 +651,17 @@ image.Draw(page, 0, 0); //Restore the graphics state page.Graphics.Restore(state); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as strea -doc.Save(stream); -//Close the document +//Save the PDF +doc.Save("output.pdf"); doc.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create Document PdfDocument doc = new PdfDocument(); //Add a new page @@ -633,6 +690,9 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create Document Dim doc As New PdfDocument() 'Add a new page @@ -673,6 +733,9 @@ The code snippet to illustrate the same is given below. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Images/Converting-multi-page-TIFF-to-PDF/.NET/Converting-multi-page-TIFF-to-PDF/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument doc = new PdfDocument(); //Set page margins @@ -691,17 +754,17 @@ for (int i = 0; i < frameCount; i++) tiffImage.ActiveFrame = i; graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height); } -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -doc.Save(stream); -//Close the document -doc.Close(true); +//Save and close the document +pdfDocument.Save("Sample.pdf"); +pdfDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a PDF document PdfDocument pdfDocument = new PdfDocument(); //Set page margins @@ -728,6 +791,9 @@ pdfDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a PDF document Dim pdfDocument As New PdfDocument() 'Set page margins @@ -767,27 +833,31 @@ The code snippet to illustrate the same is given below. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Images/Remove-images-from-PDF-document/.NET/Remove-images-from-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Exporting; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the first page. PdfPageBase pageBase = loadedDocument.Pages[0]; //Extract images from the first page. PdfImageInfo[] imageInfo = loadedDocument.Pages[0].GetImagesInfo(); //Remove the Image. pageBase.RemoveImage(imageInfo[0]); -//Create the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -loadedDocument.Save(stream); -//Close the document +//Save and close the document +loadedDocument.Save("Sample.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Exporting; +using Syncfusion.Pdf.Parsing; + //Load a PDF document PdfLoadedDocument doc = new PdfLoadedDocument("input.pdf"); //Load the first page @@ -805,6 +875,10 @@ doc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load an existing PDF Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("input.pdf") 'Load the first page @@ -813,10 +887,9 @@ Dim pageBase As PdfPageBase = loadedDocument.Pages(0) Dim imageInfo As PdfImageInfo = pageBase.ImagesInfo(0) 'Remove the Image pageBase.RemoveImage(imageInfo) -Dim stream As New MemoryStream() 'Save the document -loadedDocument.Save(stream) +loadedDocument.Save("Output.pdf") 'Close the document loadedDocument.Close(True) diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-JavaScript.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-JavaScript.md index 07ad2112a..966551198 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-JavaScript.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-JavaScript.md @@ -22,6 +22,9 @@ You can add the JavaScript action to the PDF document by using [PdfJavaScriptAct {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/JavaScript/Add-the-JavaScript-action-to-the-PDF-document/.NET/Add-the-JavaScript-action-to-the-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new document PdfDocument document = new PdfDocument(); //Add a page @@ -32,23 +35,17 @@ PdfJavaScriptAction scriptAction = new PdfJavaScriptAction("app.alert(\"Hello Wo //Add the JavaScript action document.Actions.AfterOpen = scriptAction; -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save and close the PDF document +document.Save("Output.pdf"); document.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new document PdfDocument document = new PdfDocument(); //Add a page @@ -67,6 +64,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + 'Create a new document Dim document As New PdfDocument() 'Add a page @@ -97,6 +97,11 @@ The following code snippet illustrate this. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/JavaScript/Add-JavaScript-action-to-the-form-fields-in-a-PDF/.NET/Add-JavaScript-action-to-the-form-fields-in-a-PDF/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Creates a new page @@ -116,23 +121,19 @@ submitButton.Actions.MouseDown = scriptAction; //Add the submit button to the new document document.Form.Fields.Add(submitButton); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save and close the PDF document +document.Save("Output.pdf"); document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Creates a new page @@ -161,6 +162,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document Dim document As New PdfDocument() 'Creates a new page @@ -199,6 +205,10 @@ The 3D Annotations are used to represent 3D artworks in a PDF document. You can {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/JavaScript/Add-JavaScript-to-3D-annotation-in-a-PDF-document/.NET/Add-JavaScript-to-3D-annotation-in-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Creates a new page @@ -218,23 +228,18 @@ pdf3dAnnotation.Activation = activation; //Adds annotation to page page.Annotations.Add(pdf3dAnnotation); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Closes the document +//Save and close the PDF document +document.Save("Output.pdf"); document.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "3DAnnotation.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Creates a new PDF document PdfDocument document = new PdfDocument(); //Creates a new page @@ -261,6 +266,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + 'Creates a new PDF document Dim document As New PdfDocument() 'Creates a new page @@ -297,6 +306,10 @@ Add or modify the JavaScript action in a [PdfLoadedDocument](https://help.syncfu {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -312,6 +325,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + 'Load the PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Layers.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Layers.md index 11603afce..bdd9a615d 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Layers.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Layers.md @@ -20,6 +20,10 @@ Essential® PDF allows the users to create a layer in a PDF page u {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Adding-layers-in-a-PDF-document/.NET/Adding-layers-in-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create PDF document. PdfDocument document = new PdfDocument(); //Add the page. @@ -41,23 +45,19 @@ graphics.TranslateTransform(100, 180); //Draw ellipse. graphics.DrawEllipse(pen, bounds); -//Save and close the document. -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document. +//Save the document. +document.Save("Sample.pdf"); +//Close the document document.Close(true); -//Defining the ContentType for PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create PDF document. PdfDocument document = new PdfDocument(); //Add the page. @@ -126,9 +126,13 @@ The below code illustrates how to add the multiple layers in an existing PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Add-the-multiple-layers-in-an-existing-PDF-document/.NET/Add-the-multiple-layers-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get first page from document PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -148,25 +152,22 @@ graphics.TranslateTransform(100, 180); //Draw ellipse. graphics.DrawEllipse(pen, bounds); -//Save and close the document -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Close the document. -loadedDocument.Close(true); -//Defining the ContentType for pdf file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); +//Save the document. +document.Save("Sample.pdf"); +//Close the document +document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} -//Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get first page from document PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -196,7 +197,7 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} 'Load the existing PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get first page from document Dim loadedPage As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage) @@ -255,18 +256,10 @@ annotation.Layer = layer; //Add annotation to the created page page.Annotations.Add(annotation); -//Save and close the document -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; +//Save the document. +document.Save("Sample.pdf"); //Close the document document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} @@ -339,8 +332,7 @@ The following code illustrates how to add annotation to the layers in an existin {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Add-annotation-to-the-layer-in-an-existing-PDF-document/.NET/Add-annotation-to-the-layer-in-an-existing-PDF-document/Program.cs" %} //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the first page from the document PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -359,18 +351,10 @@ annotation.Layer = Layer; //Add annotation to the created page loadedPage.Annotations.Add(annotation); -//Save and close the document -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; +//Save the document. +loadedDocument.Save("Sample.pdf"); //Close the document loadedDocument.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} @@ -466,20 +450,10 @@ graphics.TranslateTransform(100, 180); //Draw an ellipse graphics.DrawEllipse(pen, bounds); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -document.Save(stream); -//If the position is not set to '0', the PDF will be empty -stream.Position = 0; +//Save the document. +document.Save("Sample.pdf"); //Close the document document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} @@ -558,8 +532,7 @@ You can remove the layers using [RemoveAt](https://help.syncfusion.com/cr/docume {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Removing-layers-from-an-existing-PDF-document/.NET/Removing-layers-from-an-existing-PDF-document/Program.cs" %} //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Gets the first page from the document PdfLoadedPage loadedPage = document.Pages[0] as PdfLoadedPage; @@ -568,18 +541,10 @@ PdfPageLayerCollection layers = loadedPage.Layers; //Remove the layer layers.RemoveAt(0); -//Save and close the document -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; +//Save the document +document.Save("Output.pdf"); //Close the document document.Close(true); -//Defining the ContentType for pdf file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); {% endhighlight %} @@ -634,23 +599,17 @@ You can flatten a layer in a PDF document by removing it from the [PdfDocumentLa {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Flattening-the-layers-in-an-existing-PDF-document/.NET/Flattening-the-layers-in-an-existing-PDF-document/Program.cs" %} //Load the existing PDF document -FileStream inputStream = new FileStream("Layers.pdf", FileMode.Open); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the layer collection PdfDocumentLayerCollection layers = loadedDocument.Layers; //Flatten a layer in the PDF document layers.RemoveAt(0); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -//Set the position as '0' -stream.Position = 0; -//Download the PDF document in the browser -FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); -fileStreamResult.FileDownloadName = "Output.pdf"; -return fileStreamResult; +//Save the PDF document +loadedDocument.Save("Output.pdf"); +//Close the instance of PdfLoadedDocument +loadedDocument.Close(true); {% endhighlight %} @@ -724,18 +683,10 @@ graphics.TranslateTransform(100, 180); //Draw ellipse graphics.DrawEllipse(pen, bounds); -//Save and close the document -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save the PDF document +document.Save("Output.pdf"); +//Close the instance of PdfLoadedDocument document.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} @@ -813,26 +764,17 @@ The following code illustrates how to toggle the visibility of layers in an exis {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Toggle-the-visibility-of-layers-in-an-existing-PDF/.NET/Toggle-the-visibility-of-layers-in-an-existing-PDF/Program.cs" %} //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Gets the first layer from the layer collection PdfLayer layer = document.Layers[0]; //Disable the visibility layer.Visible = false; -//Save and close the document -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; +//Save the document +document.Save("Output.pdf"); //Close the document document.Close(true); -//Defining the content type for PDF file. -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} @@ -899,20 +841,10 @@ PdfGraphics graphics = layer.CreateGraphics(page); //Draw ellipse. graphics.DrawEllipse(PdfPens.Red, new RectangleF(50, 50, 40, 40)); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document into stream. -document.Save(stream); -//If the position is not set to '0,' then the PDF will be empty. -stream.Position = 0; -//Close the document. +//Save the PDF document. +document.Save("Output.pdf"); +//Close the PDF document. document.Close(true); -//Defining the content type for a PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); {% endhighlight %} From f8eb7e78ddefbee0e5526b4e905ca36142a4628a Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Thu, 9 Oct 2025 18:08:37 +0530 Subject: [PATCH 5/5] 985863-ug: Added nine file changes. --- .../NET/Working-with-HyperLinks.md | 4 +- .../PDF-Library/NET/Working-with-Layers.md | 112 +++++ .../PDF-Library/NET/Working-with-Metadata.md | 317 +++++++------- .../NET/Working-with-Named-Destination.md | 86 +++- .../NET/Working-with-PDF-Conformance.md | 400 ++++++++++-------- .../NET/Working-with-PDF-Templates.md | 144 +++++-- .../PDF/PDF-Library/NET/Working-with-Pages.md | 365 ++++++++++------ .../PDF-Library/NET/Working-with-Portfolio.md | 69 ++- .../PDF-Library/NET/Working-with-Redaction.md | 299 +++++++++---- 9 files changed, 1135 insertions(+), 661 deletions(-) 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 ee5922abf..cce02b755 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-HyperLinks.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-HyperLinks.md @@ -1,11 +1,11 @@ --- -title: Working with Hyperlinks | Syncfusion +title: Working with Hyperlinks in PDF | Syncfusion description: This section explains how to add hyperlink in a new and existing PDF document using Syncfusion .NET PDF library platform: document-processing control: PDF documentation: UG --- -# Working with Hyperlinks +# Working with Hyperlinks in PDF 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. diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Layers.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Layers.md index bdd9a615d..98e5eb3c2 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Layers.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Layers.md @@ -88,6 +88,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Create PDF document. Dim document As New PdfDocument() 'Add the page. @@ -196,6 +200,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing +Imports System.Drawing + 'Load the existing PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get first page from document @@ -236,6 +245,11 @@ Essential® PDF allows the users to add different types of [Annota {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Adding-annotation-to-layer-in-the-PDF-document/.NET/Adding-annotation-to-layer-in-the-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create new PDF document PdfDocument document = new PdfDocument(); //Add page @@ -265,6 +279,11 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create new PDF document PdfDocument document = new PdfDocument(); //Add page @@ -294,6 +313,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Interactive +Imports System.Drawing + 'Create new PDF document Dim document As New PdfDocument() 'Add page @@ -331,6 +355,12 @@ The following code illustrates how to add annotation to the layers in an existin {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Add-annotation-to-the-layer-in-an-existing-PDF-document/.NET/Add-annotation-to-the-layer-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the first page from the document @@ -360,6 +390,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the first page from the document @@ -389,6 +425,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Interactive +Imports System.Drawing + 'Load the existing PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Gets the first page from the document @@ -428,6 +470,10 @@ Essential® PDF allows users to add nested layers in the PDF docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Add-nested-layers-in-the-PDF-document/.NET/Add-nested-layers-in-the-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create the PDF document PdfDocument document = new PdfDocument(); //Add the page @@ -459,6 +505,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create the PDF document PdfDocument document = new PdfDocument(); //Add the page @@ -490,6 +540,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Create the PDF document Dim document As New PdfDocument() 'Add the page @@ -531,6 +585,9 @@ You can remove the layers using [RemoveAt](https://help.syncfusion.com/cr/docume {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Removing-layers-from-an-existing-PDF-document/.NET/Removing-layers-from-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Gets the first page from the document @@ -550,6 +607,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Gets the first page from the document @@ -569,6 +629,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load the existing PDF document Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Gets the first page from the document @@ -598,6 +661,9 @@ You can flatten a layer in a PDF document by removing it from the [PdfDocumentLa {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Flattening-the-layers-in-an-existing-PDF-document/.NET/Flattening-the-layers-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -615,6 +681,9 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Layers.pdf"); @@ -632,6 +701,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load the existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Layers.pdf") @@ -661,6 +733,10 @@ The below code illustrates how to toggle the visibility of layers in new PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Toggle-the-visibility-of-layers-in-new-PDF-document/.NET/Toggle-the-visibility-of-layers-in-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create the document PdfDocument document = new PdfDocument(); //Create a page @@ -692,6 +768,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create the document PdfDocument document = new PdfDocument(); //Create a page @@ -724,6 +804,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing 'Create the document Dim document As New PdfDocument() 'Create a page @@ -763,6 +846,9 @@ The following code illustrates how to toggle the visibility of layers in an exis {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Toggle-the-visibility-of-layers-in-an-existing-PDF/.NET/Toggle-the-visibility-of-layers-in-an-existing-PDF/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); @@ -780,6 +866,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); @@ -797,6 +886,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load the existing PDF document Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") @@ -826,6 +918,10 @@ The following code sample shows how to add a lock state to the layer in a new PD {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Layer/Add-a-lock-state-to-the-layer-in-a-new-PDF-document/.NET/Add-a-lock-state-to-the-layer-in-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creating a new PDF document. PdfDocument document = new PdfDocument(); //Adding a new page to the PDF document. @@ -850,6 +946,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creating a new PDF document. PdfDocument document = new PdfDocument(); //Adding a new page to the PDF document. @@ -874,6 +974,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Creating a new PDF document. Dim document As PdfDocument = New PdfDocument() 'Adding a new page to the PDF document. @@ -918,6 +1022,10 @@ This is illustrated in the following code sample. {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Layers.pdf"); @@ -941,6 +1049,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing + 'Load the existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Output.pdf") diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Metadata.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Metadata.md index 795912637..12093da51 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Metadata.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Metadata.md @@ -24,6 +24,9 @@ You can add XMP metadata in a PDF document using the [XmpMetadata](https://help. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Adding-XMP-metadata-in-PDF-document/.NET/Adding-XMP-metadata-in-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create a PDF document PdfDocument pdfDoc = new PdfDocument(); //Create a page @@ -47,22 +50,16 @@ basic.Nickname = "nickname"; basic.Rating.Add(-25); //Save and close the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "DocumentInformation.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create a PDF document PdfDocument pdfDoc = new PdfDocument(); //Create a page @@ -86,13 +83,16 @@ basic.Nickname = "nickname"; basic.Rating.Add(-25); //Save and close the document -pdfDoc.Save("DocumentInformation.pdf"); +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Create a PDF document Dim pdfDoc As New PdfDocument() 'Create a page @@ -133,9 +133,12 @@ You can add metadata in an existing PDF document using the [XmpMetadata](https:/ {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Adding-XMP-metadata-to-an-existing-PDF-document/.NET/Adding-XMP-metadata-to-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Xmp; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument pdfDoc = new PdfLoadedDocument(docStream); +PdfLoadedDocument pdfDoc = new PdfLoadedDocument("Input.pdf"); //Get XMP object XmpMetadata metaData = pdfDoc.DocumentInformation.XmpMetadata; @@ -155,22 +158,18 @@ basic.Nickname = "nickname"; basic.Rating.Add(-25); //Save and close the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "DocumentInformation.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); + {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Xmp; + //Load the document PdfLoadedDocument pdfDoc = new PdfLoadedDocument("input.pdf"); @@ -192,13 +191,17 @@ basic.Nickname = "nickname"; basic.Rating.Add(-25); //Save and close the document -pdfDoc.Save("DocumentInformation.pdf"); +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Load the document Dim pdfDoc As New PdfLoadedDocument("input.pdf") @@ -260,6 +263,9 @@ The [BasicSchema](https://help.syncfusion.com/cr/document-processing/Syncfusion. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Create-PDF-document-with-XMP-basic-schema/.NET/Create-PDF-document-with-XMP-basic-schema/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create a PDF document PdfDocument pdfDoc = new PdfDocument(); //Create a page @@ -283,22 +289,17 @@ basic.Nickname = "nickname"; basic.Rating.Add(-25); //Save and close the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "DocumentInformation.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); + {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create a PDF document PdfDocument pdfDoc = new PdfDocument(); //Create a page @@ -322,13 +323,16 @@ basic.Nickname = "nickname"; basic.Rating.Add(-25); //Save and close the document -pdfDoc.Save("DocumentInformation.pdf"); +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Create a PDF document Dim pdfDoc As New PdfDocument() 'Create a page @@ -381,6 +385,9 @@ The [DublinCoreSchema](https://help.syncfusion.com/cr/document-processing/Syncfu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Create-PDF-document-with-dubline-core-schema-properties/.NET/Create-PDF-document-with-dubline-core-schema-properties/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create new PDF document PdfDocument pdfDoc = new PdfDocument(); //Add a new page @@ -399,22 +406,16 @@ dublin.Type.Add("PDF"); dublin.Publisher.Add("Essential PDF"); //Save and close the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "DocumentInformation.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create new PDF document PdfDocument pdfDoc = new PdfDocument(); //Add a new page @@ -433,13 +434,16 @@ dublin.Type.Add("PDF"); dublin.Publisher.Add("Essential PDF"); //Save and close the document -pdfDoc.Save("DocumentInformation.pdf"); +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Create new PDF document Dim pdfDoc As New PdfDocument() 'Add a new page @@ -483,6 +487,9 @@ The [RightsManagementSchema](https://help.syncfusion.com/cr/document-processing/ {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Create-PDF-document-with-right-management-schema/.NET/Create-PDF-document-with-right-management-schema/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create PDF document PdfDocument pdfDoc = new PdfDocument(); //Add a new page @@ -499,22 +506,16 @@ rights.Owner.Add("Syncfusion"); rights.Marked = true; //Save and close the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "DocumentInformation.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create PDF document PdfDocument pdfDoc = new PdfDocument(); //Add a new page @@ -530,13 +531,16 @@ rights.Owner.Add("Syncfusion"); rights.Marked = true; //Save and close the document -pdfDoc.Save("DocumentInformation.pdf"); +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Create PDF document Dim pdfDoc As New PdfDocument() 'Add a new page @@ -572,6 +576,9 @@ This schema describes very simple workflow or job information and the [BasicJobT {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Create-PDF-document-with-basic-job-ticket-schema/.NET/Create-PDF-document-with-basic-job-ticket-schema/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create a document PdfDocument pdfDoc = new PdfDocument(); //Add a page @@ -586,22 +593,16 @@ BasicJobTicketSchema basicJob = metaData.BasicJobTicketSchema; basicJob.JobRef.Add("PDF document creation"); //Save and close the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document. +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "DocumentInformation.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create a document PdfDocument pdfDoc = new PdfDocument(); //Add a page @@ -616,13 +617,16 @@ BasicJobTicketSchema basicJob = metaData.BasicJobTicketSchema; basicJob.JobRef.Add("PDF document creation"); //Save and close the document -pdfDoc.Save("DocumentInformation.pdf"); +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Create a document Dim pdfDoc As New PdfDocument() 'Add a page @@ -661,6 +665,9 @@ The [PagedTextSchema](https://help.syncfusion.com/cr/document-processing/Syncfus {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Create-PDF-document-with-pages-text-schema/.NET/Create-PDF-document-with-pages-text-schema/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create a PDF document PdfDocument pdfDoc = new PdfDocument(); //Create a Page @@ -678,22 +685,16 @@ pagedText.NPages = 1; pagedText.PlateNames.Add("Sample page"); //Save and close the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "DocumentInformation.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create a Pdf document PdfDocument pdfDoc = new PdfDocument(); //Create a Page @@ -711,13 +712,16 @@ pagedText.NPages = 1; pagedText.PlateNames.Add("Sample page"); //Save and close the document -pdfDoc.Save("DocumentInformation.pdf"); +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Create a PDF document Dim pdfDoc As New PdfDocument() 'Create a Page @@ -752,6 +756,9 @@ This schema specifies the properties used with Adobe PDF documents. The [PDFSche {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Create-PDF-document-with-PDF-schema/.NET/Create-PDF-document-with-PDF-schema/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create a PDF document PdfDocument pdfDoc = new PdfDocument(); //Add a page @@ -768,22 +775,16 @@ pdfSchema.PDFVersion = "1.5"; pdfSchema.Keywords = "Essential PDF"; //Save and close the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "DocumentInformation.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create a PDF document PdfDocument pdfDoc = new PdfDocument(); //Add a page @@ -800,13 +801,16 @@ pdfSchema.PDFVersion = "1.5"; pdfSchema.Keywords = "Essential PDF"; //Save and close the document -pdfDoc.Save("DocumentInformation.pdf"); +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Create a PDF document Dim pdfDoc As New PdfDocument() 'Add a page @@ -845,6 +849,9 @@ Add the following code sample to define the custom schema in a PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Create-PDF-document-with-custom-schema/.NET/Create-PDF-document-with-custom-schema/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create PDF document PdfDocument pdfDoc = new PdfDocument(); //Add a new page @@ -860,23 +867,17 @@ customSchema["DOCID"] = "SYNCSAM001"; customSchema["Encryption"] = "Standard"; customSchema["Project"] = "Data processing"; -//Save the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document +//Save and close the document +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "DocumentInformation.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create Pdf document PdfDocument pdfDoc = new PdfDocument(); //Add a new page @@ -894,13 +895,16 @@ customSchema["Encryption"] = "Standard"; customSchema["Project"] = "Data processing"; //Save and close the document -pdfDoc.Save("DocumentInformation.pdf"); +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Create PDF document Dim pdfDoc As New PdfDocument() 'Add a new page @@ -935,6 +939,9 @@ Essential® PDF allows you to add required metadata (custom schema {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Adding-custom-schema-to-the-PDF-document/.NET/Adding-custom-schema-to-the-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create PDF document PdfDocument pdfDoc = new PdfDocument(); //Add a new page @@ -950,22 +957,16 @@ customSchema["creationDate"] = DateTime.Now.ToString(); customSchema["DOCID"] = "SYNCSAM001"; //Save and close the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "CustomMetaField.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create PDF document PdfDocument pdfDoc = new PdfDocument(); //Add a new page @@ -988,6 +989,9 @@ pdfDoc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Create PDF document Dim pdfDoc As New PdfDocument() 'Add a new page @@ -1020,6 +1024,9 @@ The custom metadata can be added in PDF document by using the [CustomMetadata](h {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Adding-custom-metadata-to-the-PDF-document/.NET/Adding-custom-metadata-to-the-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create PDF document PdfDocument pdfDoc = new PdfDocument(); //Add new PDF page @@ -1031,22 +1038,16 @@ pdfDoc.DocumentInformation.CustomMetadata["CompanyName"] = "Syncfusion"; pdfDoc.DocumentInformation.CustomMetadata["Key"] = "DocumentKey"; //Save and close the document -MemoryStream stream = new MemoryStream(); -pdfDoc.Save(stream); -stream.Position = 0; -//Close the document +pdfDoc.Save("Output.pdf"); pdfDoc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "AddCustomField.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; + //Create PDF document PdfDocument pdfDoc = new PdfDocument(); //Add new PDF page @@ -1065,6 +1066,9 @@ pdfDoc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Create PDF document Dim pdfDoc As New PdfDocument() 'Add new PDF page @@ -1093,30 +1097,28 @@ Removing the custom metadata from an existing PDF document using the [Remove](ht {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Remove-custom-metadata-from-an-existing-PDF-document/.NET/Remove-custom-metadata-from-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; +using Syncfusion.Pdf.Parsing; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Remove custom metadata using key name loadedDocument.DocumentInformation.CustomMetadata.Remove("Key"); //Save and close the document -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Close the document +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Xmp; +using Syncfusion.Pdf.Parsing; + //Load the document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -1131,6 +1133,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Load the document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") @@ -1159,6 +1165,10 @@ You can add the XMP metadata along with an image to the PDF document. The [PdfBi {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Adding-XMP-metadata-along-with-an-image-in-PDF/.NET/Adding-XMP-metadata-along-with-an-image-in-PDF/Program.cs" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using System.Reflection.Metadata; + //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document @@ -1172,24 +1182,18 @@ PdfBitmap image = new PdfBitmap(imageStream, true); //Draw the image graphics.DrawImage(image, 0, 0); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -doc.Save(stream); -stream.Position = 0; +//Save the document +doc.Save("Output.pdf"); //Close the document doc.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using System.Reflection.Metadata; + //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document @@ -1211,6 +1215,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Reflection.Metadata + 'Create a new PDF document Dim doc As New PdfDocument() 'Add a page to the document @@ -1244,9 +1252,12 @@ Refer to the following code example to extract the image metadata from a PDF ima {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Metadata/Extracting-XMP-metadata-from-PDF-image/.NET/Extracting-XMP-metadata-from-PDF-image/Program.cs" %} -//Load an existing PDF -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Xmp; +using Syncfusion.Pdf; + +//Load the PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the first page PdfPageBase pageBase = loadedDocument.Pages[0]; @@ -1262,6 +1273,10 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Xmp; +using Syncfusion.Pdf; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); //Load the first page @@ -1279,6 +1294,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Xmp +Imports Syncfusion.Pdf + 'Load an existing PDF Dim loadedDocument As New PdfLoadedDocument(fileName) 'Load the first page diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Named-Destination.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Named-Destination.md index b864b4559..71141373f 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Named-Destination.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Named-Destination.md @@ -28,6 +28,11 @@ The following code example shows how to add named destination in a new PDF docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Named%20Destination/Adding-named-destination-to-a-PDF-document/.NET/Adding-named-destination-to-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Add a page to the document. @@ -43,16 +48,19 @@ doc.NamedDestinationCollection.Add(destination); //Draw the text. page.Graphics.DrawString("Hello World!!", new PdfStandardFont(PdfFontFamily.Helvetica, 10), PdfBrushes.Black, new PointF(0, 500)); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -//Closes the document +//Save the document. +doc.Save("Output.pdf"); +//Close the document. doc.Close(true); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Add a page to the document. @@ -77,6 +85,11 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Interactive + 'Create a new PDF document. Dim doc As New PdfDocument() 'Add a page to the document. @@ -111,9 +124,13 @@ The following code example shows how to add named destination in an existing PDF {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Named%20Destination/Adding-named-destination-to-an-existing-PDF-document/.NET/Adding-named-destination-to-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the first page of the document. PdfPageBase page = loadedDocument.Pages[0]; //Create an instance for named destination. @@ -125,16 +142,20 @@ destination.Destination.Location = new PointF(0, 500); destination.Destination.Zoom = 4; loadedDocument.NamedDestinationCollection.Add(destination); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -//Closes the document. +//Save the document. +loadedDocument.Save("Output.pdf"); +//Close the document. loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the first page of the document. @@ -157,6 +178,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Interactive + 'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the first page of the document. @@ -189,9 +215,11 @@ You can remove the named destination using [Remove](https://help.syncfusion.com/ {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Named%20Destination/Remove-and-modify-the-named-destination-in-a-PDF/.NET/Remove-and-modify-the-named-destination-in-a-PDF/Program.cs" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("Barcode.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument lDoc = new PdfLoadedDocument(docStream); +PdfLoadedDocument lDoc = new PdfLoadedDocument("Input.pdf"); //Get the named destination collection. PdfNamedDestinationCollection destinationCollection = lDoc.NamedDestinationCollection; //Remove the named destination by title. @@ -200,9 +228,8 @@ destinationCollection.Remove("TOC"); PdfNamedDestination destination = destinationCollection[0]; destination.Title = "POC"; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -lDoc.Save(stream); +//Save the document. +lDoc.Save("Output.pdf"); //Close the document. lDoc.Close(true); @@ -210,6 +237,9 @@ lDoc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument lDoc = new PdfLoadedDocument("Sample.pdf"); //Get the named destination collection. @@ -230,6 +260,9 @@ lDoc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Interactive + 'Load the PDF document. Dim lDoc As New PdfLoadedDocument("Sample.pdf") 'Get the named destination collection. @@ -260,6 +293,11 @@ The following code example shows how to add named destination to the [Bookmarks] {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Named%20Destination/Adding-named-destination-to-the-bookmarks/.NET/Adding-named-destination-to-the-bookmarks/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Add a page to the document. @@ -278,10 +316,8 @@ PdfBookmark bookmark = doc.Bookmarks.Add("TOC"); //Assign the named destination to the bookmark. bookmark.NamedDestination = destination; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -stream.Position = 0; +//Save the document. +doc.Save("Sample.pdf"); //Close the document. doc.Close(true); @@ -289,6 +325,11 @@ doc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Add a page to the document. @@ -316,6 +357,11 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Interactive + 'Create a new PDF document. Dim doc As New PdfDocument() 'Add a page to the document. diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-PDF-Conformance.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-PDF-Conformance.md index ecf21596b..30a3ab9f7 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-PDF-Conformance.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-PDF-Conformance.md @@ -123,6 +123,9 @@ You can create a PDF/A-1b document by specifying the conformance level as ```Pdf {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-the-new-PDFA1B-document/.NET/Creating-the-new-PDFA1B-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/A-1b standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A1B); //Add a page to the document @@ -137,25 +140,16 @@ PdfFont font = new PdfTrueTypeFont(fontStream, 14); //Draw the text graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); -//If the position is not set to '0', then the PDF will be empty -stream.Position = 0; -//Close the document +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/A-1b standard. PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A1B); //Add a page. @@ -180,6 +174,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new document with PDF/A-1b standard. Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A1B) 'Add a page. @@ -214,6 +211,9 @@ You can create a PDF/A-2b document by specifying the conformance level as ```Pdf {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-the-new-PDFA2B-document/.NET/Creating-the-new-PDFA2B-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/A-2b standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A2B); //Add a page to the document @@ -228,25 +228,17 @@ PdfFont font = new PdfTrueTypeFont(fontStream, 14); //Draw the text graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); -//If the position is not set to '0', then the PDF will be empty -stream.Position = 0; -//Close the document +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/A-2b standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A2B); //Add a page @@ -271,6 +263,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new document with PDF/A-2b standard Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A2B) 'Add a page @@ -307,6 +302,10 @@ You can create a PDF/A-3b document by specifying the conformance level as Pdf_A3 {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-the-new-PDFA3B-document/.NET/Creating-the-new-PDFA3B-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new document with PDF/A-3b standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3B); //Add a page to the document @@ -330,25 +329,18 @@ PdfFont font = new PdfTrueTypeFont(fontStream, 14); //Draw the text graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); -//If the position is not set to '0', then the PDF will be empty -stream.Position = 0; -//Close the document +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new document with PDF/A-3b standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3B); //Add a page @@ -381,6 +373,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Interactive + 'Create a new document with PDF/A-3b standard Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A3B) 'Add a page @@ -425,6 +421,9 @@ You can create a PDF/A-1a document by specifying the conformance level as ```Pdf {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-the-new-PDFA1A-document/.NET/Creating-the-new-PDFA1A-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/A-1a standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A1A); //Add a page to the document @@ -438,25 +437,16 @@ PdfFont font = new PdfTrueTypeFont(fontStream, 14); //Draw the text graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); -//If the position is not set to '0', then the PDF will be empty -stream.Position = 0; -//Close the document +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/A-1a standard. PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A1A); //Add a page. @@ -480,6 +470,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new document with PDF/A-1a standard. Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A1A) 'Add a page. @@ -515,6 +508,9 @@ You can create a PDF/A-2a document by specifying the conformance level as ```Pdf {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-the-new-PDFA2A-document/.NET/Creating-the-new-PDFA2A-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/A-2a standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A2A); //Add a page to the document @@ -528,25 +524,17 @@ PdfFont font = new PdfTrueTypeFont(fontStream, 14); //Draw the text graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); -//If the position is not set to '0', then the PDF will be empty -stream.Position = 0; -//Close the document +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/A-2a standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A2A); //Add a page @@ -570,6 +558,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new document with PDF/A-2a standard Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A2A) 'Add a page @@ -605,6 +596,10 @@ You can create a PDF/A-3a document by specifying the conformance level as ``Pdf_ {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-the-new-PDFA3A-document/.NET/Creating-the-new-PDFA3A-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new document with PDF/A-3a standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3A); //Add a page to the document @@ -628,25 +623,18 @@ PdfFont font = new PdfTrueTypeFont(fontStream, 14); //Draw the text graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); -//If the position is not set to '0', then the PDF will be empty -stream.Position = 0; -//Close the document +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new document with PDF/A-3a standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3A); //Add a page @@ -680,6 +668,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Interactive + 'Create a new document with PDF/A-3a standard Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A3A) 'Add a page @@ -725,6 +717,9 @@ You can create a PDF/A-2u document by specifying the conformance level as ```Pdf {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-the-new-PDFA2U-document/.NET/Creating-the-new-PDFA2U-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/A-2u standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A2U); //Add a page to the document @@ -738,25 +733,16 @@ PdfFont font = new PdfTrueTypeFont(fontStream, 14); //Draw the text graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); -//If the position is not set to '0', then the PDF will be empty -stream.Position = 0; -//Close the document +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/A-2u standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A2U); //Add a page @@ -780,6 +766,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new document with PDF/A-2u standard Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A2U) 'Add a page @@ -815,6 +804,10 @@ You can create a PDF/A-3u document by specifying the conformance level as ``Pdf_ {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-the-new-PDFA3U-document/.NET/Creating-the-new-PDFA3U-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new document with PDF/A-3u standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3U); //Add a page to the document @@ -838,25 +831,18 @@ PdfFont font = new PdfTrueTypeFont(fontStream, 14); //Draw the text graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); -//If the position is not set to '0', then the PDF will be empty -stream.Position = 0; -//Close the document +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Create a new document with PDF/A-3u standard PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3U); //Add a page @@ -890,6 +876,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Interactive + 'Create a new document with PDF/A-3u standard Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A3U) 'Add a page @@ -935,6 +925,9 @@ Create a PDF/A-4 document by specifying the conformance level as ``Pdf_A4`` thro {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-the-new-PDFA4-document/.NET/Creating-the-new-PDFA4-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with the PDF/A-4 standard. PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A4); //Add a page to the document. @@ -948,25 +941,17 @@ PdfFont font = new PdfTrueTypeFont(fontStream, 14); //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//Create the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document into the memory stream. -document.Save(stream); -//If the position is not set to '0,' a PDF will be empty. -stream.Position = 0; -//Close the document. -document.Close(true); -//Define the content type for a PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Output.pdf"; -//Create the FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); +//Save and close the document. +document.Save("Output.pdf"); +document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with the PDF/A-4 standard. PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A4); //Add a page. @@ -990,6 +975,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new document with the PDF/A-4 standard. Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A4) 'Add a page. @@ -1025,6 +1013,9 @@ Create a PDF/A-4E document by specifying the conformance level as ``Pdf_A4E`` th {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-the-new-PDFA4E-document/.NET/Creating-the-new-PDFA4E-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with the PDF/A-4 standard. PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A4); //Creates a new page. @@ -1040,22 +1031,16 @@ activation.ShowToolbar = true; pdf3dAnnotation.Activation = activation; //Add the annotation to the page. page.Annotations.Add(pdf3dAnnotation); -//Save the document into the stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); stream.Position = 0; -//Close the document. -document.Close(true); -//Define the ContentType for a pdf file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "3DAnnotation.pdf"; -//Create the FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); - +//Save and close the document. +document.Save("Output.pdf"); +document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with the PDF/A-4E standard. PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A4E); //Create a new page. @@ -1079,6 +1064,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new document with the PDF/A-4 standard. Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A4E) 'Creates a new page. @@ -1115,6 +1103,9 @@ Create a PDF/A-4f document by specifying the conformance level as ``Pdf_A4F`` th {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Creating-a-new-PDFA4F-document/.NET/Creating-a-new-PDFA4F-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with the PDF/A-4F standard. PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A4F); //Add a page to the document. @@ -1140,18 +1131,17 @@ PdfFont font = new PdfTrueTypeFont(fontStream, 14); //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); -//Save the document into the memory stream. -MemoryStream stream = new MemoryStream(); -await document.SaveAsync(stream); -//Close the document. -document.Close(true); -//Save the stream as a PDF document file in the local machine. Refer to the PDF/UWP section for respective code samples. -Save(stream, "Output.pdf"); +//Save and close the document. +document.Save("Output.pdf"); +document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with the PDF/A-3b standard. PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A4F); //Add a page. @@ -1184,6 +1174,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new document with the PDF/A-3b standard. Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A4F) 'Add a page. @@ -1233,6 +1226,9 @@ You can create a PDF/X-1a document by specifying the conformance level as ```Pdf {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document with PDF/x standard. PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_X1A2001); //Add a page. @@ -1258,6 +1254,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new document with PDF/x standard. Dim document As New PdfDocument(PdfConformanceLevel.Pdf_X1A2001) 'Add a page. @@ -1307,32 +1306,32 @@ Refer to the following code sample to implement this conversion. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/Program.cs" %} -//Load an existing PDF document -FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using SkiaSharp; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Sample level font event handling loadedDocument.SubstituteFont += LoadedDocument_SubstituteFont ; //Convert the loaded document to PDF/A document loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B); -//Save the document -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Close the document -loadedDocument.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); +//Save and close the document. +loadedDocument.Save("Output.pdf"); +loadedDocument.Close(true) {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using SkiaSharp; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -1347,6 +1346,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports SkiaSharp + 'Load an existing PDF document. Dim document As New PdfLoadedDocument("Input.pdf") @@ -1429,9 +1433,15 @@ N> To convert an existing PDF to a PDF/A-compliant document in .NET Core, ensure {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Font_Subsetting_in_PDFA_conversion/.NET/Font_Subsetting_in_PDFA_conversion/Program.cs" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf; +using System.Reflection.Metadata; +using Syncfusion.Drawing; +using Syncfusion.Pdf.Graphics; +using SkiaSharp; + //Load an existing PDF document -FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Sample level font event handling loadedDocument.SubstituteFont += LoadedDocument_SubstituteFont; @@ -1447,17 +1457,21 @@ options.SubsetFonts = true; // Convert to PDF/A conformance loadedDocument.ConvertToPDFA(options); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Closes the document +//Save and close the document. +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf; +using System.Reflection.Metadata; +using System.Drawing; +using Syncfusion.Pdf.Graphics; +using SkiaSharp; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -1478,6 +1492,13 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf +Imports System.Reflection.Metadata +Imports System.Drawing +Imports Syncfusion.Pdf.Graphics +Imports SkiaSharp + ' Load an existing PDF document. Dim document As New PdfLoadedDocument("Input.pdf") @@ -1562,9 +1583,11 @@ You can find the conformance level of the existing PDF document using the [Confo {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Get-the-conformance-level-of-the-existing-PDF-document/.NET/Program.cs" %} -//Load an existing PDF document -FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the conformance level of the loaded document. PdfConformanceLevel conformance = loadedDocument.Conformance; @@ -1576,6 +1599,9 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -1589,6 +1615,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf + 'Load an existing PDF. Dim document As New PdfLoadedDocument("Input.pdf") @@ -1613,24 +1642,20 @@ The following code sample shows the delegate for handling PDF to PDF/A conversio {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Get-PDF-to-PDFA-conversion-progress/.NET/Get-PDF-to-PDFA-conversion-progress/Program.cs" %} - - -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Subscribe to the PdfAConversionProgress event to track the PDF to PDF/A conversion process loadedDocument.PdfAConversionProgress += new PdfLoadedDocument.PdfAConversionProgressEventHandler(pdfAConversion_TrackProgress); loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B); -//Save the document -FileStream outputStream = new FileStream(Path.GetFullPath(@"Output.pdf"), FileMode.Create, FileAccess.Write); -loadedDocument.Save(outputStream); - -//Close the document +//Save and close the document. +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); @@ -1645,6 +1670,9 @@ void pdfAConversion_TrackProgress(object sender, PdfAConversionProgressEventArgs {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load a PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf"); @@ -1668,6 +1696,9 @@ Console.WriteLine(String.Format("PDF to PDF/A conversion Process " + arguments. {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf + 'Load a PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("input.pdf") @@ -1699,30 +1730,25 @@ An existing PDF/A conformance document can be converted to a PDF document using {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Conformance/Convert-PDFA-to-PDF-document/.NET/Convert-PDFA-to-PDF-document/Program.cs" %} +using Syncfusion.Pdf.Parsing; + //Load a PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Remove PDF/A conformance. document.RemoveConformance(); //Save the document. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +document.Save("Output.pdf"); //Close the document. document.Close(true); -//Defining the content type for PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "output.pdf"; - -//Creates a FileContentResult object by using the file contents, content type, and file name. -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; + //Load an existing document. PdfLoadedDocument document = new PdfLoadedDocument("input.pdf"); @@ -1738,6 +1764,8 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing + 'Load an existing document. Dim document As PdfLoadedDocument = New PdfLoadedDocument("input.pdf") diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-PDF-Templates.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-PDF-Templates.md index d925cfe00..4fc50279b 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-PDF-Templates.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-PDF-Templates.md @@ -19,6 +19,10 @@ The below code snippet illustrates how to add contents to the [PdfTemplate](http {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Templates/Add-the-contents-to-template-and-render-into-PDF-page/.NET/Add-the-contents-to-template-and-render-into-PDF-page/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document. @@ -37,9 +41,8 @@ template.Graphics.DrawString("Hello World", font, brush, 5, 5); //Draw the template on the page graphics of the document. pdfPage.Graphics.DrawPdfTemplate(template, PointF.Empty); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); +//Save the document. +pdfDocument.Save("Output.pdf"); //Close the document. pdfDocument.Close(true); @@ -47,6 +50,10 @@ pdfDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document. @@ -74,6 +81,10 @@ pdfDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Create a new PDF document. Dim pdfDocument As New PdfDocument() 'Add a page to the PDF document. @@ -109,9 +120,12 @@ The below code snippet illustrates how to render the [PdfTemplate](https://help. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Templates/Render-the-template-in-an-existing-PDF-document/.NET/Render-the-template-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the page into Pdf document. PdfLoadedPage LoadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -128,9 +142,8 @@ template.Graphics.DrawString("Hello World", font, brush, 5, 5); //Draw the template on the page graphics of the document. LoadedPage.Graphics.DrawPdfTemplate(template, Syncfusion.Drawing.PointF.Empty); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Output.pdf"); //Close the document. loadedDocument.Close(true); @@ -138,8 +151,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the page into Pdf document. PdfLoadedPage LoadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -165,8 +182,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Load the existing PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Load the page into Pdf document. Dim LoadedPage As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage) @@ -204,9 +225,12 @@ The below code illustrates how to create the template from an existing page and {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Templates/Create-template-from-an-existing-PDF-document/.NET/Create-template-from-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the page. PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Create the template from the page. @@ -221,19 +245,21 @@ PdfGraphics graphics = page.Graphics; //Draw the template. graphics.DrawPdfTemplate(template, Syncfusion.Drawing.PointF.Empty, new Syncfusion.Drawing.SizeF(page.Size.Width / 2, page.Size.Height)); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the document. +loadedDocument.Save("Output.pdf"); //Close the document. -document.Close(true); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the page. PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Create the template from the page. @@ -258,8 +284,12 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Load the existing PDF document -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Load the page Dim loadedPage As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage) 'Create the template from the page @@ -296,6 +326,10 @@ The below code illustrates how to add the page template elements in a PDF docume {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Templates/Add-the-page-template-elements-in-a-PDF-document/.NET/Add-the-page-template-elements-in-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document. @@ -329,9 +363,8 @@ compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(470, 40)); //Add the footer template at the bottom. pdfDocument.Template.Bottom = footer; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); +//Save the document. +pdfDocument.Save("Output.pdf"); //Close the document. pdfDocument.Close(true); @@ -339,6 +372,10 @@ pdfDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document. @@ -379,6 +416,10 @@ pdfDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Create a new PDF document. Dim pdfDocument As New PdfDocument() 'Add a page to the PDF document. @@ -429,12 +470,15 @@ Multiple templates can be drawn over a PDF page, to create a document-overlay us {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Templates/Creating-the-document-overlays/.NET/Creating-the-document-overlays/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream1 = new FileStream(fileName1, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(docStream1); +PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument("Input1.pdf"); //Load the PDF document. -FileStream docStream2 = new FileStream(fileName2, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(docStream2); +PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument("Input2.pdf"); //Create the new document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -451,23 +495,25 @@ template = loadedPage.CreateTemplate(); //Draw the loaded template into new document. page.Graphics.DrawPdfTemplate(template, new PointF(10, 10), new SizeF(400, 500)); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); -//Set the position as '0'. -stream.Position = 0; +//Save the new document. +document.Save("Output.pdf"); //Closes the documents. -document.Close(true); loadedDocument1.Close(true); loadedDocument2.Close(true); +document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load the existing documents. -PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(fileName1); -PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(fileName2); +PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument("Input1.pdf"); +PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument("Input2.pdf"); //Create the new document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -495,9 +541,14 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing +Imports System.Drawing + 'Load the existing documents. -Dim loadedDocument1 As New PdfLoadedDocument(fileName1) -Dim loadedDocument2 As New PdfLoadedDocument(fileName2) +Dim loadedDocument1 As New PdfLoadedDocument("Input1.pdf") +Dim loadedDocument2 As New PdfLoadedDocument("Input2.pdf") 'Create the new document. Dim document As New PdfDocument() 'Add a page to the document. @@ -535,9 +586,12 @@ The following code sample shows how to add a [PdfPageTemplate](https://help.sync {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/PDF%20Templates/Add-a-template-from-an-existing-PDF-document/.NET/Add-a-template-from-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Loads an existing PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the first page of the document. PdfPageBase page = loadedDocument.Pages[0]; @@ -550,17 +604,19 @@ pageTemplate.IsVisible = true; //Adds the page template. loadedDocument.PdfPageTemplates.Add(pageTemplate); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document into stream. -loadedDocument.Save(stream); -//Close the document. +//Save the PDF document. +loadedDocument.Save("output.pdf"); +//Close the PDF document. loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Loads an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf"); //Get the first page of the document. @@ -584,6 +640,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Loads an existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("input.pdf") 'Get the first page of the documsent. diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Pages.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Pages.md index 2841de9bb..7f719a83a 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Pages.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Pages.md @@ -15,6 +15,9 @@ The following code sample explains you on how to add a [PdfPage](https://help.sy {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Add-a-new-page-to-the-PDF-document/.NET/Add-a-new-page-to-the-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page. @@ -29,17 +32,17 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); //Draw the text. graphics.DrawString("Hello world!", font, brush, new Syncfusion.Drawing.PointF(20, 20)); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -document.Save(stream); -//Close the document. +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page. @@ -62,6 +65,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document. Dim document As New PdfDocument() 'Add a page. @@ -94,23 +100,23 @@ You can insert an empty page at any location in the existing PDF document using {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Insert-pages-in-a-PDF-document/.NET/Insert-pages-in-a-PDF-document/Program.cs" %} +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Insert a new page in the beginning of the document. loadedDocument.Pages.Insert(0); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -loadedDocument.Save(stream); -//Close the document. +//Save and close the document. +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Insert a new page in the beginning of the document. @@ -123,6 +129,8 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Insert a new page in the beginning of the document. @@ -145,6 +153,9 @@ You can add margin to all the PDF pages of the PDF document using the [PageSetti {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Add-margin-to-the-PDF-pages/.NET/Add-margin-to-the-PDF-pages/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Set margin for all the pages. @@ -161,17 +172,17 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); //Draw the text. graphics.DrawString("Hello world!", font, brush, new Syncfusion.Drawing.PointF(20, 20)); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -document.Save(stream); -//Close the document. +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Set margin for all the pages @@ -196,6 +207,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document. Dim document As New PdfDocument() 'Set margin for all the pages. @@ -234,6 +248,9 @@ The following code snippet explains how to add more sections to a PDF document w {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Adding-sections-with-different-page-settings/.NET/Adding-sections-with-different-page-settings/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Create a solid brush and standard font @@ -293,17 +310,18 @@ graphics = page.Graphics; //Draw simple text on the page graphics.DrawString("Rotated by 270 degrees", font, brush, new PointF(20, 20)); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -document.Save(stream); - -//Close the document. +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); + {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Create a solid brush and standard font @@ -372,6 +390,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document Dim document As PdfDocument = New PdfDocument 'Create a solid brush and standard font @@ -451,6 +472,9 @@ For example, to use lowercase Roman numerals (i, ii, iii, ...), assign `PdfNumbe {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document. PdfDocument document = new PdfDocument(); //Add a section to the document. @@ -484,21 +508,17 @@ for (int i = 0; i < 3; i++) page.Graphics.DrawString("This is the main content of a page with a footer.", font, PdfBrushes.Black, new PointF(10, 10)); } -//Create file stream. -using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} - -//Close the document. +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new document. PdfDocument document = new PdfDocument(); //Add a section to the document. @@ -541,6 +561,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new document. Dim document As New PdfDocument() 'Add a section to the document. @@ -592,9 +615,10 @@ You can get page count from the existing PDF document as shown in the following {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Get-number-of-pages-from-PDF-document/.NET/Get-number-of-pages-from-PDF-document/Program.cs" %} +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page count. int pageCount = loadedDocument.Pages.Count; //Close the document. @@ -604,6 +628,8 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page count. @@ -615,6 +641,8 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the page count. @@ -637,10 +665,11 @@ Essential® PDF allows you to import a page or import a range of p {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Importing-pages-from-one-PDF-to-another-PDF/.NET/Importing-pages-from-one-PDF-to-another-PDF/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create a new PDF document. PdfDocument document = new PdfDocument(); int startIndex = 0; @@ -648,18 +677,17 @@ int endIndex = loadedDocument.Pages.Count - 1; //Import all the pages to the new PDF document. document.ImportPageRange(loadedDocument, startIndex, endIndex); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -document.Save(stream); -//Close the document instances. -document.Close(true); +//Save and close the document. +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create a new PDF document. @@ -679,6 +707,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Create a new PDF document. @@ -710,10 +741,11 @@ N> Performance will be effective only in the large PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Import-pages-from-PDF-without-bookmarks/.NET/Import-pages-from-PDF-without-bookmarks/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -//Load the PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create the new PDF document PdfDocument document = new PdfDocument(); int startIndex = 0; @@ -721,18 +753,17 @@ int endIndex = loadedDocument.Pages.Count - 1; //Import all the pages to the new PDF document document.ImportPageRange(loadedDocument, startIndex, endIndex, false); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -document.Save(stream); -//Close the document instances -document.Close(true); +//Save and close the document. +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -754,6 +785,9 @@ System.Diagnostics.Process.Start("Output.pdf"); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Create the new PDF document @@ -783,22 +817,25 @@ You can rearrange the pages in an existing PDF document using [ReArrange](https: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Rearrange-pages-in-an-existing-PDF-document/.NET/Rearrange-pages-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Rearrange the page by index -loadedDocument.Pages.ReArrange(new int[] { 1, 0 });//Creating the stream object -MemoryStream stream = new MemoryStream(); +loadedDocument.Pages.ReArrange(new int[] { 1, 0 }); -//Save the document as stream -loadedDocument.Save(stream); -//Close the document +//Save and close the document. +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Rearrange the page by index @@ -811,6 +848,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Rearrange the page by index @@ -834,10 +874,11 @@ You can alter the page label for the existing PDF document using [PdfPageLabel]( {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Changing-page-numbers-in-a-PDF-document/.NET/Changing-page-numbers-in-a-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -//Load the PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Create a page label PdfPageLabel pageLabel = new PdfPageLabel(); //Set the number style with upper case roman letters @@ -846,17 +887,16 @@ pageLabel.NumberStyle = PdfNumberStyle.UpperRoman; pageLabel.StartNumber = 1; loadedDocument.LoadedPageLabel = pageLabel; -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -loadedDocument.Save(stream); -//Close the document +//Save and close the document. +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create a page label @@ -876,6 +916,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Create a page label @@ -905,23 +948,24 @@ You can remove the pages from the existing PDF document using [RemoveAt](https:/ {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Remove-pages-from-the-existing-PDF-document/.NET/Remove-pages-from-the-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Remove the first page in the PDF document loadedDocument.Pages.RemoveAt(0); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -loadedDocument.Save(stream); -//Close the document. +//Save and close the document. +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Remove the first page in the PDF document @@ -935,6 +979,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Remove the first page in the PDF document @@ -958,6 +1005,10 @@ You can rotate a particular PDF page in the PDF document using [PdfPageRotateAng {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Rotating-a-PDF-page/.NET/Rotating-a-PDF-page/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a section. @@ -975,17 +1026,18 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); //Draws the text. graphics.DrawString("Rotated by 90 degree", font, brush, new Syncfusion.Drawing.PointF(20, 20)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -document.Save(stream); -//Close the document. +//Save and close the document. +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a section. @@ -1012,6 +1064,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document. Dim document As New PdfDocument() 'Add a section. @@ -1048,24 +1104,27 @@ You can also rotate a PDF page in the existing PDF document using [PdfPageRotate {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Rotate-an-existing-PDF-page/.NET/Rotate-an-existing-PDF-page/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the page PdfPageBase loadedPage = loadedDocument.Pages[0] as PdfPageBase; //Set the rotation for loaded page loadedPage.Rotation = PdfPageRotateAngle.RotateAngle90; -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -//Close the document +//Save and close the document. +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the page. @@ -1082,6 +1141,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Gets the page. @@ -1108,24 +1170,27 @@ You can find the empty pages from the PDF document using the [IsBlank](https://h {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Detect-empty-pages-from-PDF/.NET/Detect-empty-pages-from-PDF/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the page. PdfPageBase loadedPage = loadedDocument.Pages[0] as PdfPageBase; //get the page is blank or not. bool isEmpty = loadedPage.IsBlank; -//Save the document into a stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -//Close the document. +//Save and close the document. +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the page. @@ -1142,6 +1207,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("input.pdf") 'Gets the page. @@ -1170,28 +1238,30 @@ Essential® PDF allows to split the pages of an existing PDF docum //Due to platform limitations, Essential® PDF supports splitting a PDF file into individual pages only in Windows Forms, WPF, ASP.NET, and ASP.NET MVC platforms. However this can be achieved by using the following code snippet. +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); -for (int i=0;i® PDF provides support for extracting the files from {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Portfolio/Extracting-the-files-from-PDF-portfolio/.NET/Extracting-the-files-from-PDF-portfolio/Program.cs" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document -FileStream docStream = new FileStream("Sample.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Iterate the attachments foreach (PdfAttachment attachment in document.Attachments) @@ -125,23 +127,17 @@ foreach (PdfAttachment attachment in document.Attachments) s.Dispose(); } -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save and close the document. +document.Save("Sample.pdf"); document.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document PdfLoadedDocument document = new PdfLoadedDocument("Sample.pdf"); @@ -162,6 +158,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document Dim document As New PdfLoadedDocument("Sample.pdf") @@ -191,30 +190,24 @@ The following code example illustrates how to remove files from an existing PDF {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Portfolio/Remove-the-files-from-PDF-portfolio/.NET/Remove-the-files-from-PDF-portfolio/Program.cs" %} +using Syncfusion.Pdf.Parsing; + //Load the PDF document -FileStream docStream = new FileStream("Sample.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Remove the file from the Portfolio document.Attachments.RemoveAt(0); -//Save and close the document -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Close the document +//Save and close the document. +document.Save("Sample.pdf"); document.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Output.pdf"; -//Creates a FileContentResult object by using the file contents, content type, and file name -return File(stream, contentType, fileName); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; + //Load the PDF document PdfLoadedDocument document = new PdfLoadedDocument("Sample.pdf"); @@ -229,6 +222,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document Dim document As New PdfLoadedDocument("Sample.pdf") diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Redaction.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Redaction.md index 616c54d60..c9ccb547a 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Redaction.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Redaction.md @@ -24,9 +24,13 @@ The following code example demonstrates the redaction of PDF documents from the {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load the existing PDF document -FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the first page from the document PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; @@ -37,17 +41,19 @@ page.AddRedaction(redaction); //Redact the contents from the PDF document document.Redact(); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document -document.Save(stream); -//Close the document +//Save and close the PDF document +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load a PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get first page from the document @@ -66,6 +72,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Redaction + 'Load a PDF document Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get first page from the document @@ -96,9 +107,14 @@ The following code example explains how to add overlay text in the redacted area {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Display-text-on-the-redacted-area/.NET/Display-text-on-the-redacted-area/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load the existing PDF document -FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the first page from the document PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; @@ -113,17 +129,20 @@ page.AddRedaction(redaction); //Redact the contents from the PDF document document.Redact(); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document -document.Save(stream); -//Close the document +//Save and close the PDF document +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load a PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get first page from the document @@ -146,6 +165,12 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Redaction + 'Load a PDF document Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get first page from the document @@ -180,9 +205,14 @@ The following code example explains how to redact the information from a page by {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Draw-image-on-the-redacted-area-in-PDF-document/.NET/Draw-image-on-the-redacted-area-in-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load the existing PDF document -FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the first page from the document PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; @@ -196,17 +226,20 @@ page.AddRedaction(redaction); //Redact the contents from the PDF document document.Redact(); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document -document.Save(stream); -//Close the document +//Save and close the PDF document +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load a PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get first page from the document @@ -228,6 +261,12 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Redaction + 'Load a PDF document Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get first page from the document @@ -261,9 +300,14 @@ The following code example explains how to redact the information from a page by {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Draw-pattern-on-the-redacted-area-in-PDF-document/.NET/Draw-pattern-on-the-redacted-area-in-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load the existing PDF document -FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the first page from the document PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; @@ -299,17 +343,19 @@ page.AddRedaction(redaction); //Redact the contents from the PDF document document.Redact(); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the documents -document.Save(stream); -//Close the documents +//Save and close the PDF document +document.Save("Output.pdf"); document.Close(true); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load a PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get first page from the document @@ -354,6 +400,12 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Redaction + 'Load a PDF document Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get first page from the document @@ -410,9 +462,13 @@ The following code example explains how to redact the information from a page wi {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Fill-color-on-the-redacted-area-in-a-PDF/.NET/Fill-color-on-the-redacted-area-in-a-PDF/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load the existing PDF document -FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the first page from the document PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; @@ -425,17 +481,19 @@ page.AddRedaction(redaction); //Redact the contents from the PDF document document.Redact(); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document -document.Save(stream); -//Close the document +//Save and close the PDF document +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load a PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get first page from the document @@ -456,6 +514,12 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Redaction + 'Load a PDF document Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get first page from the document @@ -488,9 +552,13 @@ The following code snippet explains how to redact the information from a page wi {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Redaction-without-fill-color-and-appearance/.NET/Redaction-without-fill-color-and-appearance/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load the existing PDF document -FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the first page from the document PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; @@ -502,17 +570,19 @@ page.AddRedaction(redaction); //Redact the contents from the PDF document document.Redact(); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document -document.Save(stream); -//Close the document +//Save and close the PDF document +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load a PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get first page from the document @@ -531,6 +601,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Redaction + 'Load a PDF document Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get first page from the document @@ -561,6 +636,11 @@ The following code example demonstrates how to apply a appearance fill color to {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Redaction-fill-color-customization/.NET/Redaction-fill-color-customization/Program.cs" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf; +using Syncfusion.Drawing; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -593,16 +673,19 @@ annot.SetAppearance(true); //Add the annotation to the page page.Annotations.Add(annot); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); -//Close the document. +//Save and close the PDF document +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf; +using Syncfusion.Drawing; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -644,6 +727,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf +Imports System.Drawing + ' Create a new PDF document Dim document As PdfDocument = New PdfDocument() ' Create a new page @@ -696,9 +784,13 @@ The code snippet to illustrate the same is given below. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Get-the-redaction-progress-from-PDF-document/.NET/Get-the-redaction-progress-from-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load an existing PDF document -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the first page PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; @@ -708,11 +800,8 @@ PdfRedaction redaction = new PdfRedaction(new RectangleF(37, 94, 50, 10), System page.AddRedaction(redaction); loadedDocument.RedactionProgress += redaction_TrackProgress; -//Create the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -loadedDocument.Save(stream); -//Close the document +//Save and close the PDF document +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); //Event handler for Track redaction process @@ -725,6 +814,11 @@ void redaction_TrackProgress(object sender, RedactionProgressEventArgs arguments {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load a PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf"); //Load the first page @@ -751,6 +845,11 @@ MessageBox.Show(String.Format("Redaction Process " + arguments.Progress + " % co {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Redaction + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("input.pdf") 'Load the first page @@ -763,8 +862,7 @@ page.Redactions.Add(redaction) loadedDocument.RedactionProgress += redaction_TrackProgress 'Save the document -Dim stream As New MemoryStream() -loadedDocument.Save(stream) +loadedDocument.Save("Output.pdf") 'Close the document loadedDocument.Close(True) @@ -786,9 +884,13 @@ Using [PdfRedactionResult](https://help.syncfusion.com/cr/document-processing/Sy {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Get-the-result-of-redaction-with-other-information/.NET/Get-the-result-of-redaction-with-other-information/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load an existing PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the first page. PdfLoadedPage page = loadedDocument.Pages[0]; @@ -807,17 +909,19 @@ else Console.WriteLine("Content not redacted properly..."); } -//Create the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -loadedDocument.Save(stream); -//Close the document +//Save and close the PDF document +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load an existing PDF document PdfLoadedDocument lDoc = new PdfLoadedDocument("input.pdf"); //Load the first page @@ -847,6 +951,11 @@ lDoc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Redaction + 'Load an existing PDF Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("input.pdf") 'Load the first page @@ -868,8 +977,7 @@ End If Next 'Save the document -Dim stream As New MemoryStream() -loadedDocument.Save(stream) +loadedDocument.Save("Output.pdf") 'Close the document loadedDocument.Close(True) @@ -889,9 +997,13 @@ The code snippet to illustrate the same is given below. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Redact-text-content-alone-on-the-redated-area/.NET/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load an existing PDF document -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); PdfRedaction redaction = new PdfRedaction(new RectangleF(150, 150, 60, 24), Color.Transparent); //Only the text within the redaction bounds should be redacted. redaction.TextOnly = true; @@ -900,17 +1012,18 @@ foreach (PdfLoadedPage loadedPage in document.Pages) loadedPage.AddRedaction(redaction); } document.Redact(); -//Create the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into stream -loadedDocument.Save(stream); -//Close the document +//Save and close the PDF document +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Redaction; + //Load a PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf"); PdfRedaction redaction = new PdfRedaction(new RectangleF(150, 150, 60, 24), Color.Transparent); @@ -930,6 +1043,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Redaction + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("input.pdf") 'Create PDF redaction for the page @@ -940,8 +1058,7 @@ For Each loadedPage As PdfLoadedPage In document.Pages Next document.Redact() 'Save the document -Dim stream As New MemoryStream() -loadedDocument.Save(stream) +loadedDocument.Save("Output.pdf") 'Close the document loadedDocument.Close(True) @@ -962,11 +1079,13 @@ The following code snippet explains how to find text by regular expression patte {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Redaction/Find-text-by-regular-expression-pattern-and-redact-it-from-PDF-document/.NET/Find_text_by_regular_expression/Program.cs" %} - //Create stream from an existing PDF document. - FileStream docStream = new FileStream(Path.GetFullPath("Input.pdf"), FileMode.Open, FileAccess.Read); + using Syncfusion.Pdf.Parsing; + using Syncfusion.Pdf.Redaction; + using Syncfusion.Pdf; + using System.Text.RegularExpressions; //Load the existing PDF document. - PdfLoadedDocument document = new PdfLoadedDocument(docStream); + PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the first page from the document. PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; @@ -1001,17 +1120,19 @@ The following code snippet explains how to find text by regular expression patte //Redact the contents from the PDF document. document.Redact(); - //Creating the stream object - MemoryStream stream = new MemoryStream(); - //Save the document - document.Save(stream); - //Close the document + //Save and close the PDF document + document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} + using Syncfusion.Pdf.Parsing; + using Syncfusion.Pdf.Redaction; + using Syncfusion.Pdf; + using System.Text.RegularExpressions; + //Load a PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); @@ -1052,11 +1173,13 @@ The following code snippet explains how to find text by regular expression patte {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create stream from an existing PDF document. - Dim docStream As New FileStream(Path.GetFullPath("Input.pdf"), FileMode.Open, FileAccess.Read) + Imports Syncfusion.Pdf.Parsing + Imports Syncfusion.Pdf.Redaction + Imports Syncfusion.Pdf + Imports System.Text.RegularExpressions 'Load the existing PDF document. - Dim document As New PdfLoadedDocument(docStream) + Dim document As New PdfLoadedDocument("Input.pdf") 'Get the first page from the document. Dim page As PdfLoadedPage = TryCast(document.Pages(0), PdfLoadedPage) @@ -1087,10 +1210,8 @@ The following code snippet explains how to find text by regular expression patte 'Redact the contents from the PDF document. document.Redact() - 'Creating the stream object - Dim stream As New MemoryStream() 'Save the document - document.Save(stream) + document.Save("Output.pdf") 'Close the document document.Close(True)