diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Security.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Security.md index 6947d09c0..c4f7837f2 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Security.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Security.md @@ -26,6 +26,11 @@ User password: Prevents people from opening or viewing a PDF document. Once the {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Encrypt-PDF-with-RC4-using-user-password/.NET/Encrypt-PDF-with-RC4-using-user-password/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 page to the document. @@ -46,16 +51,19 @@ security.UserPassword = "password"; //Draw the text. graphics.DrawString("Encrypted with RC4 128bit", font, brush, new PointF(0, 40)); -//Save the document into stream. -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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -84,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 + 'Create a new PDF document. Dim document As New PdfDocument() 'Add a page to the document. @@ -124,6 +137,11 @@ Owner password: Sets PDF document restrictions, which can include printing, cont {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Encrypt-PDF-with-RC4-using-owner-password/.NET/Encrypt-PDF-with-RC4-using-owner-password/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 page to the document. @@ -147,16 +165,19 @@ security.UserPassword = "password"; //Draw the text. graphics.DrawString("This document is protected with owner password", font, brush, new PointF(0, 40)); -//Save the document into stream. -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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -188,6 +209,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 page to the document. @@ -229,6 +255,11 @@ You can encrypt PDF document by specifying the [Algorithm](https://help.syncfusi {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Encrypt-PDF-with-AES-using-user-password/.NET/Encrypt-PDF-with-AES-using-user-password/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 page to the document. @@ -249,16 +280,19 @@ security.UserPassword = "password"; //Draw the text. graphics.DrawString("Encrypted with AES 256bit", font, brush, new PointF(0, 40)); -//Save the document into stream. -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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -287,6 +321,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 page to the document. @@ -323,6 +362,11 @@ You can protect the PDF document from printing, editing, copying with the [Owner {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Encrypt-PDF-with-AES-using-owner-password/.NET/Encrypt-PDF-with-AES-using-owner-password/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 page to the document. @@ -346,16 +390,19 @@ security.UserPassword = "password"; //Draw the text. graphics.DrawString("This document is protected with owner password", font, brush, new PointF(0, 40)); -//Save the document into stream. -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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -387,6 +434,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 page to the document. @@ -432,6 +484,11 @@ Refer to the following code example for further details. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Secure_data%20_with%20_AES_GCM/.NET/Secure_data%20_with%20_AES_GCM/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(); @@ -461,17 +518,19 @@ security.Algorithm = PdfEncryptionAlgorithm.AESGCM; security.OwnerPassword = "ownerPassword"; security.UserPassword = "userPassword"; -//Save the document into stream. -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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Create a new PDF document. PdfDocument document = new PdfDocument(); @@ -510,6 +569,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 PdfDocument = New PdfDocument() @@ -570,6 +634,11 @@ You can encrypt all the PDF content by specifying the [EncryptionOptions](https: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Encrypt-all-contents-of-the-PDF-document/.NET/Encrypt-all-contents-of-the-PDF-document/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 page to the document. @@ -592,16 +661,19 @@ security.UserPassword = "password"; //Draw the text. graphics.DrawString("Encrypted with AES 256bit", font, brush, new PointF(0, 40)); -//Save the document into stream. -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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -632,6 +704,11 @@ document.Close(); {% 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 page to the document. @@ -676,6 +753,11 @@ N> Encrypt all contents except metadata is only supported in AES algorithms wit {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Encrypt-all-contents-except-metadata-of-the-PDF/.NET/Encrypt-all-contents-except-metadata-of-the-PDF/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 page to the document. @@ -698,16 +780,19 @@ security.UserPassword = "password"; //Draw the text. graphics.DrawString("Encrypted all contents except metadata with AES 256bit", font, brush, new PointF(0, 40)); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); -//Close the document. -document.Close(true); +//Save and close the document. +document.Save("Output.pdf"); +document.Close(); {% 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 page to the document. @@ -738,6 +823,11 @@ document.Close(); {% 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 page to the document. @@ -782,6 +872,11 @@ N> [UserPassword](https://help.syncfusion.com/cr/document-processing/Syncfusion. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Encrypt-only-attachment-in-the-PDF-document/.NET/Encrypt-only-attachment-in-the-PDF-document/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 page to the document. @@ -812,16 +907,19 @@ attachment.MimeType = "application/txt"; //Add the attachment to the document. document.Attachments.Add(attachment); -//Save the document into stream. -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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Security; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -860,6 +958,11 @@ document.Close(); {% 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 page to the document. @@ -908,61 +1011,64 @@ The following code example demonstrates how to decrypt a PDF document and restor {% tabs %} -{% highlight c# tabtitle="C# [Cross-platform]" %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Program.cs" %} -using (FileStream inputStream = new FileStream(@"Data/Input.pdf", FileMode.Open, FileAccess.Read)) -{ - // Load the encrypted PDF document from the input stream - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream, "syncfusion"); - - // Set the document permissions to default (removes any restrictions) - loadedDocument.Security.Permissions = PdfPermissionsFlags.Default; - - // Clear the owner and user passwords to decrypt the document - loadedDocument.Security.OwnerPassword = string.Empty; - loadedDocument.Security.UserPassword = string.Empty; - - using (FileStream outputStream = new FileStream(@"Output/Output.pdf", FileMode.Create, FileAccess.Write)) - { - // Save the decrypted PDF document to the output stream - loadedDocument.Save(outputStream); - } - // Close the loaded PDF document and release resources - loadedDocument.Close(true); -} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + + // Load the encrypted PDF document from the input stream + PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf", "syncfusion"); + + // Set the document permissions to default (removes any restrictions) + loadedDocument.Security.Permissions = PdfPermissionsFlags.Default; + + // Clear the owner and user passwords to decrypt the document + loadedDocument.Security.OwnerPassword = string.Empty; + loadedDocument.Security.UserPassword = string.Empty; + + //Save and close the document. + loadedDocument.Save("Output.pdf"); + loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} -using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) -{ - // Load the encrypted PDF document from the input stream - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream, "syncfusion"); +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; - // Set the document permissions to default (removes any restrictions) - loadedDocument.Security.Permissions = PdfPermissionsFlags.Default; + // Load the encrypted PDF document from the input stream + PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf", "syncfusion"); - // Clear the owner and user passwords to decrypt the document - loadedDocument.Security.OwnerPassword = string.Empty; - loadedDocument.Security.UserPassword = string.Empty; + // Set the document permissions to default (removes any restrictions) + loadedDocument.Security.Permissions = PdfPermissionsFlags.Default; - // Save the decrypted PDF document to the output stream - loadedDocument.Save("Output.pdf"); + // Clear the owner and user passwords to decrypt the document + loadedDocument.Security.OwnerPassword = string.Empty; + loadedDocument.Security.UserPassword = string.Empty; - // Close the loaded PDF document and release resources - loadedDocument.Close(true); -} + //Save and close the document. + loadedDocument.Save("Output.pdf"); + loadedDocument.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Open the encrypted PDF document using FileStream -Using inputStream As New FileStream(Path.GetFullPath("Data/Input.pdf"), FileMode.Open, FileAccess.Read) +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security ' Load the encrypted PDF document from the input stream with password - Dim loadedDocument As New PdfLoadedDocument(inputStream, "syncfusion") + Dim loadedDocument As New PdfLoadedDocument("Input.pdf", "syncfusion") ' Set the document permissions to default (removes any restrictions) loadedDocument.Security.Permissions = PdfPermissionsFlags.Default @@ -977,13 +1083,11 @@ Using inputStream As New FileStream(Path.GetFullPath("Data/Input.pdf"), FileMode ' Close the loaded PDF document and release resources loadedDocument.Close(True) -End Using - {% endhighlight %} {% endtabs %} -You can download a complete working sample from GitHub. +You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Security/Decrypting-encrypted-PDF-document/.NET). ## Opening an encrypt-only-attachment document @@ -1001,11 +1105,11 @@ The following code example explains how to load an encrypt-only-attachment docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Load-an-encrypt-only-attachment-document/.NET/Load-an-encrypt-only-attachment-document/Program.cs" %} -//Get the stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream, "password"); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf", "password"); //Accessing the attachments. foreach (PdfAttachment attachment in document.Attachments) @@ -1022,11 +1126,11 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} -//Get the stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream, "password"); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf", "password"); //Accessing the attachments. foreach (PdfAttachment attachment in document.Attachments) @@ -1043,11 +1147,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Get the stream from an existing PDF document. -Dim docStream As New FileStream(Path.GetFullPath("Data/Input.pdf"), FileMode.Open, FileAccess.Read) +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Interactive ' Load the PDF document. -Dim document As New PdfLoadedDocument(docStream, "password") +Dim document As New PdfLoadedDocument("Input.pdf", "password") ' Accessing the attachments. For Each attachment As PdfAttachment In document.Attachments @@ -1073,11 +1177,11 @@ The following code example illustrates how to provide the password when accessin {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Set-user-password-when-accessing-the-attachment/.NET/Set-user-password-when-accessing-the-attachment/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.Interactive; +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); document.OnPdfPassword += Document_OnPdfPassword; @@ -1104,11 +1208,11 @@ void Document_OnPdfPassword(object sender, OnPdfPasswordEventArgs args) {% highlight c# tabtitle="C# [Windows-specific]" %} -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); document.OnPdfPassword += Document_OnPdfPassword; @@ -1135,11 +1239,11 @@ void Document_OnPdfPassword(object sender, OnPdfPasswordEventArgs args) {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Get stream from an existing PDF document. -Dim docStream As New FileStream(Path.GetFullPath("Data/Input.pdf"), FileMode.Open, FileAccess.Read) +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Interactive ' Load the PDF document. -Dim document As New PdfLoadedDocument(docStream) +Dim document As New PdfLoadedDocument("Input.pdf") ' Add the event handler for PDF password. AddHandler document.OnPdfPassword, AddressOf Document_OnPdfPassword @@ -1175,9 +1279,11 @@ N> [UserPassword](https://help.syncfusion.com/cr/document-processing/Syncfusion. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Protect-attachments-in-existing-PDF-document/.NET/Protect-attachments-in-existing-PDF-document/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 document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //PDF document security. PdfSecurity security = document.Security; @@ -1189,9 +1295,8 @@ security.UserPassword = "password"; //Specifies encryption option. security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments; -//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); @@ -1199,6 +1304,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the PDF document. PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); @@ -1221,6 +1329,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Load the PDF document. Dim document As New PdfLoadedDocument("Input.pdf") @@ -1253,9 +1364,11 @@ You can protect an existing PDF document with both [UserPassword](https://help.s {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/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 document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //PDF document security. PdfSecurity security = document.Security; @@ -1266,16 +1379,17 @@ security.Algorithm = PdfEncryptionAlgorithm.AES; security.OwnerPassword = "ownerPassword256"; security.UserPassword = "userPassword256"; -//Save the document into stream. -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.Parsing; +using Syncfusion.Pdf.Security; + //Load the PDF document. PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); @@ -1297,6 +1411,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Load an existing document. Dim document As New PdfLoadedDocument("Input.pdf") @@ -1328,22 +1445,26 @@ You can change the [UserPassword](https://help.syncfusion.com/cr/document-proces {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Change-password-of-the-PDF-document/.NET/Change-password-of-the-PDF-document/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, "password"); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf", "password"); //Change the user password loadedDocument.Security.UserPassword = "NewPassword"; -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -//Close the document +//Save the password changed PDF document. +loadedDocument.Save("Output.pdf"); +//Close the document. loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the password protected PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf","password"); //Change the user password. @@ -1358,6 +1479,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Load the password protected PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf", "password") 'Change the user password @@ -1429,22 +1553,25 @@ You can change the permission of the PDF document using the [Permissions](https: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Change-the-permission-of-the-PDF-document/.NET/Change-the-permission-of-the-PDF-document/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, "syncfusion"); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf", "syncfusion"); //Change the permission loadedDocument.Security.Permissions = PdfPermissionsFlags.CopyContent | PdfPermissionsFlags.AssembleDocument; -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -//Close the PDF document +//Save and Close the PDF document +loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the password protected PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf", "syncfusion"); //Change the permission @@ -1458,6 +1585,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Load the password protected PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf", "syncfusion") 'Change the permission @@ -1481,22 +1611,25 @@ You can remove the [UserPassword](https://help.syncfusion.com/cr/document-proces {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Remove-password-from-user-password-PDF-document/.NET/Remove-password-from-user-password-PDF-document/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, "password"); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf", "password"); //Change the user password loadedDocument.Security.UserPassword = string.Empty; -//Save the document into stream -MemoryStream stream = new MemoryStream(); -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 Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Security; + //Load the password protected PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf","password"); //Change the user password @@ -1511,6 +1644,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Parsing +Imports Syncfusion.Pdf.Security + 'Load the password protected PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf", "password") 'Change the user password @@ -1535,11 +1671,13 @@ You can determine whether the existing PDF document is password protected or not {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Security/Determine-whether-the-PDF-is-protected-or-not/.NET/Determine-whether-the-PDF-is-protected-or-not/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + try { //Load the PDF document - FileStream docStream = new FileStream("Output.pdf", FileMode.Open, FileAccess.Read); - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); + PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); } catch (PdfDocumentException exception) { @@ -1553,6 +1691,9 @@ catch (PdfDocumentException exception) {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + try { //Load the password protected PDF document without user password @@ -1570,6 +1711,9 @@ catch (PdfDocumentException exception) {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + Try 'Load the password protected PDF document without user password Dim loadedDocument As New PdfLoadedDocument("Output.pdf") diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Shapes.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Shapes.md index 58980f3ae..eb9d8891e 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Shapes.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Shapes.md @@ -31,6 +31,10 @@ You can draw a polygon in PDF document by using the [DrawPolygon](https://help.s {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-polygon-in-new-PDF-document/.NET/Draw-polygon-in-new-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 page to the document @@ -50,9 +54,8 @@ PointF[] points = { p1, p2, p3, p4, p5 }; //Draw the polygon on PDF document page.Graphics.DrawPolygon(pen, brush, points); -//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); @@ -60,6 +63,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 @@ -87,6 +94,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 PdfDocument = New PdfDocument 'Add a page to the document @@ -122,9 +133,12 @@ The following code snippet explains how to draw a polygon in an existing PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-polygon-in-an-existing-PDF-document/.NET/Draw-a-polygon-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Load the PDF document as stream -FileStream inputStream = new FileStream("Input.pdf", FileMode.Open); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Initialize PdfPen to draw the polygon @@ -141,9 +155,8 @@ PointF[] points = { p1, p2, p3, p4, p5 }; //Draw the polygon on PDF document loadedPage.Graphics.DrawPolygon(pen, brush, points); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the PDF document +loadedDocument.Save("Output.pdf"); //Close the instance of PdfLoadedDocument loadedDocument.Close(true); @@ -151,6 +164,10 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage @@ -178,6 +195,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the page into PdfLoadedPage @@ -215,6 +236,10 @@ You can draw a line in PDF document by using the [DrawLine](https://help.syncfus {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-line-in-new-PDF-document/.NET/Draw-a-line-in-new-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 page to the document @@ -228,9 +253,8 @@ PointF point2 = new PointF(10, 100); //Draw the line on PDF document page.Graphics.DrawLine(pen, point1, point2); -//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); @@ -238,6 +262,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 @@ -259,6 +287,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 PdfDocument = New PdfDocument 'Add a page to the document @@ -288,12 +320,15 @@ The following code snippet explains how to draw a line in an existing PDF docume {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-line-in-an-existing-PDF-document/.NET/Draw-a-line-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document as stream -FileStream inputStream = new FileStream("Input.pdf", FileMode.Open); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load an existing PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - //Initialize pen to draw the line PdfPen pen = new PdfPen(PdfBrushes.Black, 5f); //Create the line points @@ -302,9 +337,8 @@ PointF point2 = new PointF(10, 100); //Draw the line on PDF document loadedPage.Graphics.DrawLine(pen, point1, point2); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the PDF document +loadedDocument.Save("Output.pdf"); //Close the instance of PdfLoadedDocument loadedDocument.Close(true); @@ -312,6 +346,11 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage @@ -333,6 +372,11 @@ 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 + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the page into PdfLoadedPage @@ -365,6 +409,10 @@ You can draw a curve in PDF document by using the [Draw](https://help.syncfusion {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-curve-in-new-PDF-document/.NET/Draw-a-curve-in-new-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 page to the document @@ -377,9 +425,8 @@ PdfBezierCurve bezier = new PdfBezierCurve(new PointF(0, 0), new PointF(100, 50) //Draw the bezier curve on PDF document bezier.Draw(graphics, new PointF(10, 10)); -//Save the PDF document to MemoryStream -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the PDF document +document.Save("Output.pdf"); //Close the instance of PdfDocument document.Close(true); @@ -387,6 +434,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(); //Add a page to the document @@ -408,6 +459,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 PdfDocument = New PdfDocument 'Add a page to the document @@ -437,22 +492,25 @@ The following code snippet explains how to draw a curve in an existing PDF docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-curve-in-an-existing-PDF-document/.NET/Draw-a-curve-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document as stream -FileStream inputStream = new FileStream("Input.pdf", FileMode.Open); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load an existing PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Get the graphics of PdfLoadedPage PdfGraphics graphics = loadedPage.Graphics; //Create new instance of PdfBezierCurve -PdfBezierCurve bezier = new PdfBezierCurve(new PointF(0, 0), new PointF(100, 50), new PointF(50, 50), new PointF(100, 100)); +PdfBezierCurve bezier = new PdfBezierCurve(new PointF(0, 0), new PointF(100, 50), new PointF(50, 50), new PointF(100, 100)); //Draw the bezier curve on PDF document bezier.Draw(graphics, new PointF(10, 10)); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the PDF document +loadedDocument.Save("Output.pdf"); //Close the instance of PdfLoadedDocument loadedDocument.Close(true); @@ -460,6 +518,11 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage @@ -481,6 +544,11 @@ 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 + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the page into PdfLoadedPage @@ -512,6 +580,10 @@ You can draw a path in PDF document by using the [DrawPath](https://help.syncfus {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-path-in-a-new-PDF-document/.NET/Draw-path-in-a-new-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 page to the document @@ -527,9 +599,8 @@ path.AddLine(new PointF(100, 200), new PointF(10, 100)); //Draw the PDF path on page page.Graphics.DrawPath(PdfPens.Black, path); -//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); @@ -537,6 +608,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 @@ -561,6 +636,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 PdfDocument = New PdfDocument 'Add a page to the document @@ -593,9 +672,13 @@ The following code snippet explains how to draw path in an existing PDF document {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-path-in-an-existing-PDF-document/.NET/Draw-path-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document as stream -FileStream inputStream = new FileStream("Input.pdf", FileMode.Open); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load an existing PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -609,9 +692,8 @@ path.AddLine(new PointF(100, 200), new PointF(10, 100)); //Draw the PDF path on page loadedPage.Graphics.DrawPath(PdfPens.Black, path); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the PDF document +loadedDocument.Save("Output.pdf"); //Close the instance of PdfLoadedDocument loadedDocument.Close(true); @@ -619,6 +701,11 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage @@ -643,6 +730,11 @@ 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 + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the page into PdfLoadedPage @@ -681,6 +773,10 @@ You can draw a rectangle in PDF document by using the [DrawRectangle](https://he {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-rectangle-in-a-new-PDF-document/.NET/Draw-a-rectangle-in-a-new-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 page to the document @@ -693,9 +789,8 @@ RectangleF bounds = new RectangleF(10, 10, 100, 50); //Draw the rectangle on PDF document page.Graphics.DrawRectangle(brush, bounds); -//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); @@ -703,6 +798,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 @@ -724,6 +823,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 PdfDocument = New PdfDocument 'Add a page to the document @@ -753,12 +856,16 @@ The following code snippet explains how to draw a rectangle in an existing PDF d {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-rectangle-in-an-existing-PDF-document/.NET/Draw-a-rectangle-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document as stream -FileStream inputStream = new FileStream("Input.pdf", FileMode.Open); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +//Load an existing PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + //Initialize PdfSolidBrush for drawing the rectangle PdfSolidBrush brush = new PdfSolidBrush(Color.Green); //Set the bounds for rectangle @@ -766,9 +873,8 @@ RectangleF bounds = new RectangleF(10, 10, 100, 50); //Draw the rectangle on PDF document loadedPage.Graphics.DrawRectangle(brush, bounds); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the PDF document +loadedDocument.Save("Output.pdf"); //Close the instance of PdfLoadedDocument loadedDocument.Close(true); @@ -776,6 +882,11 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage @@ -797,6 +908,11 @@ 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 + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the page into PdfLoadedPage @@ -828,6 +944,10 @@ You can draw a pie in PDF document by using the [DrawPie](https://help.syncfusio {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-pie-in-new-PDF-document/.NET/Draw-a-pie-in-new-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 page to the document @@ -842,9 +962,8 @@ RectangleF rectangle = new RectangleF(10, 50, 200, 200); //Draw the pie on PDF document page.Graphics.DrawPie(pen, PdfBrushes.Green, rectangle, 180, 60); -//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); @@ -852,6 +971,10 @@ document.Close(true); {% highlight c# tabtitle="C#" %} +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 @@ -875,6 +998,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a new PDF document Dim document As PdfDocument = New PdfDocument 'Add a page to the document @@ -906,9 +1033,13 @@ The following code snippet explains how to draw a pie in an existing PDF documen {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-pie-in-an-existing-PDF-document/.NET/Draw-a-pie-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 as stream -FileStream inputStream = new FileStream("Input.pdf", FileMode.Open); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -921,16 +1052,20 @@ RectangleF rectangle = new RectangleF(10, 50, 200, 200); //Draw the pie on PDF document loadedPage.Graphics.DrawPie(pen, PdfBrushes.Green, rectangle, 180, 60); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -//Close the instance of PdfLoadedDocument -loadedDocument.Close(true); +//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.Parsing; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage @@ -954,6 +1089,11 @@ 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 + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the page into PdfLoadedPage @@ -987,6 +1127,10 @@ You can draw an arc in PDF document by using the [DrawArc](https://help.syncfusi {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-an-arc-in-new-PDF-document/.NET/Draw-an-arc-in-new-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 page to the document @@ -1000,9 +1144,8 @@ RectangleF bounds = new RectangleF(20, 40, 200, 200); //Draw the arc on PDF document page.Graphics.DrawArc(pen, bounds, 270, 90); -//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); @@ -1010,6 +1153,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 @@ -1033,6 +1180,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 PdfDocument = New PdfDocument 'Add a page to the document @@ -1064,9 +1215,13 @@ The following code snippet explains how to draw an arc in an existing PDF docume {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-an-arc-in-an-existing-PDF-document/.NET/Draw-an-arc-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document as stream -FileStream inputStream = new FileStream("Input.pdf", FileMode.Open); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load an existing PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -1079,9 +1234,8 @@ RectangleF bounds = new RectangleF(20, 40, 200, 200); //Draw the arc on PDF document loadedPage.Graphics.DrawArc(pen, bounds, 270, 90); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the PDF document +loadedDocument.Save("Output.pdf"); //Close the instance of PdfLoadedDocument loadedDocument.Close(true); @@ -1089,6 +1243,11 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage @@ -1112,6 +1271,11 @@ 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 + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the page into PdfLoadedPage @@ -1145,6 +1309,10 @@ You can draw a bezier in PDF document by using the [DrawBezier](https://help.syn {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-bazier-in-new-PDF-document/.NET/Draw-a-bazier-in-new-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 page to the document @@ -1155,9 +1323,8 @@ PdfPen pen = new PdfPen(PdfBrushes.Brown, 1f); //Draw the bezier on PDF document page.Graphics.DrawBezier(pen, new PointF(10, 10), new PointF(10, 50), new PointF(50, 80), new PointF(80, 10)); -//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); @@ -1165,6 +1332,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 @@ -1184,6 +1355,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 PdfDocument = New PdfDocument 'Add a page to the document @@ -1211,9 +1386,13 @@ The following code snippet explains how to draw a bezier in an existing PDF docu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-a-bazier-in-an-existing-PDF-document/.NET/Draw-a-bazier-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document as stream -FileStream inputStream = new FileStream("Input.pdf", FileMode.Open); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -1222,9 +1401,8 @@ PdfPen pen = new PdfPen(PdfBrushes.Brown, 1f); //Draw the bezier on PDF document loadedPage.Graphics.DrawBezier(pen, new PointF(10, 10), new PointF(10, 50), new PointF(50, 80), new PointF(80, 10)); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the PDF document +loadedDocument.Save("Output.pdf"); //Close the instance of PdfLoadedDocument loadedDocument.Close(true); @@ -1232,6 +1410,11 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage @@ -1251,6 +1434,11 @@ 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 + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the page into PdfLoadedPage @@ -1280,6 +1468,10 @@ You can draw an ellipse in PDF document by using the [DrawEllipse](https://help. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-an-ellipse-in-new-PDF-document/.NET/Draw-an-ellipse-in-new-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 page to the document @@ -1290,9 +1482,8 @@ PdfSolidBrush brush = new PdfSolidBrush(Color.Red); //Draw ellipse on the page page.Graphics.DrawEllipse(brush, new RectangleF(10, 10, 200, 100)); -//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); @@ -1300,6 +1491,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 @@ -1319,6 +1514,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 PdfDocument = New PdfDocument 'Add a page to the document @@ -1346,9 +1545,13 @@ The following code snippet explains how to draw an ellipse in an existing PDF do {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-an-ellipse-in-an-existing-PDF-document/.NET/Draw-an-ellipse-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document as stream -FileStream inputStream = new FileStream("Input.pdf", FileMode.Open); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +//Load an existing PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -1357,9 +1560,8 @@ PdfSolidBrush brush = new PdfSolidBrush(Color.Red); //Draw ellipse on the page loadedPage.Graphics.DrawEllipse(brush, new RectangleF(10, 10, 200, 100)); -//Saving the PDF to the MemoryStream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the PDF document +loadedDocument.Save("Output.pdf"); //Close the instance of PdfLoadedDocument loadedDocument.Close(true); @@ -1367,6 +1569,11 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the page into PdfLoadedPage @@ -1386,6 +1593,11 @@ 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 + 'Load an existing PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the page into PdfLoadedPage @@ -1415,6 +1627,10 @@ You can also allow large shapes to paginate across pages by assigning ```Paginat {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Draw-large-shapes-across-multiple-pages/.NET/Draw-large-shapes-across-multiple-pages/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create Document PdfDocument doc = new PdfDocument(); //Add new page @@ -1432,16 +1648,18 @@ ellipse.Brush = PdfBrushes.Brown; //Draw ellipse. ellipse.Draw(page, 20, 20, format); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -//Closes the document +//Save and close the PDF document +doc.Save("Shapes.pdf"); doc.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create Document PdfDocument doc = new PdfDocument(); //Add new page @@ -1467,6 +1685,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create Document Dim doc As New PdfDocument() 'Add new page @@ -1504,6 +1726,10 @@ The following code example demonstrates applying a dash pattern to a line shape. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Shapes/Dash-pattern-in-shapes/.NET/Dash-pattern-in-shapes/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 @@ -1523,12 +1749,9 @@ dashPen.DashPattern = dashPattern; // Draw a line with the custom dash pattern graphics.DrawLine(dashPen, new Syncfusion.Drawing.PointF(10, 10), new PointF(300, 10)); -//Create file stream. -using (FileStream outputFileStream = new FileStream("Output/Output.pdf", FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + +//Save the PDF document to file stream. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1536,6 +1759,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 @@ -1565,6 +1792,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 page to the document diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Tagged-PDF.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Tagged-PDF.md index c85b41ebc..8959a48b1 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Tagged-PDF.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Tagged-PDF.md @@ -28,6 +28,10 @@ The following code sample explains you how to add tag for the text element in PD {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Add-tag-for-the-text-element-in-PDF-document/.NET/Add-tag-for-the-text-element-in-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creates new PDF document PdfDocument doc = new PdfDocument(); //Set the document title @@ -53,23 +57,18 @@ element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); //Draws text PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width, 200)); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document and dispose it +doc.Save("Output.pdf"); doc.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; + //Creates new PDF document PdfDocument doc = new PdfDocument(); //Set the document title @@ -103,6 +102,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Creates new PDF document Dim doc As PdfDocument = New PdfDocument() 'Set the document title @@ -148,6 +151,10 @@ The following code explains how to add tag for image element in PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Add-tag-for-image-element-in-PDF-document/.NET/Add-tag-for-image-element-in-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creates new PDF document PdfDocument doc = new PdfDocument(); //Set the document title @@ -172,23 +179,18 @@ bitmap.PdfTag = imageElement; //Draw image bitmap.Draw(page.Graphics, new PointF(50, 20)); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document and dispose it +doc.Save("Image.pdf"); doc.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Image.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; + //Creates new PDF document PdfDocument doc = new PdfDocument(); //Set the document title @@ -218,6 +220,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Creates new PDF document Dim doc As PdfDocument = New PdfDocument() 'Set the document title @@ -259,6 +265,10 @@ The following code explains how to add tag for shape element in the PDF document {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Adding-tag-to-shape-element-in-the-PDF-document/.NET/Adding-tag-to-shape-element-in-the-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creates new PDF document PdfDocument doc = new PdfDocument(); //Set the document title @@ -284,23 +294,18 @@ line.PdfTag = element; //Draws the line line.Draw(page.Graphics); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document and dispose it +doc.Save("Output.pdf"); 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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creates new PDF document PdfDocument doc = new PdfDocument(); //Set the document title @@ -331,6 +336,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Creates new PDF document Dim doc As PdfDocument = New PdfDocument() 'Set the document title @@ -373,6 +382,11 @@ The following code explains how to add tag for the form fields in PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Adding-tag-to-form-fields-in-the-PDF-document/.NET/Adding-tag-to-form-fields-in-the-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Creates new PDF document PdfDocument doc = new PdfDocument(); //Set document information @@ -395,23 +409,19 @@ textBoxField.ToolTip = "TextBox field"; //Add the form field to the document. doc.Form.Fields.Add(textBoxField); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document and dispose it +doc.Save("Output.pdf"); 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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; + //Creates new PDF document PdfDocument doc = new PdfDocument(); //Set the document information @@ -442,6 +452,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 + 'Creates new PDF document Dim doc As PdfDocument = New PdfDocument() 'Set the document information @@ -484,6 +499,10 @@ The following code explains how to add tag for the annotations in PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Adding-tag-to-annotation-in-the-PDF-document/.NET/Adding-tag-to-annotation-in-the-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Creates new PDF document PdfDocument doc = new PdfDocument(); //Set the document title @@ -508,23 +527,18 @@ popupAnnotation.Icon = PdfPopupIcon.NewParagraph; //Adds this annotation to a new page page.Annotations.Add(popupAnnotation); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document and dispose it +doc.Save("Output.pdf"); doc.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "PopupAnnotation.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 new PDF document PdfDocument doc = new PdfDocument(); //Set the document title @@ -558,6 +572,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + 'Creates new PDF document Dim doc As PdfDocument = New PdfDocument() 'Set the document title @@ -603,6 +621,11 @@ The following code example shows how to add tag for hyperlink in PDF document {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Add-tag-for-hyperlink-in-the-PDF-document/.NET/Add-tag-for-hyperlink-in-the-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(); document.DocumentInformation.Title = "Link"; @@ -630,24 +653,21 @@ textLink.Brush = PdfBrushes.Blue; //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); -stream.Position = 0; -//Closes the document +//Save the document +document.Save("Output.pdf"); +//Close the document document.Close(true); fontStream.Dispose(); -//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(); document.DocumentInformation.Title = "Link"; @@ -685,6 +705,11 @@ fontStream.Dispose(); {% 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 document As PdfDocument = New PdfDocument() document.DocumentInformation.Title = "Link" @@ -733,6 +758,10 @@ The following code sample explains how to add tag support for the template eleme {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Add-tags-to-template-in-PDF-document/.NET/Add-tags-to-template-in-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creates a new PDF document PdfDocument pdfDocument = new PdfDocument(); pdfDocument.DocumentInformation.Title = "TemplateDocument"; @@ -760,23 +789,18 @@ template.Graphics.DrawRectangle(brush, new RectangleF(0, 30, 150, 90)); //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); -stream.Position = 0; -//Closes the document +//Save the document and dispose it +pdfDocument.Save("Output.pdf"); pdfDocument.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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creates a new PDF document PdfDocument pdfDocument = new PdfDocument(); pdfDocument.DocumentInformation.Title = "TemplateDocument"; @@ -810,6 +834,10 @@ pdfDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Creates a new PDF document Dim pdfDocument As PdfDocument = New PdfDocument() pdfDocument.DocumentInformation.Title = "TemplateDocument" @@ -857,6 +885,11 @@ The following code snippet illustrates how to add tag for table element. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Add-tags-to-table-in-the-PDF-document/.NET/Add-tags-to-table-in-the-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Grid; + //Creates a new PDF document PdfDocument pdfDocument = new PdfDocument(); pdfDocument.DocumentInformation.Title = "Table"; @@ -906,23 +939,19 @@ pdfGridRow.Cells[2].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell); //Draw the PdfGrid pdfGrid.Draw(pdfPage, PointF.Empty); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document and dispose it +pdfDocument.Save("Output.pdf"); pdfDocument.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.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Grid; + //Creates a new PDF document PdfDocument pdfDocument = new PdfDocument(); pdfDocument.DocumentInformation.Title = "Table"; @@ -980,6 +1009,11 @@ pdfDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Grid + 'Creates a new PDF document Dim pdfDocument As PdfDocument = New PdfDocument() pdfDocument.DocumentInformation.Title = "Table" @@ -1049,6 +1083,10 @@ The following code example illustrates how to add tag support for list element. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Add-the-tag-to-list-element-in-PDF-document/.NET/Add-the-tag-to-list-element-in-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Sets document title @@ -1092,23 +1130,18 @@ for (int i = 0; i < products.Length; i++) //Draw the list pdfList.Draw(page, new RectangleF(0, 20, size.Width, size.Height)); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Closes 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 System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Sets document title @@ -1158,6 +1191,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 PdfDocument = New PdfDocument() 'Sets document title @@ -1218,6 +1255,10 @@ You can apply tags to nested list elements using the [PdfStructureElement](https {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + // Create a new PDF document PdfDocument document = new PdfDocument(); @@ -1285,12 +1326,8 @@ mainList.Items[1].SubList = subList; // Draw the main list, which includes the nested sublist, on the PDF mainList.Draw(page, new RectangleF(0, 30, size.Width, size.Height)); -//Create file stream. -using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} +//Save the PDF document +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1298,6 +1335,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(); @@ -1374,6 +1415,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() @@ -1465,10 +1510,14 @@ The following code sample demonstrates how to create a well-tagged PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Well-Tagged-PDF/.NET/Well-Tagged-PDF/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A4); -//Set Pdf File version 2.0 +//Set PDF File version 2.0 document.FileStructure.Version = PdfVersion.Version2_0; //Set true to auto tag all elements in document @@ -1499,21 +1548,23 @@ textElement.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); // Draw text element with tag textElement.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width, 200)); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; +//Save the document +document.Save("Output.pdf"); //Closes the document -document.Close(true); +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(PdfConformanceLevel.Pdf_A4); -//Set Pdf File version 2.0 +//Set PDF File version 2.0 document.FileStructure.Version = PdfVersion.Version2_0; //Set true to auto tag all elements in document @@ -1553,10 +1604,14 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Creates new PDF document Dim doc As PdfDocument = New PdfDocument(PdfConformanceLevel.Pdf_A4) -'Set Pdf File version 2.0 +'Set PDF File version 2.0 doc.FileStructure.Version = PdfVersion.Version2_0 'Set true to auto tag all elements in document @@ -1608,10 +1663,14 @@ The following code sample demonstrates how to create a PDF with Universal Access {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/PDF-for-Universal-Accessibility/.NET/PDF-for-Universal-Accessibility/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument document = new PdfDocument(); -//Set Pdf File version 2.0 +//Set PDF File version 2.0 document.FileStructure.Version = PdfVersion.Version2_0; //Set true to auto tag all elements in document @@ -1640,21 +1699,23 @@ textElement.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); // Draw text element with tag textElement.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width, 200)); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; +//Save the document +document.Save("Output.pdf"); //Closes the document -document.Close(true); +document.Close(true); {% endhighlight %} {% 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(); -//Set Pdf File version 2.0 +//Set PDF File version 2.0 document.FileStructure.Version = PdfVersion.Version2_0; //Set true to auto tag all elements in document @@ -1692,10 +1753,14 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Creates new PDF document Dim doc As PdfDocument = New PdfDocument() -'Set Pdf File version 2.0 +'Set PDF File version 2.0 doc.FileStructure.Version = PdfVersion.Version2_0 'Set true to auto tag all elements in document @@ -1745,6 +1810,10 @@ The following code explains how to add tag for header and footers in the PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Add-tags-for-header-and-footer-in-the-PDF-document/.NET/Add-tags-for-header-and-footer-in-the-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creates new PDF document PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document @@ -1786,23 +1855,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); -stream.Position = 0; -//Closes the document +//Save the document and dispose it +pdfDocument.Save("HeaderFooter.pdf"); pdfDocument.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "HeaderFooter.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; + //Creates new PDF document PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document @@ -1850,6 +1914,10 @@ pdfDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Creates new PDF document Dim pdfDocument As PdfDocument = New PdfDocument() 'Add a page to the PDF document @@ -1909,6 +1977,10 @@ The following code example illustrates how to order the tagged elements in a PDF {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Order-the-tagged-elements-in-a-PDF-document/.NET/Order-the-tagged-elements-in-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Sets document title @@ -1951,23 +2023,18 @@ element2.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); element2.PdfTag = paraStruct2; element2.Draw(page.Graphics, new PointF(0, 100)); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document and dispose it +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; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Sets document title @@ -2019,6 +2086,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 PdfDocument = New PdfDocument() 'Sets document title @@ -2083,6 +2154,10 @@ N> Enabling the auto-tag feature will never add alternate texts/descriptions for {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Auto-tag-the-elements-in-a-PDF-document/.NET/Auto-tag-the-elements-in-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creates new PDF document PdfDocument document = new PdfDocument(); //Set true to auto tag all elements in document @@ -2106,23 +2181,18 @@ PdfTextElement element2 = new PdfTextElement("This is paragraph THREE.", new Pdf element2.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); element2.Draw(page.Graphics, new PointF(0, 100)); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document and dispose it +document.Save("Output.pdf"); document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "AutoTag.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; + //Creates new PDF document PdfDocument document = new PdfDocument(); //Set true to auto tag all elements in document @@ -2154,6 +2224,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Creates new PDF document Dim document As PdfDocument = New PdfDocument() 'Set true to auto tag all elements in document @@ -2212,10 +2286,12 @@ The following code sample shows how to preserve document structured tags in the {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Converting-word-document-to-Tagged-PDF/.NET/Converting-word-document-to-Tagged-PDF/Program.cs" %} -//Open the file as Stream -FileStream docStream = new FileStream(@"D:\Template.docx", FileMode.Open, FileAccess.Read); +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using Syncfusion.Pdf; + //Loads file stream into Word document -WordDocument wordDocument = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic); +WordDocument wordDocument = new WordDocument("Template.docx", Syncfusion.DocIO.FormatType.Automatic); //Instantiation of DocIORenderer for Word to PDF conversion DocIORenderer render = new DocIORenderer(); @@ -2225,19 +2301,20 @@ render.Settings.AutoTag = true; //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(); -//Saves the PDF file -MemoryStream outputStream = new MemoryStream(); -pdfDocument.Save(outputStream); -//Closes the instance of PDF document object -pdfDocument.Close(); +//Saves the PDF file to file system +pdfDocument.Save("WordtoPDF.pdf"); +//Closes 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; + //Loads an existing Word document WordDocument wordDocument = new WordDocument("Sample.docx", FormatType.Docx); @@ -2259,6 +2336,10 @@ wordDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.DocIO.DLS +Imports Syncfusion.DocIORenderer +Imports Syncfusion.Pdf + 'Loads an existing Word document Dim wordDocument As New WordDocument("Sample.docx", FormatType.Docx) @@ -2304,6 +2385,10 @@ The following code sample demonstrates how to create custom role mapping documen {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Tagged%20PDF/Custom-Role-Mapping/.NET/Custom-Role-Mapping/Program.cs" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using Syncfusion.Drawing; + // Create a new PDF document PdfDocument doc = new PdfDocument(); @@ -2344,10 +2429,8 @@ element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); // Draw text on the page PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width, 200)); -// Save the document into a memory stream (Cross-platform compatibility) -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -stream.Position = 0; // Reset stream position for further processing if needed +// Save the document +doc.Save("Output.pdf"); // Close the document to release resources doc.Close(true); @@ -2355,6 +2438,10 @@ doc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using System.Drawing; + // Create a new PDF document PdfDocument doc = new PdfDocument(); @@ -2405,6 +2492,10 @@ doc.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 doc As New PdfDocument() @@ -2464,10 +2555,13 @@ You can extract the existing tag details by using the [StructureElement](https:/ {% highlight c# tabtitle="C# [Cross-platform]" %} -//Get the stream from the document. -FileStream documentStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using System.Drawing; + //Load the existing PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(documentStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the structure element root from the document. PdfStructureElement rootElement = document.StructureElement; //Get the child elements for the element. @@ -2493,6 +2587,11 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using System.Drawing; + //Load the existing PDF document. PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the structure element root from the document. @@ -2522,6 +2621,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.Parsing + 'Load the existing PDF document. Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the structure element root from the document. @@ -2557,10 +2661,13 @@ You can also extract the accessibility tags page-wise with the help of the [Stru {% highlight c# tabtitle="C# [Cross-platform]" %} -//Get the stream from the document. -FileStream documentStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using System.Drawing; + //Load the existing PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(documentStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the first page from the document. PdfLoadedPage loadedPage = document.Pages[0] as PdfLoadedPage; //Get the structure elements associated with the page. @@ -2590,6 +2697,11 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; +using System.Drawing; + //Load the existing PDF document. PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the first page from the document. @@ -2622,6 +2734,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.Parsing + 'Load the existing PDF document. Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Get the first page from the document. diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Text-Extraction.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Text-Extraction.md index 2c4e45eef..5f0638fb1 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Text-Extraction.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Text-Extraction.md @@ -22,10 +22,11 @@ The following code snippet explains how to extract the texts from a page. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text%20Extraction/Extract-the-texts-from-a-page-in-the-PDF-document/.NET/Extract-the-texts-from-a-page-in-the-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("Sample.pdf", FileMode.Open, FileAccess.Read); -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the first page. PdfPageBase page = loadedDocument.Pages[0]; @@ -38,8 +39,11 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the first page. PdfPageBase page = loadedDocument.Pages[0]; @@ -52,8 +56,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +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 page As PdfPageBase = loadedDocument.Pages(0) @@ -78,10 +85,11 @@ The below code illustrates how to extract the text from entire PDF document: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text%20Extraction/Extract-text-from-the-entire-PDF-document/.NET/Extract-text-from-the-entire-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("Sample.pdf", FileMode.Open, FileAccess.Read); -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Loading page collections PdfLoadedPageCollection loadedPages = loadedDocument.Pages; @@ -98,8 +106,11 @@ 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(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Loading page collections PdfLoadedPageCollection loadedPages = loadedDocument.Pages; @@ -116,8 +127,11 @@ loadedDocument.Close(true); {% 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(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") ' Loading page collections Dim loadedPages As PdfLoadedPageCollection = loadedDocument.Pages @@ -145,10 +159,11 @@ Please refer the following code snippet to extract the text with layout. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text%20Extraction/Extract-the-text-with-layout-in-a-PDF-document/.NET/Extract-the-text-with-layout-in-a-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream("Sample.pdf", FileMode.Open, FileAccess.Read); -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load first page. PdfPageBase page = loadedDocument.Pages[0]; @@ -157,9 +172,8 @@ string extractedTexts = page.ExtractText(true); //Close the document. loadedDocument.Close(true); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document +loadedDocument.Save("Output.pdf"); //Closes the document loadedDocument.Close(true); @@ -167,8 +181,11 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //Load an existing PDF. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load first page. PdfPageBase page = loadedDocument.Pages[0]; @@ -181,15 +198,20 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -//Load an existing PDF. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); -//Load first page. -PdfPageBase page = loadedDocument.Pages[0]; +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing -//Extract text from first page. -string extractedTexts = page.ExtractText(true); -//close the document -loadedDocument.Close(true); +' Load an existing PDF +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") + +' Load the first page +Dim page As PdfPageBase = loadedDocument.Pages(0) + +' Extract text from the first page +Dim extractedTexts As String = page.ExtractText(True) + +' Close the document +loadedDocument.Close(True) {% endhighlight %} @@ -211,8 +233,11 @@ You can get the line and its properties that contains texts by using [TextLine]( //PDF supports getting the lines and its properties using TextLine only in WinForms, WPF and Xamarin platforms. Instead of TextLine, TextLineCollection can be used in ASP.NET Core. +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + // Load the existing PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Get the first page of the loaded PDF document PdfPageBase page = loadedDocument.Pages[0]; var lineCollection = new TextLineCollection(); @@ -232,8 +257,11 @@ foreach (var line in lineCollection.TextLine) {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + // Load the existing PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Get the first page of the loaded PDF document PdfPageBase page = loadedDocument.Pages[0]; TextLines lineCollection = new TextLines(); @@ -250,8 +278,12 @@ string text = line.Text; {% endhighlight %} {% 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(fileName) +Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") ' Get the first page of the loaded PDF document Dim page As PdfPageBase = loadedDocument.Pages(0) Dim lineCollection As TextLines = New TextLines() @@ -281,8 +313,12 @@ You can get the single word and its properties by using [TextWord](https://help. //PDF supports getting the word and its properties using TextWord only in WinForms, WPF and Xamarin platforms. Instead of TextLine, TextLineCollection can be used in ASP.NET Core. +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + // Load the existing PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Get the first page of the loaded PDF document PdfPageBase page = loadedDocument.Pages[0]; var lineCollection = new TextLineCollection(); @@ -304,8 +340,12 @@ foreach (var line in lineCollection.TextLine) {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + // Load the existing PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Get the first page of the loaded PDF document PdfPageBase page = loadedDocument.Pages[0]; TextLines lineCollection = new TextLines(); @@ -325,8 +365,12 @@ List textWordCollection = line.WordCollection; {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing +Imports System.Drawing + ' Load the existing PDF document -Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument(fileName) +Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") ' Get the first page of the loaded PDF document Dim page As PdfPageBase = loadedDocument.Pages(0) Dim lineCollection As TextLines = New TextLines() @@ -356,8 +400,12 @@ You can retrieve a single character and its properties, including bounds, font n {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text%20Extraction/Get-text-glyph-details-from-extract-text/.NET/Get-text-glyph-details-from-extract-text/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + // Load the existing PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Get the first page of the loaded PDF document PdfPageBase page = loadedDocument.Pages[0]; TextLineCollection lineCollection = new TextLineCollection(); @@ -393,8 +441,12 @@ Color glyphColor = textGlyph.TextColor; {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing +Imports System.Drawing + ' Load the existing PDF document -Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument(stream) +Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") ' Get the first page of the loaded PDF document Dim page As PdfPageBase = loadedDocument.Pages(0) Dim lineCollection As New TextLineCollection() @@ -441,9 +493,11 @@ The code example provided below demonstrates the utilization of the [FindText](h {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Find-text-in-PDF-document/.NET/Find-text-in-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Parsing; + //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"); //Returns page number and rectangle positions of the text maches. Dictionary> matchRects = new Dictionary>(); loadedDocument.FindText("document", out matchRects); @@ -454,6 +508,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"); //Returns page number and rectangle positions of the text maches. @@ -466,6 +523,9 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Parsing + 'Load an existing PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf") 'Returns page number and rectangle positions of the text maches. diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Text.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Text.md index 864810cdb..18c4d8516 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Text.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Text.md @@ -20,6 +20,10 @@ You can add text in the new PDF document by using [DrawString](https://help.sync {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Drawing-text-in-a-new-PDF-document/.NET/Drawing-text-in-a-new-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 page to the document. @@ -32,17 +36,18 @@ 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 memory stream. -document.Save(stream); -//Close the document. +//Save the document and dispose it +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 page to the document. @@ -64,6 +69,10 @@ document.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 document As New PdfDocument() 'Add a page to the document. @@ -98,6 +107,10 @@ Please refer to the below code example to understand how to save and restore the {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/refs/heads/master/Text/Saving-and-Restoring-the-PdfGraphics/.NET/Saving-and-Restoring-the-PdfGraphics/Saving-and-Restoring-the-PdfGraphics/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + // Create a new PDF document using (PdfDocument pdfDocument = new PdfDocument()) { @@ -116,11 +129,8 @@ using (PdfDocument pdfDocument = new PdfDocument()) graphics.Restore(); // Draw text that is not influenced by transformations graphics.DrawString("This text is not rotated.", font, PdfBrushes.Black, new PointF(0, 100)); - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - //Save the PDF document to file stream. - pdfDocument.Save(outputFileStream); - } + // Save the document to a file + pdfDocument.Save("Output.pdf"); } @@ -128,6 +138,10 @@ using (PdfDocument pdfDocument = new PdfDocument()) {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + // Create a new PDF document using (PdfDocument pdfDocument = new PdfDocument()) { @@ -153,6 +167,11 @@ using (PdfDocument pdfDocument = new PdfDocument()) {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + + Imports Syncfusion.Pdf + Imports Syncfusion.Pdf.Graphics + Imports System.Drawing + ' Create a PDF document Using pdfDocument As New PdfDocument() ' Add Pages to the document @@ -171,8 +190,9 @@ using (PdfDocument pdfDocument = new PdfDocument()) graphics.Restore() ' Draw text that is not influenced by transformations graphics.DrawString("This text is not rotated.", font, PdfBrushes.Black, New PointF(0, 100)) - ' Save the document to a file + ' Save and close the document to a file pdfDocument.Save("Output.pdf") + pdfDocument.Close(True) {% endhighlight %} @@ -190,9 +210,13 @@ The following code snippet illustrates how to add text in the existing PDF docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Draw-text-in-an-existing-PDF-document/.NET/Draw-text-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 doc = new PdfLoadedDocument(docStream); +PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf"); //Get first page from document. PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage; //Create PDF graphics for the page. @@ -203,10 +227,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 memory stream. -doc.Save(stream); +//Save the document. +doc.Save("Output.pdf"); //Close the document. doc.Close(true); @@ -214,6 +236,11 @@ doc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +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. @@ -235,6 +262,11 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing +Imports Syncfusion.Pdf.Parsing + 'Load a PDF document. Dim doc As New PdfLoadedDocument("input.pdf") 'Get first page from document @@ -278,6 +310,10 @@ You can add text using the standard PDF fonts, by initializing [PdfFont](https:/ {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Draw-text-in-PDF-document-using-standard-fonts/.NET/Draw-text-in-PDF-document-using-standard-fonts/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. @@ -290,17 +326,18 @@ 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 memory stream. -document.Save(stream); -//Close the document. +//Save the document and dispose it +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 page to the document. @@ -322,6 +359,10 @@ document.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 document As New PdfDocument() 'Add a page to the document. @@ -353,6 +394,9 @@ You can add text using the TrueType fonts installed in the system, by initializi {% 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. @@ -374,6 +418,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + 'Create a new PDF document. Dim document As New PdfDocument() 'Add a page to the document. @@ -401,6 +448,9 @@ You can add text using the font file from local file system by providing the pat {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Draw-text-in-a-PDF-using-TrueType-fonts/.NET/Draw-text-in-a-PDF-using-TrueType-fonts/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -414,17 +464,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); -//Close the document. +//Save the document and dispose it +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 to the document. @@ -446,6 +496,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 to the document. @@ -477,6 +530,9 @@ You can add text using CJK fonts, initializing [PdfFont](https://help.syncfusion {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Draw-text-in-a-PDF-using-CJK-fonts/.NET/Draw-text-in-a-PDF-using-CJK-fonts/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -489,10 +545,8 @@ PdfFont font = new PdfCjkStandardFont(PdfCjkFontFamily.HeiseiMinchoW3, 20); //Draw the text. graphics.DrawString("こんにちは世界", 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); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -500,6 +554,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. @@ -521,6 +578,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 to the document. @@ -552,6 +612,10 @@ The Essential® PDF allows you to measure the size of a string whi {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Measure-the-text-in-PDF-document/.NET/Measure-the-text-in-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create the new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document @@ -567,17 +631,19 @@ SizeF size = font.MeasureString(text); //Draw string to th ePDF page graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(PointF.Empty, size)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -document.Save(stream); -//Close the document +//Save the document. +document.Save("Output.pdf"); +//Close the document. document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create the new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document @@ -602,6 +668,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Create the new PDF document Dim document As New PdfDocument() 'Add a page to the document @@ -639,6 +709,10 @@ Refer to the following code example for further information. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Measure-tilting-space-in-PDF/.NET/Measure-tilting-space-in-PDF/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + PdfDocument document = new PdfDocument(); //Add a page to the document PdfPage page = document.Pages.Add(); @@ -655,18 +729,20 @@ string text = "Hello World!"; SizeF size = font.MeasureString(text, format); //Draw the text to the PDF document. page.Graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(0, 0, size.Width, size.Height)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document as stream -document.Save(stream); -//Close the document -document.Close(true); +//Save the document. +document.Save("Output.pdf"); +//Close the document. +document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} - //Create a new PDF document +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 PdfPage page = document.Pages.Add(); @@ -690,6 +766,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Create the new PDF document Dim document As PdfDocument = New PdfDocument() 'Add a page to the document @@ -707,9 +787,8 @@ Dim text As String = "Hello World!" Dim size As SizeF = font.MeasureString(text, format) 'Draw the text to the PDF document. page.Graphics.DrawString(text, font, PdfBrushes.Black, New RectangleF(0, 0, size.Width, size.Height)) -Dim stream As MemoryStream = New MemoryStream() -Save the document as stream -document.Save(stream) +Save the document +document.Save("Output.pdf") Close the document document.Close(True) @@ -735,6 +814,10 @@ N> To render a Unicode text in the PDF document the chosen font should have the {% 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. @@ -760,6 +843,10 @@ document.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 document As New PdfDocument() 'Add a page to the document. @@ -795,6 +882,10 @@ The Essential® PDF allows you to draw the right-to-left language {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Draw-Right-To-Left-text-in-a-PDF-document/.NET/Draw-Right-To-Left-text-in-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document @@ -827,10 +918,8 @@ format.Alignment = PdfTextAlignment.Left; //Draw string with left-to-right format graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(0, 100, page.GetClientSize().Width, page.GetClientSize().Height), format); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -doc.Save(stream); +//Save the document +doc.Save("Output.pdf"); //Close the document doc.Close(true); @@ -838,6 +927,10 @@ doc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document @@ -877,6 +970,10 @@ doc.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 doc As PdfDocument = New PdfDocument() 'Add a page to the document @@ -977,6 +1074,10 @@ The following code example illustrates how to render the HTML string in a PDF do {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Adding-HTML-styled-text-to-PDF-document/.NET/Adding-HTML-styled-text-to-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document @@ -997,16 +1098,19 @@ format.Break = PdfLayoutBreakType.FitPage; //Draw htmlString. richTextElement.Draw(page, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height), format); -//Save the document into stream -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; + //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Add a page to the document. @@ -1038,6 +1142,10 @@ doc.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 doc As New PdfDocument() 'Add a page to the document. @@ -1078,6 +1186,9 @@ Essential® PDF allows you to create multi-column text in PDF docu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Creating-a-multicolumn-PDF-document/.NET/Creating-a-multicolumn-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a PDF document instance PdfDocument document = new PdfDocument(); //Add page to the document @@ -1094,10 +1205,8 @@ textElement = new PdfTextElement(text, new PdfStandardFont(PdfFontFamily.TimesRo //Draw the text in the second column textElement.Draw(page, new RectangleF(page.GetClientSize().Width / 2, 0, page.GetClientSize().Width / 2, page.GetClientSize().Height)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1105,6 +1214,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a PDF document instance PdfDocument document = new PdfDocument(); //Add page to the document @@ -1129,6 +1241,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a PDF document instance Dim document As New PdfDocument() 'Add page to the document @@ -1165,6 +1280,9 @@ The following code example demonstrates how to add elements relatively and also {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Add-text-across-multiple-pages/.NET/Add-text-across-multiple-pages/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a PDF document instance PdfDocument document = new PdfDocument(); //Add page to the document @@ -1188,10 +1306,8 @@ PdfLayoutResult result = textElement.Draw(page, new RectangleF(0, 0, page.GetCli //Draw the second paragraph from the first paragraph end position result = textElement.Draw(page, new RectangleF(0, result.Bounds.Bottom + paragraphGap, page.GetClientSize().Width / 2, page.GetClientSize().Height), layoutFormat); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1199,6 +1315,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a PDF document instance PdfDocument document = new PdfDocument(); //Add page to the document @@ -1230,6 +1349,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics + 'Create a PDF document instance Dim document As New PdfDocument() 'Add page to the document @@ -1280,6 +1402,10 @@ The following code example illustrates how to insert RTF text in PDF document. {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Add a page. @@ -1307,6 +1433,10 @@ doc.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 doc As New PdfDocument() 'Add a page. @@ -1345,6 +1475,10 @@ Essential® PDF allows you to create an ordered list in the docume {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Adding-an-ordered-list-to-PDF-document/.NET/Adding-an-ordered-list-to-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new instance of PdfDocument class. PdfDocument document = new PdfDocument(); //Add a new page to the document. @@ -1374,10 +1508,8 @@ foreach (string s in products) } pdfList.Draw(page, new RectangleF(0, 20, size.Width, size.Height)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1385,6 +1517,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new instance of PdfDocument class. PdfDocument document = new PdfDocument(); //Add a new page to the document. @@ -1422,6 +1558,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Create a new instance of PdfDocument class. Dim document As New PdfDocument() 'Add a new page to the document. @@ -1469,6 +1609,10 @@ Essential® PDF also provides support to create an unordered List {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Adding-an-unordered-list-to-PDF-document/.NET/Adding-an-unordered-list-to-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new instance of PdfDocument class. PdfDocument document = new PdfDocument(); //Add a new page to the document. @@ -1502,10 +1646,8 @@ list.TextIndent = 10; //Draw list list.Draw(page, new RectangleF(0, 10, size.Width, size.Height)); -//Creating the stream object -MemoryStream stream = new MemoryStream(); -//Save the document into memory stream -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1513,6 +1655,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Create a new instance of PdfDocument class. PdfDocument document = new PdfDocument(); //Add a new page to the document. @@ -1554,6 +1700,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Create a new instance of PdfDocument class. Dim document As New PdfDocument() 'Add a new page to the document. @@ -1611,6 +1761,10 @@ Essential® PDF allows you to replace the fonts in an existing PDF {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + //Creates a new PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Replace font @@ -1624,6 +1778,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Creates a new PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Replace font @@ -1653,6 +1811,9 @@ The following code snippet illustrates how to get the bound of a text from PDF d {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.PdfViewer; + PdfViewerControl documentViewer = new PdfViewerControl(); //Load the PDF document documentViewer.Load("Input.pdf"); @@ -1666,6 +1827,9 @@ documentViewer.Dispose(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing; +Imports Syncfusion.PdfViewer; + Dim documentViewer As New PdfViewerControl() 'Load the PDF document documentViewer.Load("Input.pdf") @@ -1687,6 +1851,10 @@ Essential® PDF allows you to add complex script language text in {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Drawing-complex-script-language-text-to-PDF/.NET/Drawing-complex-script-language-text-to-PDF/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Drawing; + //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document @@ -1704,16 +1872,19 @@ format.ComplexScript = true; //Draw the text graphics.DrawString("สวัสดีชาวโลก", pdfFont, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format); -//Save the PDF document -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -//Close the PDF document +//Save the document +doc.Save("Output.pdf"); +//Close the document doc.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using System.Drawing; + //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document @@ -1740,6 +1911,10 @@ doc.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 doc As New PdfDocument() 'Add a page to the document @@ -1774,9 +1949,12 @@ You can add the complex script language text in an existing PDF document by usin {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Add-complex-script-to-an-existing-PDF-document/.NET/Add-complex-script-to-an-existing-PDF-document/Program.cs" %} -FileStream inputFileStream = new FileStream("input.pdf", FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Drawing; + //Load a PDF document -PdfLoadedDocument doc = new PdfLoadedDocument(inputFileStream); +PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf"); //Get first page from the document PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage; @@ -1792,16 +1970,19 @@ format.ComplexScript = true; //Draw the text graphics.DrawString("สวัสดีชาวโลก", pdfFont, PdfBrushes.Black, new RectangleF(0, 0, page.Size.Width, page.Size.Height), format); -//Save the PDF document -MemoryStream stream = new MemoryStream(); -await doc.Save(stream); -//Close the PDF document +//Save the document +doc.Save("Output.pdf"); +//Close the document doc.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using System.Drawing; + //Load a PDF document PdfLoadedDocument doc = new PdfLoadedDocument("input.pdf"); //Get first page from the document @@ -1828,6 +2009,10 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports System.Drawing + 'Load a PDF document Dim doc As New PdfLoadedDocument("input.pdf") 'Get first page from the document @@ -1864,6 +2049,10 @@ Essential® PDF supports drawing text on a PDF document with OpenT {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Draw-text-using-OpenTypeFont-in-PDF-document/.NET/Draw-text-using-OpenTypeFont-in-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Drawing; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page @@ -1884,16 +2073,19 @@ RectangleF rect = new RectangleF(0, 0, clipBounds.Width, clipBounds.Height); //Draw the text page.Graphics.DrawString(text, font, brush, rect); -//Save the PDF document -MemoryStream stream = new MemoryStream(); -document.Save(stream); -//Close the PDF document +//Save the document. +document.Save("Output.pdf"); +//Close the document. document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using System.Drawing; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document @@ -1919,6 +2111,10 @@ document.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 document As PdfDocument = New PdfDocument 'Add a page to the document @@ -1954,6 +2150,10 @@ The Essential® PDF allows you to draw text using a different type {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Drawing-text-with-baseline-alignment-in-a-PDF/.NET/Drawing-text-with-baseline-alignment-in-a-PDF/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Drawing; + //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document @@ -1981,23 +2181,19 @@ graphics.DrawString("Hello World!", font, PdfBrushes.Black, new PointF(0, 50), f graphics.DrawString("Hello World!", font1, PdfBrushes.Black, new PointF(65, 50), format); graphics.DrawString("Hello World!", font2, PdfBrushes.Black, new PointF(220, 50), format); graphics.DrawString("Hello World!", font3, PdfBrushes.Black, new PointF(320, 50), format); -//Save the PDF document -MemoryStream stream = new MemoryStream(); -doc.Save(stream); -//Close the PDF 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); +//Save the document +doc.Save("Output.pdf"); +//Close the document +doc.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using System.Drawing; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document @@ -2032,6 +2228,10 @@ document.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 document As New PdfDocument() 'Add a page to the document @@ -2078,6 +2278,10 @@ The following code sample explains this. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Drawing-text-using-different-text-alignment/.NET/Drawing-text-using-different-text-alignment/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Drawing; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document @@ -2099,19 +2303,19 @@ graphics.DrawRectangle(PdfPens.Black, new RectangleF(10, 10, 200, 20)); //Draw the text graphics.DrawString("Right-Alignment", font, PdfBrushes.Red, new RectangleF(10, 10, 200, 20), format); -//Create a file stream to save the document -using (FileStream fs = new FileStream("Output.pdf", FileMode.Create, FileAccess.Write)) -{ - //Save the document to the file stream - document.Save(fs); -} -//Close the document +//Save the document. +document.Save("Output.pdf"); +//Close the document. document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using System.Drawing; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document @@ -2143,6 +2347,10 @@ document.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 document As New PdfDocument() 'Add a page to the document @@ -2186,6 +2394,10 @@ N>To enable this functionality in .NET Core, ensure that the following encoding {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Add-text-encoding-using-standard-PDF-fonts/.NET/Add-text-encoding-using-standard-PDF-fonts/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Drawing; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Adding a new page to the PDF document @@ -2200,10 +2412,8 @@ font.SetTextEncoding(Encoding.GetEncoding("Windows-1250")); //Draw string to a PDF page. graphics.DrawString("äÖíßĆŇ", font, PdfBrushes.Black, PointF.Empty); -//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); @@ -2211,6 +2421,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using System.Drawing; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Adding a new page to the PDF document. @@ -2234,6 +2448,10 @@ document.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 document As PdfDocument = New PdfDocument() 'Adding a new page to the PDF document. @@ -2269,6 +2487,10 @@ The following code example demonstrates how to access the remainder text when th {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Drawing; + // Create a new PDF document PdfDocument document = new PdfDocument(); @@ -2311,6 +2533,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using System.Drawing; + // Create a new PDF document PdfDocument document = new PdfDocument(); @@ -2353,6 +2579,10 @@ document.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 document As New PdfDocument() @@ -2406,6 +2636,10 @@ The following code example illustrates this. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Text/Customizing-truetype-fonts-in-a-PDF/.NET/Customizing-truetype-fonts-in-a-PDF/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Drawing; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -2417,11 +2651,11 @@ FileStream fontStream = new FileStream("Arial.ttf", FileMode.Open, FileAccess.Re // Initialize the PdfFontSettings PdfFontSettings fontSettings = new PdfFontSettings(10, PdfFontStyle.Bold, true, true, true); PdfFont pdfFont = new PdfTrueTypeFont(fontStream, fontSettings); -//Draw the text. graphics.DrawString("Hello World!!!", pdfFont, PdfBrushes.Black, new PointF(0, 0)); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document into stream. -document.Save(stream); +//Draw the text. +graphics.DrawString("Hello World!!!", pdfFont, PdfBrushes.Black, new PointF(0, 0)); + +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -2429,6 +2663,10 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using System.Drawing; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. @@ -2438,7 +2676,8 @@ PdfGraphics graphics = page.Graphics; // Initialize the PdfFontSettings PdfFontSettings fontSettings = new PdfFontSettings(10, PdfFontStyle.Bold, true, true, true); PdfFont pdfFont = new PdfTrueTypeFont(new Font("Arial"), fontSettings); -//Draw the text. graphics.DrawString("Hello World!!!", pdfFont, PdfBrushes.Black, new PointF(0, 0)); +//Draw the text. +graphics.DrawString("Hello World!!!", pdfFont, PdfBrushes.Black, new PointF(0, 0)); //Save the document. document.Save("Output.pdf"); //Close the document. @@ -2448,6 +2687,10 @@ document.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 document As PdfDocument = New PdfDocument 'Add a page to the document. @@ -2476,7 +2719,6 @@ You can download a complete working sample from [GitHub](https://github.com/Sync **LineLimit:** When LineLimit is enabled, the provided string will be laid out within the specified bounds. If the LineLimit property is disabled, the layout will continue to fill any remaining space. The default value of the LineLimit property is true. - **NoClip:** If we enable the NoClip option, it will show the text without cutting any words. If we disable the NoClip option, any text outside the fitting area will be hidden. The following code example illustrates this. @@ -2485,6 +2727,10 @@ The following code example illustrates this. {% highlight c# tabtitle="C# [Cross-platform]" %} + using Syncfusion.Pdf; + using Syncfusion.Pdf.Graphics; + using Syncfusion.Drawing; + // Create a new PdfStringFormat and set its properties PdfStringFormat format = new PdfStringFormat(); //Set no clip @@ -2512,10 +2758,8 @@ The following code example illustrates this. // Draw the string inside the rectangle with the specified font, brush, and format graphics.DrawString("PDF text line 1 \r\nPDF text line 3", font, PdfBrushes.Black, new RectangleF(100, 100, 100, 20), format); - //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); @@ -2524,6 +2768,10 @@ The following code example illustrates this. {% highlight c# tabtitle="C# [Windows-specific]" %} + using Syncfusion.Pdf; + using Syncfusion.Pdf.Graphics; + using System.Drawing; + // Create a new PdfStringFormat and set its properties PdfStringFormat format = new PdfStringFormat(); //Set no clip @@ -2560,6 +2808,10 @@ The following code example illustrates this. {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + Imports Syncfusion.Pdf + Imports Syncfusion.Pdf.Graphics + Imports System.Drawing + ' Create a new PdfStringFormat and set its properties Dim format As New PdfStringFormat() ' Set no clip diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-Watermarks.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-Watermarks.md index d3422ab4d..78ca24559 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-Watermarks.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-Watermarks.md @@ -20,6 +20,10 @@ The below code illustrates how to draw the text watermark in new PDF document us {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Watermark/Adding-text-watermark-in-PDF-document/.NET/Adding-text-watermark-in-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. @@ -35,23 +39,18 @@ graphics.SetTransparency(0.25f); graphics.RotateTransform(-40); graphics.DrawString("Imported using Essential PDF", font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); -stream.Position = 0; -//Close the document. +//Save and close the document. +pdfDocument.Save("Watermark.pdf"); pdfDocument.Close(true); -//Defining the content type for PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Watermark.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 a new PDF document. PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document. @@ -75,6 +74,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 +112,13 @@ The below code illustrates how to draw the text watermark in an existing PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Watermark/Add-text-watermark-in-an-existing-PDF-document/.NET/Add-text-watermark-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + //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"); //Get first page from document. PdfPageBase loadedPage = loadedDocument.Pages[0]; //Create PDF graphics for the page. @@ -124,27 +131,23 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); PdfGraphicsState state = graphics.Save(); graphics.SetTransparency(0.25f); graphics.RotateTransform(-40); -graphics.DrawString("Imported using Essential PDF", font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, +graphics.DrawString("Imported using Essential PDF", font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Close the document. +//Save and close the document. +loadedDocument.Save("Watermark.pdf"); loadedDocument.Close(true); -//Defining the content type for PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Watermark.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; + //Load an existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get first page from document. PdfPageBase loadedPage = loadedDocument.Pages[0]; //Create PDF graphics for the page. @@ -166,8 +169,13 @@ 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 an existing PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get first page from document. Dim loadedPage As PdfPageBase = loadedDocument.Pages(0) 'Create PDF graphics for the page. @@ -203,6 +211,10 @@ The below code sample illustrates how to add image watermark in PDF document, us {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Watermark/Adding-image-watermark-in-PDF-document/.NET/Adding-image-watermark-in-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. @@ -219,23 +231,18 @@ graphics.SetTransparency(0.25f); //Draw the image. graphics.DrawImage(image, new PointF(0, 0), pdfPage.Graphics.ClientSize); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -pdfDocument.Save(stream); -stream.Position = 0; -//Close the document. +//Save and close the document. +pdfDocument.Save("Watermark.pdf"); pdfDocument.Close(true); -//Defining the content type for PDF file. -string contentType = "application/pdf"; -//Define the file name. -string fileName = "Watermark.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 a new PDF document. PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document. @@ -258,6 +265,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. @@ -291,9 +302,13 @@ The below code illustrates how to draw the image watermark in existing PDF docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Watermark/Draw-the-image-watermark-in-an-existing-PDF-document/.NET/Draw-the-image-watermark-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 PdfPageBase loadedPage = loadedDocument.Pages[0]; //Create PDF graphics for the page @@ -307,25 +322,21 @@ graphics.SetTransparency(0.25f); //Draw the image graphics.DrawImage(image, new PointF(0, 0), loadedPage.Graphics.ClientSize); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -stream.Position = 0; -//Close the document +//Save and close the document. +loadedDocument.Save("watermark.pdf"); loadedDocument.Close(true); -//Defining the content type for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Watermark.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; + //Load an existing document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get first page from document. PdfPageBase loadedPage = loadedDocument.Pages[0]; //Create PDF graphics for the page. @@ -346,8 +357,13 @@ 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 document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get first page from document. Dim loadedPage As PdfPageBase = loadedDocument.Pages(0) 'Create PDF graphics for the page @@ -382,9 +398,13 @@ The following code example explains how to add a watermark annotation in the PDF {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Annotation/Add-watermark-annotation-in-the-PDF-document/.NET/Add-watermark-annotation-in-the-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 the page PdfLoadedPage lpage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -397,16 +417,19 @@ watermark.Appearance.Normal.Graphics.DrawString("Watermark Text", new PdfStandar //Adds the annotation to page lpage.Annotations.Add(watermark); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); -//Close the document -loadedDocument.Close(true); +//Saves the document. +loadedDocument.Save("WatermarkAnnotation.pdf"); +loadedDocument.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 PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf"); //Get the page @@ -429,6 +452,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 the page @@ -460,9 +488,12 @@ You can remove the Watermark annotation from the annotation collection, represen {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Watermark/Removing-watermark-annotation-in-PDF-document/.NET/Remove-watermark-annotation-in-the-PDF-document/Program.cs" %} + 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"); // Iterate through the annotations collection and remove PdfLoadedWatermark annotations foreach (PdfPageBase page in loadedDocument.Pages) { @@ -477,16 +508,18 @@ You can remove the Watermark annotation from the annotation collection, represen } } - //Save the document into stream - MemoryStream stream = new MemoryStream(); - loadedDocument.Save(stream); - //Close the document - loadedDocument.Close(true); + //Saves the document to disk. + loadedDocument.Save("WatermarkAnnotation.pdf"); + 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("input.pdf"); // Iterate through the annotations collection and remove PdfLoadedWatermark annotations @@ -511,6 +544,10 @@ You can remove the Watermark annotation from the annotation collection, represen {% 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 New PdfLoadedDocument("input.pdf") ' Iterate through the annotations collection and remove PdfLoadedWatermark annotations diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-XFA.MD b/Document-Processing/PDF/PDF-Library/NET/Working-with-XFA.MD index f64c310e9..92cc4fa51 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-XFA.MD +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-XFA.MD @@ -24,6 +24,8 @@ The following code example explains how to add a new page using [PdfXfaPage](htt {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-a-new-page-in-a-PDF-XFA-document/.NET/Add-a-new-page-in-a-PDF-XFA-document/Program.cs" %} +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -38,16 +40,16 @@ mainForm.Fields.Add(textElement); //Add the XFA form to the document. document.XfaForm = mainForm; -//Save the PDF document to stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf", PdfXfaType.Dynamic); //Close the document. document.Close(); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -71,6 +73,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Xfa + 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -110,6 +114,10 @@ The below sample illustrates how to create a new PDF document with XFA page size {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Create-a-new-PDF-document-with-XFA-page-size/.NET/Create-a-new-PDF-document-with-XFA-page-size/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Set the page size. @@ -128,9 +136,8 @@ mainForm.Fields.Add(textElement); //Add the XFA form to the document. document.XfaForm = mainForm; -//Save the PDF document to stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -138,6 +145,10 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Set the page size. @@ -165,6 +176,10 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Xfa + 'Create a new PDF XFA document. Dim document As New PdfXfaDocument() 'Set the page size. @@ -200,6 +215,10 @@ You can create a custom page size to the PDF document by using following code sn {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Create-a-custom-page-size-to-the-PDF-document/.NET/Create-a-custom-page-size-to-the-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Set the page size. @@ -218,9 +237,8 @@ mainForm.Fields.Add(textElement); //Add the XFA form to the document. document.XfaForm = mainForm; -//Save the PDF document to stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -228,6 +246,10 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Set the page size. @@ -255,6 +277,10 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Xfa + 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Set the page size @@ -290,6 +316,10 @@ You can change page orientation from portrait to landscape by using [PdfXfaPageO {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Change-page-orientation-from-portrait-to-landscape-in-PDF/.NET/Change-page-orientation-from-portrait-to-landscape-in-PDF/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Set the page size. @@ -310,9 +340,8 @@ mainForm.Fields.Add(textElement); //Add the XFA form to the document. document.XfaForm = mainForm; -//Save the PDF document to stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -320,6 +349,10 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Set the page size. @@ -349,6 +382,10 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Xfa + 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Set the page size @@ -388,6 +425,10 @@ To create a dynamic XFA forms using [PdfXfaType](https://help.syncfusion.com/cr/ {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Create-a-dynamic-XFA-forms-in-a-PDF-document/.NET/Create-a-dynamic-XFA-forms-in-a-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Set the page size. @@ -406,9 +447,8 @@ mainForm.Fields.Add(textElement); //Add the XFA form to the document. document.XfaForm = mainForm; -//Save the PDF document to stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -416,6 +456,10 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Set the page size. @@ -443,6 +487,10 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Xfa + 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Set the page size @@ -480,6 +528,10 @@ To create a static XFA forms using [PdfXfaType](https://help.syncfusion.com/cr/d {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Create-a-static-XFA-forms-in-a-PDF-document/.NET/Create-a-static-XFA-forms-in-a-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Set the page size. @@ -498,9 +550,8 @@ mainForm.Fields.Add(textElement); //Add the XFA form to the document. document.XfaForm = mainForm; -//Save the PDF document to stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, PdfXfaType.Static); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -508,6 +559,10 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Set the page size. @@ -535,6 +590,10 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Xfa + 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Set the page size @@ -574,6 +633,9 @@ The below code snippet illustrates how to add a textbox field to a new PDF docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -592,9 +654,8 @@ mainForm.Fields.Add(textBoxField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Save the PDF document to stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -602,6 +663,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -629,6 +693,9 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Create a new PDF XFA document. Dim document As New PdfXfaDocument() 'Add a new XFA page. @@ -664,10 +731,11 @@ The below code snippet illustrates how to add a textbox field to an existing PDF {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-a-textbox-field-to-an-existing-PDF-document/.NET/Add-a-textbox-field-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -680,10 +748,8 @@ textBoxField.ToolTip = "First Name"; //Add the field to the existing XFA form. loadedForm.Fields.Add(textBoxField); -//Create memory stream. -MemoryStream stream = new MemoryStream(); //Save the document. -loadedDocument.Save(stream); +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -691,6 +757,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -714,6 +783,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document. Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form. @@ -747,6 +819,9 @@ The below code snippet illustrates how to add a numeric field to a new PDF docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-a-XFA-numeric-field-to-a-new-PDF-document/.NET/Add-a-XFA-numeric-field-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -763,9 +838,8 @@ mainForm.Fields.Add(numericField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Save the PDF document to stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -773,6 +847,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -798,6 +875,9 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf. + 'Create a new PDF XFA document. Dim document As New PdfXfaDocument() 'Add a new XFA page. @@ -831,10 +911,11 @@ The below code snippet illustrates how to add the numeric field to an existing P {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-numeric-field-to-an-existing-PDF-document/.NET/Add-the-XFA-numeric-field-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -845,10 +926,8 @@ numericField.Caption.Text = "Numeric Field"; //Add the field to the existing XFA form. loadedForm.Fields.Add(numericField); -//Create memory stream. -MemoryStream stream = new MemoryStream(); //Save the document. -loadedDocument.Save(stream); +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -856,6 +935,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -877,6 +959,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -908,6 +993,9 @@ The below code snippet illustrates how to add a combo box field to a new PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-a-combobox-field-to-a-new-PDF-document/.NET/Add-a-combobox-field-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -929,10 +1017,8 @@ mainForm.Fields.Add(comboBoxField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); //Save the document. -document.Save(stream, PdfXfaType.Dynamic); +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -940,6 +1026,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -969,6 +1058,9 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Create a new PDF XFA document Dim document As PdfXfaDocument = New PdfXfaDocument() 'Add a new XFA page @@ -1006,10 +1098,11 @@ The below code snippet illustrates how to add the combo box field to an existing {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-combobox-field-to-an-existing-PDF-document/.NET/Add-the-combobox-field-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -1024,10 +1117,8 @@ comboBoxField.Items.Add("Documentation."); //Add the field to the existing XFA form. loadedForm.Fields.Add(comboBoxField); -//Create memory stream. -MemoryStream stream = new MemoryStream(); //Save the document. -loadedDocument.Save(stream); +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -1035,6 +1126,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -1060,6 +1154,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -1095,6 +1192,9 @@ The below code snippet illustrates how to add a list box field to a new PDF docu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-listbox-field-to-a-new-PDF-document/.NET/Add-the-XFA-listbox-field-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -1117,10 +1217,8 @@ mainForm.Fields.Add(listBoxField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); //Save the document. -document.Save(stream, PdfXfaType.Dynamic); +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -1128,6 +1226,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -1159,6 +1260,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -1198,10 +1301,11 @@ The below code snippet illustrates how to add the list box field to an existing {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-listbox-field-to-an-existing-PDF-document/.NET/Add-the-XFA-listbox-field-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -1218,10 +1322,8 @@ listBoxField.Items.Add("German"); //Add the field to the existing XFA form. loadedForm.Fields.Add(listBoxField); -//Create memory stream. -MemoryStream stream = new MemoryStream(); //Save the document. -loadedDocument.Save(stream); +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -1229,6 +1331,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -1256,6 +1361,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -1293,6 +1401,9 @@ The below code snippet illustrates how to add a check box field to a new PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-checkbox-field-to-a-new-PDF-document/.NET/Add-the-XFA-checkbox-field-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -1310,10 +1421,8 @@ mainForm.Fields.Add(checkBoxField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); //Save the document. -document.Save(stream, PdfXfaType.Dynamic); +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -1321,6 +1430,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -1347,6 +1459,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -1381,10 +1495,11 @@ The below code snippet illustrates how to add the check box field to an existing {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-checkbox-field-to-an-existing-PDF-document/.NET/Add-the-XFA-checkbox-field-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -1396,10 +1511,8 @@ checkBoxField.CheckedStyle = PdfXfaCheckedStyle.Cross; //Add the field to the existing XFA form. loadedForm.Fields.Add(checkBoxField); -//Create memory stream. -MemoryStream stream = new MemoryStream(); //Save the document. -loadedDocument.Save(stream); +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -1407,6 +1520,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -1429,6 +1545,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -1461,6 +1580,9 @@ The below code snippet illustrates how to add a radio button field to a new PDF {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-radio-button-field-to-a-new-PDF-document/.NET/Add-the-XFA-radio-button-field-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -1486,10 +1608,8 @@ mainForm.Fields.Add(group); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); //Save the document. -document.Save(stream, PdfXfaType.Dynamic); +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -1497,6 +1617,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -1531,6 +1654,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -1573,10 +1698,11 @@ The below code snippet illustrates how to add the radio button field to an exist {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-radio-button-field-to-an-existing-PDF-document/.NET/Add-the-XFA-radio-button-field-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -1596,10 +1722,8 @@ group.Items.Add(radioButtonField2); //Add the field to the existing XFA form. loadedForm.Fields.Add(group); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -1607,6 +1731,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -1637,6 +1764,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -1677,6 +1807,9 @@ The below code snippet illustrates how to add a date time field to a new PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-datetime-field-in-a-new-PDF-document/.NET/Add-the-XFA-datetime-field-in-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -1695,17 +1828,17 @@ mainForm.Fields.Add(dateTimeField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -1733,6 +1866,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -1768,10 +1903,11 @@ The below code snippet illustrates how to add the date time field to an existing {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-datetime-field-in-an-existing-PDF-document/.NET/Add-the-XFA-datetime-field-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -1784,10 +1920,8 @@ dateTimeField.ToolTip = "Date Time"; //Add the field to the existing XFA form. loadedForm.Fields.Add(dateTimeField); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -1795,6 +1929,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -1818,6 +1955,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -1851,6 +1991,9 @@ The below code snippet illustrates how to add a button field to a new PDF docume {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-button-field-to-a-new-PDF-document/.NET/Add-the-XFA-button-field-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -1867,17 +2010,17 @@ mainForm.Fields.Add(buttonField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -1903,6 +2046,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -1936,10 +2081,11 @@ The below code snippet illustrates how to add the button field to an existing PD {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-button-field-to-an-existing-PDF-document/.NET/Add-the-XFA-button-field-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -1950,10 +2096,8 @@ buttonField.Content = "Click"; //Add the field to the existing XFA form. loadedForm.Fields.Add(buttonField); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -1961,6 +2105,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -1982,6 +2129,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -2013,6 +2163,9 @@ The below code snippet illustrates how to add a text element to a new PDF docume {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-text-element-to-a-new-PDF-document/.NET/Add-the-XFA-text-element-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -2029,10 +2182,8 @@ mainForm.Fields.Add(textElement); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -2040,6 +2191,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -2065,6 +2219,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -2098,10 +2254,11 @@ The below code snippet illustrates how to add a text element to an existing PDF {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-text-element-to-an-existing-PDF-document/.NET/Add-the-XFA-text-element-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -2112,10 +2269,8 @@ textElement.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle //Add the text element to the existing XFA form. loadedForm.Fields.Add(textElement); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -2123,6 +2278,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -2144,6 +2302,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -2175,6 +2336,9 @@ The below code snippet illustrates how to add the rectangle field to a new PDF d {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-rectangle-field-to-a-new-PDF-document/.NET/Add-the-XFA-rectangle-field-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -2191,17 +2355,17 @@ mainForm.Fields.Add(rectangle); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -2227,6 +2391,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -2260,10 +2426,11 @@ The below code snippet illustrates how to add the rectangle field to an existing {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-rectangle-field-to-an-existing-PDF-document/.NET/Add-the-XFA-rectangle-field-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -2274,10 +2441,8 @@ rectangle.Border.FillColor = new PdfXfaSolidBrush(Color.FromArgb(0,255,0,0)); //Add the rectangle to the existing XFA form. loadedForm.Fields.Add(rectangle); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -2285,6 +2450,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form @@ -2306,6 +2474,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -2337,6 +2508,9 @@ The below code snippet illustrates how to add the circle field to a new PDF docu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-circle-field-to-a-new-PDF-document/.NET/Add-the-XFA-circle-field-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -2353,17 +2527,17 @@ mainForm.Fields.Add(circle); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -2389,6 +2563,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -2422,10 +2598,11 @@ The below code snippet illustrates how to add the circle field to an existing PD {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-circle-field-to-an-existing-PDF-document/.NET/Add-circle-field-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -2436,10 +2613,8 @@ circle.Border.FillColor = new PdfXfaSolidBrush(Color.FromArgb(0,255,0,0)); //Add the circle to the existing XFA form. loadedForm.Fields.Add(circle); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -2447,6 +2622,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -2468,6 +2646,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -2499,6 +2680,9 @@ The below code snippet illustrates how to add a line to a new PDF document using {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-line-to-a-new-PDF-document/.NET/Add-the-XFA-line-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -2515,17 +2699,17 @@ mainForm.Fields.Add(line); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -2551,6 +2735,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -2584,10 +2770,11 @@ The below code snippet illustrates how to add a line to an existing PDF document {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-XFA-line-to-an-existing-PDF-document/.NET/Add-XFA-line-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -2598,10 +2785,8 @@ line.Color = new PdfColor(Color.FromArgb(0,255,0,0)); //Add the line to the existing XFA form. loadedForm.Fields.Add(line); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -2609,6 +2794,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm.pdf"); //Load the existing XFA form. @@ -2630,6 +2818,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm.pdf") 'Load the existing XFA form @@ -2661,6 +2852,9 @@ The below code snippet illustrates how to add an image to a new PDF document usi {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-image-to-a-new-PDF-document/.NET/Add-the-XFA-image-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -2677,17 +2871,17 @@ mainForm.Fields.Add(image); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream, PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); - {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add a new XFA page. @@ -2711,6 +2905,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add a new XFA page @@ -2742,24 +2938,23 @@ The below code snippet illustrates how to add an image to an existing PDF docume {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-XFA-image-to-an-existing-PDF-document/.NET/Add-the-XFA-image-to-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; //Load the image as stream. -MemoryStream imageStream = new MemoryStream(File.ReadAllBytes(imageFileName)); +MemoryStream imageStream = new MemoryStream(File.ReadAllBytes("Image.png")); //Create a image and add the properties. PdfXfaImage image = new PdfXfaImage("imgage1", imageStream); //Add the image to the existing XFA form. loadedForm.Fields.Add(image); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -2767,6 +2962,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. @@ -2786,6 +2984,9 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa + 'Load the existing XFA document Dim loadedDocument As New PdfLoadedXfaDocument("XfaForm1.pdf") 'Load the existing XFA form @@ -2822,6 +3023,9 @@ You can set the flow direction to an XFA form while creating, using [PdfXfaFlowD {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Set-the-horizontal-flow-direction-in-XFA-forms/.NET/Set-the-horizontal-flow-direction-in-XFA-forms/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -2846,10 +3050,8 @@ mainForm.Fields.Add(textBoxField1); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Add the field to the XFA form. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf", PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -2857,6 +3059,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -2890,6 +3095,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -2933,6 +3140,9 @@ You can set the flow direction to an XFA form while creating, using [PdfXfaFlowD {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Set-the-vertical-flow-direction-in-XFA-forms/.NET/Set-the-vertical-flow-direction-in-XFA-forms/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -2957,17 +3167,18 @@ mainForm.Fields.Add(textBoxField1); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} - + +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3001,6 +3212,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -3044,6 +3257,9 @@ You can rotate a form field in XFA document, using [PdfXfaRotateAngle](https://h {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Rotating-the-XFA-form-fields-in-a-PDF-document/.NET/Rotating-the-XFA-form-fields-in-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3064,10 +3280,8 @@ mainForm.Fields.Add(textBoxField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -3075,6 +3289,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3104,6 +3321,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -3143,6 +3362,9 @@ You can validate the date time fields of the input text by enabling the [Require {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Validating-the-XFA-datetime-field-in-a-PDF-document/.NET/Validating-the-XFA-datetime-field-in-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3163,10 +3385,8 @@ mainForm.Fields.Add(dateTimeField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -3174,6 +3394,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3203,6 +3426,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -3244,6 +3469,9 @@ Please refer the below link for numeric pattern format in detail, {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Customizing-the-XFA-numeric-field-in-a-PDF-document/.NET/Customizing-the-XFA-numeric-field-in-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3262,10 +3490,8 @@ mainForm.Fields.Add(numericField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -3273,6 +3499,9 @@ document.Close(); {% highlight c# tabtitle="C#" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3337,6 +3566,9 @@ You can add the nested sub forms by using [PdfXfaForm](https://help.syncfusion.c {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-XFA-nested-subforms-in-a-PDF-document/.NET/Add-XFA-nested-subforms-in-a-PDF-document/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3366,10 +3598,8 @@ mainForm.Fields.Add(form1); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -3377,6 +3607,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3415,6 +3648,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -3487,10 +3722,8 @@ mainForm.Fields.Add(textBoxField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -3498,6 +3731,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3525,6 +3761,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -3562,6 +3800,9 @@ You can add the vertical alignments in XFA form fields through [VerticalAlignmen {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-vertical-alignments-in-XFA-form-fields/.NET/Add-the-vertical-alignments-in-XFA-form-fields/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3580,10 +3821,8 @@ mainForm.Fields.Add(textBoxField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -3591,6 +3830,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3618,6 +3860,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -3655,6 +3899,9 @@ You can add margin to the XFA form fields by using [Margins](https://help.syncfu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Adding-margins-to-the-XFA-form-fields/.NET/Adding-margins-to-the-XFA-form-fields/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3674,10 +3921,8 @@ mainForm.Fields.Add(textBoxField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -3685,6 +3930,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3713,6 +3961,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -3751,6 +4001,9 @@ You can add padding to the XFA form fields by using [padding](https://help.syncf {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-the-padding-to-XFA-form-fields/.NET/Add-the-padding-to-XFA-form-fields/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3769,10 +4022,8 @@ mainForm.Fields.Add(textBoxField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -3780,6 +4031,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3807,6 +4061,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -3844,6 +4100,9 @@ You can add border to the XFA fields by using [Border](https://help.syncfusion.c {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Add-border-to-the-XFA-form-fields/.NET/Add-border-to-the-XFA-form-fields/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3863,10 +4122,8 @@ mainForm.Fields.Add(textBoxField); //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -3874,6 +4131,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -3902,6 +4162,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -3944,10 +4206,11 @@ Please refer the below sample for filling the XFA text box field using [PdfLoade {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Filling-the-XFA-textbox-field-in-an-existing-PDF-document/.NET/Filling-the-XFA-textbox-field-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -3956,10 +4219,8 @@ PdfLoadedXfaTextBoxField loadedTextBox = (loadedForm.Fields["subform1[0]"] as Pd //fill the text box. loadedTextBox.Text = "First Name"; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -3967,6 +4228,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -3986,6 +4250,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4015,10 +4281,11 @@ You can fill the XFA numeric field by using [PdfLoadedXfaNumericField](https://h {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Filling-the-XFA-numeric-field-in-an-existing-PDF-document/.NET/Filling-the-XFA-numeric-field-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -4027,10 +4294,8 @@ PdfLoadedXfaNumericField loadedNumericField = (loadedForm.Fields["subform1[0]"] //fill the numeric field. loadedNumericField.NumericValue = 945322; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4038,6 +4303,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -4057,6 +4325,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4086,10 +4356,11 @@ You can fill the XFA combo box field by using [PdfLoadedXfaComboBoxField](https: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Filling-the-XFA-combobox-field-in-an-existing-PDF-document/.NET/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -4098,10 +4369,8 @@ PdfLoadedXfaComboBoxField loadedComboBoxField = (loadedForm.Fields["subform1[0]" //Set the combo box selected index. loadedComboBoxField.SelectedIndex = 1; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4109,6 +4378,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -4128,6 +4400,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4155,10 +4429,11 @@ You can fill and save hidden items in XFA combo box field by using [HiddenItems] {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Fill-and-save-hidden-items-in-XFA-combobox-field/.NET/Fill-and-save-hidden-items-in-XFA-combobox-field/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -4170,10 +4445,8 @@ loadedComboBoxField.SelectedValue = loadedComboBoxField.HiddenItems[0]; List hiddenValues = new List(); hiddenValues = loadedComboBoxField.HiddenItems; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4181,6 +4454,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("Input.pdf"); //Load the existing XFA form. @@ -4203,6 +4479,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("Input.pdf") 'Load the existing XFA form @@ -4235,10 +4513,11 @@ You can fill the XFA list box field by using [PdfLoadedXfaListBoxField](https:// {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Fill-the-XFA-listbox-field-in-an-existing-PDF-document/.NET/Fill-the-XFA-listbox-field-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -4247,10 +4526,8 @@ PdfLoadedXfaListBoxField loadedListBoxField = (loadedForm.Fields["subform1[0]"] //Set the list box selected index. loadedListBoxField.SelectedIndex = 1; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4258,6 +4535,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -4277,6 +4557,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4304,10 +4586,11 @@ You can also select the multiple values by using [SelectedItems](https://help.sy {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Select-multiple-values-in-an-existing-XFA-listbox-field/.NET/Select-multiple-values-in-an-existing-XFA-listbox-field/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -4316,10 +4599,8 @@ PdfLoadedXfaListBoxField loadedListBoxField = (loadedForm.Fields["subform1[0]"] //Set the list box selected items. loadedListBoxField.SelectedItems = new string[] { "English", "Spanish" }; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4327,6 +4608,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -4346,6 +4630,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4375,10 +4661,11 @@ You can fill the XFA date time field by using [PdfLoadedXfaDateTimeField](https: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Fill-the-XFA-datetime-field-in-an-existing-PDF-document/.NET/Fill-the-XFA-datetime-field-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -4387,10 +4674,8 @@ PdfLoadedXfaDateTimeField loadedDateTimeField = (loadedForm.Fields["subform1[0]" //Set the value. loadedDateTimeField.Value = DateTime.Now; -//Save the document to memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Output.pdf"); //Close the document. loadedDocument.Close(); @@ -4398,6 +4683,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -4417,6 +4705,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4446,10 +4736,11 @@ You can fill the XFA check box field by using [PdfLoadedXfaCheckBoxField](https: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Fill-the-XFA-checkbox-field-in-an-existing-PDF-document/.NET/Fill-the-XFA-checkbox-field-in-an-existing-PDF-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -4458,10 +4749,8 @@ PdfLoadedXfaCheckBoxField loadedCheckBox = (loadedForm.Fields["subform1[0]"] as //Check the check box. loadedCheckBox.IsChecked = true; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4469,6 +4758,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -4488,6 +4780,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4517,10 +4811,11 @@ You can fill the XFA radio button field by using [PdfLoadedXfaRadioButtonField]( {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Fill-the-XFA-radiobutton-field-in-an-existing-PDF-document/.NET/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -4531,10 +4826,8 @@ PdfLoadedXfaRadioButtonField loadedRadioButtonField = loadedRadioButtonGroup.Fie //Check the radio button. loadedRadioButtonField.IsChecked = true; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4542,6 +4835,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -4563,6 +4859,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4596,6 +4894,9 @@ The below code snippet illustrates how to set the [ReadOnly](https://help.syncfu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Removing-editing-capability-of-form-fields-in-a-new-PDF/.NET/Removing-editing-capability-of-form-fields-in-a-new-PDF/Program.cs" %} +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -4614,10 +4915,8 @@ mainForm.ReadOnly = true; //Add the XFA form to the document. document.XfaForm = mainForm; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -document.Save(stream,PdfXfaType.Dynamic); +//Save the document. +document.Save("XfaForm.pdf",PdfXfaType.Dynamic); //Close the document. document.Close(); @@ -4625,6 +4924,9 @@ document.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Create a new PDF XFA document. PdfXfaDocument document = new PdfXfaDocument(); //Add new XFA page. @@ -4652,6 +4954,8 @@ document.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Create a new PDF XFA document Dim document As New PdfXfaDocument() 'Add new XFA page @@ -4687,19 +4991,18 @@ The below code snippet illustrates how to set the [ReadOnly](https://help.syncfu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Remove-editing-capability-to-an-existing-form-fields/.NET/Remove-editing-capability-to-an-existing-form-fields/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; //Set the form as read only. loadedForm.ReadOnly = true; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4707,6 +5010,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -4723,6 +5029,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4757,6 +5065,9 @@ The following code snippet illustrates how to flatten the XFA form field. {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing document. PdfLoadedXfaDocument ldoc = new PdfLoadedXfaDocument("input.pdf"); //Set flatten. @@ -4771,6 +5082,8 @@ ldoc.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing document Dim ldoc As New PdfLoadedXfaDocument("input.pdf") 'Set flatten @@ -4795,10 +5108,11 @@ You can remove the dynamic XFA form fields by using [Remove](https://help.syncfu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Removing-the-dynamic-form-fields-from-an-existing-PDF/.NET/Removing-the-dynamic-form-fields-from-an-existing-PDF/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -4807,10 +5121,8 @@ PdfLoadedXfaTextBoxField loadedText = (loadedForm.Fields["subform1[0]"] as PdfLo //Remove the field. loadedForm.Fields.Remove(loadedText); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4818,6 +5130,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -4837,6 +5152,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4866,10 +5183,11 @@ You can modify the existing dynamic XFA fields like Width, Height and Text by us {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Modidy-the-existing-fields-in-XFA-document/.NET/Modidy-the-existing-fields-in-XFA-document/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Load the existing XFA form. PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; @@ -4881,10 +5199,8 @@ loadedText.Height = 30; //Set the caption text. loadedText.Caption.Text = "Second Name"; -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4892,6 +5208,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing PDF document. PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("input.pdf"); //Load the existing XFA form. @@ -4914,6 +5233,8 @@ loadedDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa 'Load the existing PDF document Dim loadedDocument As New PdfLoadedXfaDocument("input.pdf") 'Load the existing XFA form @@ -4948,19 +5269,18 @@ The following sample illustrates how to clear the date time field in an existing {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/XFA/Clear-XFA-datetime-field-value-in-an-existing-XFA-document/.NET/Program.cs" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); +using Syncfusion.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA document. -PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(docStream); +PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument("XfaForm1.pdf"); //Get the date time field. PdfLoadedXfaDateTimeField dateTimeField = loadedDocument.XfaForm.TryGetFieldByCompleteName("form[0].subform[0].dateTime[0]") as PdfLoadedXfaDateTimeField; //Clear the date time field value. dateTimeField.ClearValue(); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document to memory stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("XfaForm.pdf"); //Close the document. loadedDocument.Close(); @@ -4968,6 +5288,9 @@ loadedDocument.Close(); {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.Pdf.Xfa; + //Load the existing XFA PDF document. PdfLoadedXfaDocument loadedXfaDocument = new PdfLoadedXfaDocument("input.pdf"); //Get the date time field. @@ -4983,7 +5306,8 @@ loadedXfaDocument.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the existing XFA PDF document +Imports System.Drawing +Imports Syncfusion.Pdf.Xfa'Load the existing XFA PDF document Dim loadedXfaDocument As PdfLoadedXfaDocument = New PdfLoadedXfaDocument("input.pdf") 'Get the date time field Dim dateTimeField As PdfLoadedXfaDateTimeField = TryCast(loadedXfaDocument.XfaForm.TryGetFieldByCompleteName("form[0].subform[0].dateTime[0]"), PdfLoadedXfaDateTimeField) diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-ZUGFeRD-invoice.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-ZUGFeRD-invoice.md index 8be1a1b8e..d0746ee48 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-ZUGFeRD-invoice.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-ZUGFeRD-invoice.md @@ -162,6 +162,9 @@ Using **PDF/A-3b** conformance, you can create a **ZUGFeRD invoice PDF** by spec {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/ZUGFeRD/Factur-X/.NET/Factur-X/Program.cs" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf; + //Create a new PDF document PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3B); @@ -184,17 +187,18 @@ attachment.MimeType = "text/xml"; //Add attachment to PDF document document.Attachments.Add(attachment); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; +//Save the document +document.Save("Output.pdf"); //Closes the document -document.Close(true); +document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf; + //Create a new PDF document PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3B); @@ -226,6 +230,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf + ' Create a new PDF document Dim document As New PdfDocument(PdfConformanceLevel.Pdf_A3B) @@ -266,6 +273,9 @@ The complete code to create ZUGFeRD invoice PDF document as follows. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/ZUGFeRD/Create-ZUGFeRD-compliment-PDF-invoice/.NET/Create-ZUGFeRD-compliment-PDF-invoice/Program.cs" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf; + //Create ZUGFeRD invoice PDF document PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3B); //Set ZUGFeRD conformance level @@ -281,25 +291,18 @@ attachment.MimeType = "application/xml"; //Add attachment to PDF document document.Attachments.Add(attachment); -//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 -document.Close(true); -//Defining the ContentType for PDF file -string contentType = "application/pdf"; -//Define the file name -string fileName = "Zugferd.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("Output.pdf"); +//Closes the document +document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf; + //Create ZUGFeRD invoice PDF document PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3B); //Set ZUGFeRD conformance level @@ -323,6 +326,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf + 'Create ZUGFeRD invoice PDF document Dim document As PdfDocument = New PdfDocument(PdfConformanceLevel.Pdf_A3B) 'Set ZUGFeRD conformance level @@ -356,28 +362,32 @@ You can extract the ZUGFeRD invoice using [PdfAttachment](https://help.syncfusio {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/ZUGFeRD/Extract-ZUGFeRD-invoice-from-PDF-document/.NET/Extract-ZUGFeRD-invoice-from-PDF-document/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.Interactive; +using Syncfusion.Pdf.Parsing; -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +//Loads the PDF document +PdfLoadedDocument document = new PdfLoadedDocument("Sample.pdf"); -//Iterates the attachments. -foreach (PdfAttachment attachment in loadedDocument.Attachments) +//Iterates the attachments +foreach (PdfAttachment attachment in document.Attachments) { - //Extracts the ZUGFeRD invoice attachment and saves it to the disk. - FileStream s = new FileStream("Output/" + attachment.FileName, FileMode.Create, FileAccess.Write); - s.Write(attachment.Data, 0, attachment.Data.Length); - s.Dispose(); +//Extracts the ZUGFeRD invoice attachment and saves it to the disk +FileStream s = new FileStream(attachment.FileName, FileMode.Create); +s.Write(attachment.Data, 0, attachment.Data.Length); +s.Dispose(); } -//Close the PDF document. -loadedDocument.Close(true); +//Saves and closes the document +document.Save("Output.pdf"); +document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Loads the PDF document PdfLoadedDocument document = new PdfLoadedDocument("Sample.pdf"); @@ -398,6 +408,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Loads the PDF document Dim document As New PdfLoadedDocument("Sample.pdf") diff --git a/Document-Processing/PDF/PDF-Library/NET/Working-with-forms.md b/Document-Processing/PDF/PDF-Library/NET/Working-with-forms.md index cb5da10af..8f6961431 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Working-with-forms.md +++ b/Document-Processing/PDF/PDF-Library/NET/Working-with-forms.md @@ -26,6 +26,11 @@ The below code snippet illustrates how to add a textbox field to a new PDF docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-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 new page to the PDF document. @@ -38,10 +43,8 @@ textBoxField.ToolTip = "First Name"; //Add the form field to the document. document.Form.Fields.Add(textBoxField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -49,6 +52,11 @@ document.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 document = new PdfDocument(); //Add a new page to the PDF document. @@ -70,7 +78,12 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create a new PDF document. +Imports Syncfusion.Drawing +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As PdfDocument = New PdfDocument() 'Add a new page to the PDF document. Dim page As PdfPage = document.Pages.Add() @@ -99,9 +112,12 @@ The below code snippet illustrates how to add the textbox to an existing PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Add-the-textbox-to-an-existing-PDF-document/.NET/Add-the-textbox-to-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Create the form if the form does not exist in the loaded document. if (loadedDocument.Form == null) loadedDocument.CreateForm(); @@ -115,10 +131,8 @@ textBoxField.ToolTip = "First Name"; //Add the form field to the existing PDF document. loadedDocument.Form.Fields.Add(textBoxField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Form.pdf"); //Close the document. loadedDocument.Close(true); @@ -126,8 +140,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create the form if the form does not exist in the loaded document. if(loadedDocument.Form==null) loadedDocument.CreateForm(); @@ -150,8 +168,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the existing PDF document -Dim loadedDocument As New PdfLoadedDocument(fileName) +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Create the form if the form does not exist in the loaded document If loadedDocument.Form Is Nothing Then loadedDocument.CreateForm() @@ -187,6 +209,9 @@ Please refer the below code snippet for adding the combo box in new PDF document {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Adding-combo-box-in-the-new-PDF-document/.NET/Adding-combo-box-in-the-new-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -205,10 +230,8 @@ comboBoxField.Items.Add(new PdfListFieldItem("Documentation", "content")); //Add combo box to the form. document.Form.Fields.Add(comboBoxField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -216,6 +239,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -242,8 +268,11 @@ document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - -'Create a new PDF document + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to PDF document Dim page As PdfPage = document.Pages.Add() @@ -278,9 +307,12 @@ Please refer the below code snippet for adding the combo box in existing PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Adding-the-combo-box-in-existing-PDF-document/.NET/Adding-the-combo-box-in-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Create the form if the form does not exist in the loaded document. if (loadedDocument.Form == null) loadedDocument.CreateForm(); @@ -300,10 +332,8 @@ comboBoxField.Items.Add(new PdfListFieldItem("Documentation", "content")); //Add combo box to the form. loadedDocument.Form.Fields.Add(comboBoxField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Form.pdf"); //Close the document. loadedDocument.Close(true); @@ -311,8 +341,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create the form if the form does not exist in the loaded document. if(loadedDocument.Form==null) loadedDocument.CreateForm(); @@ -341,8 +375,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the existing PDF document -Dim loadedDocument As New PdfLoadedDocument(fileName) +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Create the form if the form does not exist in the loaded document If loadedDocument.Form Is Nothing Then loadedDocument.CreateForm() @@ -382,29 +420,28 @@ Use the [TextAlignment](https://help.syncfusion.com/cr/document-processing/Syncf {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Annotation/Set-text-alignment-in-a-Combo-Box-field/.NET/Set-text-alignment-in-a-Combo-Box-field/Program.cs" %} - // Load an existing document from a file stream. - using (FileStream fileStream = new FileStream("SourceForm.pdf", FileMode.Open, FileAccess.Read)) - { - PdfLoadedDocument doc = new PdfLoadedDocument(fileStream); - // Load an existing combo box field by its name. - PdfLoadedComboBoxField comboField = doc.Form.Fields["EmployeeCombo"] as PdfLoadedComboBoxField; - // Set text alignment to center for the combo box field. - comboField.TextAlignment = PdfTextAlignment.Center; - - // Save the updated document to a file stream. - using (FileStream outputStream = new FileStream("Form.pdf", FileMode.Create, FileAccess.Write)) - { - doc.Save(outputStream); - } + using Syncfusion.Pdf; + using Syncfusion.Pdf.Interactive; + using Syncfusion.Pdf.Parsing; - // Close the document. - doc.Close(true); - } + // Load an existing document. + PdfLoadedDocument doc = new PdfLoadedDocument("SourceForm.pdf"); + // Load an existing combo box field by its name. + PdfLoadedComboBoxField comboField = doc.Form.Fields["EmployeeCombo"] as PdfLoadedComboBoxField; + // Set text alignment to center for the combo box field. + comboField.TextAlignment = PdfTextAlignment.Center; + // Save the updated document. + doc.Save("Form.pdf"); + doc.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} + using Syncfusion.Pdf; + using Syncfusion.Pdf.Interactive; + using Syncfusion.Pdf.Parsing; + // Load an existing document. PdfLoadedDocument doc = new PdfLoadedDocument("SourceForm.pdf"); // Load an existing combo box field by its name. @@ -418,8 +455,11 @@ Use the [TextAlignment](https://help.syncfusion.com/cr/document-processing/Syncf {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - - ' Load an existing document. + + Imports Syncfusion.Pdf + Imports Syncfusion.Pdf.Interactive + + 'Load the PDF document. Dim doc As New PdfLoadedDocument("SourceForm.pdf") ' Load an existing combo box field by its name. Dim comboField As PdfLoadedComboBoxField = TryCast(doc.Form.Fields("EmployeeCombo"), PdfLoadedComboBoxField) @@ -445,6 +485,9 @@ Please refer the below code snippet for adding the radio button in new PDF docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Adding-radio-button-in-new-PDF-document/.NET/Adding-radio-button-in-new-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -463,16 +506,16 @@ radioButtonItem2.Bounds = new Syncfusion.Drawing.RectangleF(100, 170, 20, 20); employeesRadioList.Items.Add(radioButtonItem1); employeesRadioList.Items.Add(radioButtonItem2); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -document.Save(stream); +//Save the document. +document.Save("Form.pdf"); //Close the document. document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; //Create a new PDF document. PdfDocument document = new PdfDocument(); @@ -500,8 +543,11 @@ document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - -'Create a new PDF document. + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to PDF document. Dim page As PdfPage = document.Pages.Add() @@ -536,9 +582,12 @@ The below code snippet illustrates how to add the radio button in existing PDF d {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Add-radio-button-in-existing-PDF-document/.NET/Add-radio-button-in-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Create the form if the form does not exist in the loaded document. if (loadedDocument.Form == null) loadedDocument.CreateForm(); @@ -558,10 +607,8 @@ radioButtonItem2.Bounds = new Syncfusion.Drawing.RectangleF(100, 170, 20, 20); employeesRadioList.Items.Add(radioButtonItem1); employeesRadioList.Items.Add(radioButtonItem2); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Form.pdf"); //Close the document. loadedDocument.Close(true); @@ -569,8 +616,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create the form if the form does not exist in the loaded document. if(loadedDocument.Form==null) loadedDocument.CreateForm(); @@ -599,8 +650,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the existing PDF document -Dim loadedDocument As New PdfLoadedDocument(fileName) +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Create the form if the form does not exist in the loaded document If loadedDocument.Form Is Nothing Then loadedDocument.CreateForm() @@ -640,6 +695,9 @@ You can choose default value for radio button field using [SelectedIndex](https: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/refs/heads/master/Forms/Default-value-for-radio-button-field/.NET/Default_Value_For_Radio_Button/Program.cs" %} + using Syncfusion.Pdf; + using Syncfusion.Pdf.Interactive; + // Create a new PDF document PdfDocument document = new PdfDocument(); // Add a new page to the PDF document @@ -672,16 +730,18 @@ You can choose default value for radio button field using [SelectedIndex](https: // Add the radio button list to the form document.Form.Fields.Add(employeesRadioList); - //Save the document into stream. - MemoryStream stream = new MemoryStream(); - document.Save(stream); - //Close the document. - document.Close(true); +//Save the document. +document.Save("Form.pdf"); +//Close the document. +document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} + using Syncfusion.Pdf; + using Syncfusion.Pdf.Interactive; + // Create a new PDF document PdfDocument document = new PdfDocument(); // Add a new page to the PDF document @@ -723,7 +783,10 @@ You can choose default value for radio button field using [SelectedIndex](https: {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - ' Create a new PDF document + Imports Syncfusion.Pdf + Imports Syncfusion.Pdf.Interactive + + 'Load the PDF document. Dim document As New PdfDocument() ' Add a new page to the PDF document Dim page As PdfPage = document.Pages.Add() @@ -777,6 +840,9 @@ Please refer the below code snippet for adding the list box field in new PDF doc {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Add-listbox-field-in-new-PDF-document/.NET/Add-listbox-field-in-new-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -797,10 +863,8 @@ listBoxField.MultiSelect = true; //Add the list box into PDF document. document.Form.Fields.Add(listBoxField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -document.Save(stream); +//Save the document. +document.Save("Form.pdf"); //Close the document. document.Close(true); @@ -808,6 +872,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -836,8 +903,11 @@ document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - -'Create a new PDF document. + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to PDF document. Dim page As PdfPage = document.Pages.Add() @@ -874,9 +944,12 @@ Please refer the below code snippet for adding the list box field in existing PD {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Add-listbox-field-in-an-existing-PDF-document/.NET/Add-listbox-field-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Create the form if the form does not exist in the loaded document. if (loadedDocument.Form == null) loadedDocument.CreateForm(); @@ -898,10 +971,8 @@ listBoxField.MultiSelect = true; //Add the list box into PDF document. loadedDocument.Form.Fields.Add(listBoxField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Form.pdf"); //Close the document. loadedDocument.Close(true); @@ -909,8 +980,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create the form if the form does not exist in the loaded document. if(loadedDocument.Form==null) loadedDocument.CreateForm(); @@ -941,8 +1016,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the existing PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Create the form if the form does not exist in the loaded document. If loadedDocument.Form Is Nothing Then loadedDocument.CreateForm() @@ -986,6 +1065,9 @@ Please refer the below code snippet for adding the check box field in new PDF do {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Add-checkbox-field-in-new-PDF-document/.NET/Add-checkbox-field-in-new-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -999,10 +1081,8 @@ checkBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 20, 10, 10); //Add the form field to the document. document.Form.Fields.Add(checkBoxField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -document.Save(stream); +//Save the document. +document.Save("Form.pdf"); //Close the document. document.Close(true); @@ -1010,6 +1090,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -1031,8 +1114,11 @@ document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - -'Create a new PDF document. + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to PDF document. Dim page As PdfPage = document.Pages.Add() @@ -1062,8 +1148,12 @@ Please refer the below code snippet for adding the check box field in existing P {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Adding-checkbox-field-in-an-existing-PDF-document/.NET/Adding-checkbox-field-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create the form if the form does not exist in the loaded document. if(loadedDocument.Form==null) loadedDocument.CreateForm(); @@ -1087,35 +1177,41 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} -'Load the existing PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) -'Create the form if the form does not exist in the loaded document. -If loadedDocument.Form Is Nothing Then -loadedDocument.CreateForm() -End If -'Load the page. -Dim loadedPage As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage) +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; -'Create Check Box field. -Dim checkBoxField As New PdfCheckBoxField(loadedPage, "CheckBox") -'Set check box properties. -checkBoxField.ToolTip = "Check Box" -checkBoxField.Bounds = New RectangleF(0, 20, 10, 10) -'Add the form field to the existing document. -loadedDocument.Form.Fields.Add(checkBoxField) +//Load the existing PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); +//Create the form if the form does not exist in the loaded document. +if(loadedDocument.Form==null) + loadedDocument.CreateForm(); +//Load the page. +PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -'Save the document. -loadedDocument.Save("Form.pdf") -'close the document. -loadedDocument.Close(True) +//Create Check Box field. +PdfCheckBoxField checkBoxField = new PdfCheckBoxField(loadedPage, "CheckBox"); +//Set check box properties. +checkBoxField.ToolTip = "Check Box"; +checkBoxField.Bounds = new RectangleF(0, 20, 10, 10); +//Add the form field to the existing document. +loadedDocument.Form.Fields.Add(checkBoxField); + +//Save the document. +loadedDocument.Save("Form.pdf"); +//Close the document. +loadedDocument.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -//Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create the form if the form does not exist in the loaded document. if (loadedDocument.Form == null) loadedDocument.CreateForm(); @@ -1130,10 +1226,8 @@ checkBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 20, 10, 10); //Add the form field to the existing document. loadedDocument.Form.Fields.Add(checkBoxField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Form.pdf"); //Close the document. loadedDocument.Close(true); @@ -1153,6 +1247,9 @@ Please refer the below code snippet for adding the signature field in new PDF do {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Add-signature-field-in-a-new-PDF-document/.NET/Add-signature-field-in-a-new-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -1166,10 +1263,8 @@ signatureField.ToolTip = "Signature"; //Add the form field to the document. document.Form.Fields.Add(signatureField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -document.Save(stream); +//Save the document. +document.Save("Form.pdf"); //Close the document. document.Close(true); @@ -1177,6 +1272,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -1199,7 +1297,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create a new PDF document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to PDF document. Dim page As PdfPage = document.Pages.Add() @@ -1229,9 +1330,12 @@ Please refer the below code snippet for adding the signature field in existing P {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Adding-the-signatre-field-in-existing-PDF-document/.NET/Adding-the-signatre-field-in-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Create the form if the form does not exist in the loaded document. if (loadedDocument.Form == null) loadedDocument.CreateForm(); @@ -1246,10 +1350,8 @@ signatureField.ToolTip = "Signature"; //Add the form field to the existing document. loadedDocument.Form.Fields.Add(signatureField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Form.pdf"); //Close the document. loadedDocument.Close(true); @@ -1257,8 +1359,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create the form if the form does not exist in the loaded document. if(loadedDocument.Form==null) loadedDocument.CreateForm(); @@ -1282,8 +1388,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the existing PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Create the form if the form does not exist in the loaded document. If loadedDocument.Form Is Nothing Then loadedDocument.CreateForm() @@ -1318,6 +1428,9 @@ The signedDate parameter in the [PdfSignature](https://help.syncfusion.com/cr/do {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Digital%20Signature/Customize-the-signed-date/.NET/Customize-the-signed-date/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Creates a new PDF document. PdfDocument document = new PdfDocument(); //Adds a new page. @@ -1327,9 +1440,8 @@ PdfSignature signature = new PdfSignature(page, "Signature", new DateTime(2020, signature.TimeStampServer = new TimeStampServer(new Uri("http://timestamp.digicert.com")); signature.SignedName = "Test"; signature.Bounds = new RectangleF(new PointF(0, 0), new SizeF(200, 100)); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the document. +document.Save("Form.pdf"); //Close the document. document.Close(true); @@ -1337,6 +1449,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Creates a new PDF document. PdfDocument document = new PdfDocument(); //Adds a new page. @@ -1354,8 +1469,11 @@ document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - -'Creates a new PDF document. + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Adds a new page. Dim page As PdfPage = document.Pages.Add() @@ -1385,6 +1503,9 @@ The below code illustrates how to add the button field in new PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Add-the-button-field-in-a-new-PDF-document/.NET/Add-the-button-field-in-a-new-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -1398,10 +1519,8 @@ buttonField.Text = "Click"; //Add the form field to the document. document.Form.Fields.Add(buttonField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -document.Save(stream); +//Save the document. +document.Save("Form.pdf"); //Close the document. document.Close(true); @@ -1409,6 +1528,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -1430,8 +1552,11 @@ document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - -'Create a new PDF document. + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to PDF document. Dim page As PdfPage = document.Pages.Add() @@ -1461,9 +1586,12 @@ Please refer the below code snippet for adding the button field in existing PDF {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Adding-button-field-in-an-existing-PDF-document/.NET/Adding-button-field-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Create the form if the form does not exist in the loaded document. if (loadedDocument.Form == null) loadedDocument.CreateForm(); @@ -1477,10 +1605,8 @@ buttonField.Text = "Click"; //Add the form field to the existing document. loadedDocument.Form.Fields.Add(buttonField); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the PDF document to stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Form.pdf"); //Close the document. loadedDocument.Close(true); @@ -1488,8 +1614,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Create the form if the form does not exist in the loaded document. if (loadedDocument.Form == null) loadedDocument.CreateForm(); @@ -1510,10 +1640,14 @@ loadedDocument.Close(true); {% endhighlight %} -{% highlight c# tabtitle="C# [Windows-specific]" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing -'Load the existing PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Create the form if the form does not exist in the loaded document. If loadedDocument.Form Is Nothing Then loadedDocument.CreateForm() @@ -1547,6 +1681,9 @@ You can add a complex script language text in PDF AcroForm fields by using the [ {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new PDF page. @@ -1570,16 +1707,18 @@ document.Form.Fields.Add(textField); //Set default appearance as false. document.Form.SetDefaultAppearance(false); -//Save the PDF document. -MemoryStream stream = new MemoryStream(); -document.Save(stream); -//Close the PDF document. +//Save the document. +document.Save("Form.pdf"); +//Close the document. document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new PDF page. @@ -1611,7 +1750,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create a new PDF document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new PDF page. Dim page As PdfPage = document.Pages.Add() @@ -1657,6 +1799,9 @@ The following code example illustrates how to add complex script support for all {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new PDF page. @@ -1680,16 +1825,18 @@ document.Form.SetDefaultAppearance(false); //Enable complex script layout for form. document.Form.ComplexScript = true; -//Save the PDF document. -MemoryStream stream = new MemoryStream(); -document.Save(stream); -//Close the PDF document. +//Save the document. +document.Save("Form.pdf"); +//Close the document. document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new PDF page. @@ -1721,7 +1868,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create a new PDF document +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new PDF page Dim page As PdfPage = document.Pages.Add() @@ -1758,9 +1909,11 @@ You can also flatten the existing form fields with complex script layout by usin {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Flatten-the-existing-form-fields-with-complex-script/.NET/Flatten-the-existing-form-fields-with-complex-script/Program.cs" %} -//Load the existing PDF document. -FileStream inputFileStream = new FileStream("Form.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; +//Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the existing PDF form. PdfLoadedForm lForm = loadedDocument.Form as PdfLoadedForm; //Set the complex script layout. @@ -1768,10 +1921,8 @@ lForm.ComplexScript = true; //Set flatten. lForm.Flatten = true; -//Create memory stream. -MemoryStream stream = new MemoryStream(); //Save the document. -loadedDocument.Save(stream); +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -1779,6 +1930,10 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Form.pdf"); //Get the existing PDF form. @@ -1797,7 +1952,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the existing PDF document +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Form.pdf") 'Get the existing PDF form Dim lForm As PdfLoadedForm = TryCast(loadedDocument.Form, PdfLoadedForm) @@ -1835,9 +1994,12 @@ You can fill a text box field using [Text](https://help.syncfusion.com/cr/docume {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Filling-the-textbox-field-in-an-existing-PDF-document/.NET/Filling-the-textbox-field-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -1845,9 +2007,8 @@ PdfLoadedForm loadedForm = loadedDocument.Form; PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; loadedTextBoxField.Text = "First Name"; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -1855,8 +2016,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -1873,8 +2038,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form @@ -1901,9 +2070,12 @@ You can fill a combo box field using [SelectedValue](https://help.syncfusion.com {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Fill-the-combobox-field-in-an-existing-PDF-document/.NET/Fill-the-combobox-field-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -1912,9 +2084,8 @@ PdfLoadedComboBoxField loadedComboboxField = loadedForm.Fields[1] as PdfLoadedCo //Select the item. loadedComboboxField.SelectedIndex = 1; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -1922,8 +2093,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -1941,8 +2116,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form @@ -1970,9 +2149,12 @@ You can fill a radio button field using [SelectedValue](https://help.syncfusion. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Fill-radio-button-field-in-an-existing-PDF-document/.NET/Fill-radio-button-field-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -1981,9 +2163,8 @@ PdfLoadedRadioButtonListField loadedRadioButtonField = loadedForm.Fields[3] as P //Select the item. loadedRadioButtonField.SelectedIndex = 1; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -1991,8 +2172,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2010,8 +2195,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form @@ -2039,9 +2228,12 @@ The below code snippet illustrates how to fill the list box field in an existing {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Fill-list-box-field-in-an-existing-PDF-document/.NET/Fill-list-box-field-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2050,9 +2242,8 @@ PdfLoadedListBoxField loadedListBox = loadedForm.Fields[2] as PdfLoadedListBoxFi //Fill list box and Modify the list box select index. loadedListBox.SelectedIndex = new int[2] { 1, 2 }; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -2060,8 +2251,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2079,8 +2274,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the existing PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form @@ -2108,9 +2307,12 @@ You can fill a check box field by enabling [Checked](https://help.syncfusion.com {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Fill-the-checkbox-field-in-an-existing-PDF-document/.NET/Fill-the-checkbox-field-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2121,9 +2323,8 @@ loadedCheckBoxField.Items[0].Checked = true; //Check the checkbox if it is not grouped. loadedCheckBoxField.Checked = true; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -2131,8 +2332,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2152,8 +2357,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form @@ -2183,9 +2392,12 @@ The below code snippet illustrates how to fill the signature field with certific {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Fill-the-signature-field-in-an-existing-PDF/.NET/Fill-the-signature-field-in-an-existing-PDF/Program.cs" %} +using Syncfusion.Pdf; +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"); PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2199,9 +2411,8 @@ loadedSignatureField.Signature = new PdfSignature(); loadedSignatureField.Signature.Certificate = certificate; loadedSignatureField.Signature.Reason = "Reason"; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -2209,8 +2420,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2232,8 +2447,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") Dim loadedPage As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage) 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form @@ -2269,9 +2488,12 @@ The following code snippet illustrates how to fill XFA forms via Acroform API. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Fill-the-XFA-forms-fields-via-acroform-API/.NET/Fill-the-XFA-forms-fields-via-acroform-API/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the existing Acroform. PdfLoadedForm acroform = loadedDocument.Form; //Enable XFA form filling. @@ -2285,10 +2507,8 @@ PdfLoadedTextBoxField lastName = acroform.Fields["LastName"] as PdfLoadedTextBox //Set text. lastName.Text = "Bistro"; -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("Form.pdf"); //Close the document. loadedDocument.Close(true); @@ -2296,6 +2516,10 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the existing XFA PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Form.pdf"); //Get the existing Acroform. @@ -2320,7 +2544,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the existing XFA PDF document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Form.pdf") 'Get the existing Acroform. Dim acroform As PdfLoadedForm = loadedDocument.Form @@ -2356,9 +2584,12 @@ The following code example illustrates this. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Enumarate-form-fields-in-a-PDF-document/.NET/Enumarate-form-fields-in-a-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm form = document.Form; @@ -2373,9 +2604,8 @@ for (int i = 0; i < fields.Count; i++) } } -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the document. +document.Save("Form.pdf"); //Close the document. document.Close(true); @@ -2383,8 +2613,12 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(fileName); +PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm form = document.Form; @@ -2407,8 +2641,12 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim document As New PdfLoadedDocument(fileName) +Dim document As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim form As PdfLoadedForm = document.Form @@ -2445,6 +2683,9 @@ By default, the value is set to true. This is illustrated in the following code {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Auto-naming-of-form-fields-in-a-PDF-document/.NET/Auto-naming-of-form-fields-in-a-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to the PDF document. @@ -2469,10 +2710,8 @@ textBoxField1.Text = "Doe"; //Add form field to the document. document.Form.Fields.Add(textBoxField1); -//Create memory stream. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -2480,6 +2719,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to the PDF document. @@ -2513,7 +2755,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create a new PDF document +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to the PDF document Dim page As PdfPage = document.Pages.Add() @@ -2563,9 +2809,12 @@ The following code snippet explains how to modify an existing form field in a PD {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Modify-the-existing-form-field-in-PDF-document/.NET/Modify-the-existing-form-field-in-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2577,9 +2826,8 @@ loadedTextBoxField.SpellCheck = true; loadedTextBoxField.Text = "New text of the field."; loadedTextBoxField.Password = false; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -2587,8 +2835,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2609,8 +2861,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form @@ -2643,9 +2899,12 @@ Please refer to the code example below to set the check box item. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Export_checkbox_values/.NET/Export_checkbox_values/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.Interactive; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2657,17 +2916,19 @@ PdfLoadedCheckBoxItem pdfLoadedCheckBoxItem = loadedCheckBoxField.Items[0] as Pd //Set the Export value pdfLoadedCheckBoxItem.ExportValue = "123"; -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document. +document.Save("Output.pdf"); +//Close the document. document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -2692,6 +2953,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") @@ -2724,9 +2989,12 @@ You can retrieve/modify the fore and background color of existing form fields in {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Modifying-fore-and-backcolor-of-existing-form-fields/.NET/Modifying-fore-and-backcolor-of-existing-form-fields/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2741,9 +3009,8 @@ PdfColor backColor = loadedTextBoxField.BackColor; //Set the background color. loadedTextBoxField.BackColor = new PdfColor(Color.Green); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -2751,8 +3018,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -2774,10 +3045,14 @@ loadedDocument.Close(true); {% endhighlight %} -{% highlight c# tabtitle="C# [Windows-specific]" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form Dim loadedForm As PdfLoadedForm = loadedDocument.Form @@ -2813,9 +3088,12 @@ The following code example illustrates how to get option values from acroform ra {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Get-option-value-from-acroform-radio-button/.NET/Get-option-value-from-acroform-radio-button/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument doc = new PdfLoadedDocument(docStream); +PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf"); //Gets the loaded form. PdfLoadedForm form = doc.Form; //Set default appearance to false. @@ -2833,9 +3111,8 @@ foreach (PdfLoadedRadioButtonItem item in radioButtonField.Items) } } -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -doc.Save(stream); +//Save the document. +doc.Save("Output.pdf"); //Close the document. doc.Close(true); @@ -2843,6 +3120,10 @@ doc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load an existing document. PdfLoadedDocument doc = new PdfLoadedDocument("SourceForm.pdf"); //Gets the loaded form. @@ -2870,7 +3151,11 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load an existing document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. Dim doc As New PdfLoadedDocument("SourceForm.pdf") 'Gets the loaded form. Dim form As PdfLoadedForm = doc.Form @@ -2907,9 +3192,12 @@ The following code snippet demonstrates how to retrieving an existing widget ann {% highlight c# tabtitle="C# [Cross-platform]" %} +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"); // Loop through each page in the loaded PDF document. foreach (PdfLoadedPage page in loadedDocument.Pages) { @@ -2942,6 +3230,10 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Loop through each page in the loaded PDF document. @@ -2976,7 +3268,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Load the PDF document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") ' Loop through each page in the loaded PDF document. @@ -3020,9 +3316,12 @@ Refer to the code snippet below to retrieve a custom value from a form field usi {% highlight c# tabtitle="C# [Cross-platform]" %} -// Load the PDF document using a file stream -FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read); - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the first page of the document PdfField field = loadedDocument.Form.Fields[0] as PdfField; @@ -3051,7 +3350,11 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} -// Load the PDF document using a file stream +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + +// Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Gets the first page of the document @@ -3082,7 +3385,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Load the PDF document +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") ' Get the first form field from the document @@ -3121,9 +3428,12 @@ The below code snippet explains how to get the field from collection using [TryG {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Get-the-field-from-collection-using-TryGetField/.NET/Get-the-field-from-collection-using-TryGetField/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument doc = new PdfLoadedDocument(docStream); +PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf"); //Load the form from the loaded document. PdfLoadedForm form = doc.Form; @@ -3136,9 +3446,8 @@ if (fieldCollection.TryGetField("f1-1", out loadedField)) (loadedField as PdfLoadedTextBoxField).Text = "1"; } -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -doc.Save(stream); +//Save the document. +doc.Save("Output.pdf"); //Close the document. doc.Close(true); @@ -3146,8 +3455,12 @@ doc.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the document. -PdfLoadedDocument doc = new PdfLoadedDocument(fileName); +PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf"); //Load the form from the loaded document. PdfLoadedForm form = doc.Form; @@ -3168,8 +3481,12 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Load the form from the loaded document. Dim form As PdfLoadedForm = loadedDocument.Form @@ -3201,9 +3518,12 @@ Please refer the below code snippet to get the field value from collection using {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Get-the-field-from-collection-using-TryGetValue/.NET/Get-the-field-from-collection-using-TryGetValue/Program.cs" %} +using Syncfusion.Pdf; +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 form from the loaded document. PdfLoadedForm form = loadedDocument.Form; @@ -3213,9 +3533,8 @@ string fieldValue = string.Empty; //Get the field value using TryGetValue Method. fieldCollection.TryGetValue("FirstName", out fieldValue); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -3223,8 +3542,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(filename); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the form from the loaded document. PdfLoadedForm form = loadedDocument.Form; @@ -3242,8 +3565,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load the document. -Dim loadedDocument As New PdfLoadedDocument(filename) +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Load the form from the loaded document. Dim form As PdfLoadedForm = loadedDocument.Form @@ -3273,11 +3600,12 @@ The below code illustrates get the pages of a form fields. {% highlight c# tabtitle="C# [Cross-platform]" %} -// Use the 'using' statement to automatically dispose of the FileStream when done. -using (FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read)) -{ + using Syncfusion.Pdf; + using Syncfusion.Pdf.Interactive; + using Syncfusion.Pdf.Parsing; + // Load the PDF document from the stream. - PdfLoadedDocument document = new PdfLoadedDocument(docStream); + PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); // Get all the form fields in the PDF. PdfLoadedForm loadedForm = document.Form; @@ -3306,12 +3634,15 @@ using (FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAcc // Close the PDF document. document.Close(true); -} {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + // Load the PDF document. PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf"); @@ -3347,7 +3678,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Load the PDF document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. Dim document As New PdfLoadedDocument("Input.pdf") ' Get all the form fields in the PDF. @@ -3389,9 +3724,12 @@ The below code illustrates how to remove the form fields from the existing PDF d {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Remove-the-form-fields-form-the-existing-PDF-document/.NET/Remove-the-form-fields-form-the-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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; //Get the loaded form. @@ -3403,9 +3741,8 @@ loadedForm.Fields.Remove(loadedTextBoxField); //Remove the field at index 0. loadedForm.Fields.RemoveAt(0); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -3413,8 +3750,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C#" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the page. PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Get the loaded form. @@ -3433,10 +3774,14 @@ loadedDocument.Close(true); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing -'Load the PDF document -Dim loadedDocument As New PdfLoadedDocument(fileName) +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Load the page Dim loadedPage As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage) 'Get the loaded form @@ -3469,6 +3814,9 @@ Please refer the sample for flattening the form fields in new PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Removing-editing-capability-of-form-fields/.NET/Removing-editing-capability-of-form-fields/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -3483,9 +3831,8 @@ document.Form.Flatten = true; //Add the form field to the document. document.Form.Fields.Add(textBoxField); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the document. +document.Save("Form.pdf"); //Close the document. document.Close(true); @@ -3493,6 +3840,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -3516,7 +3866,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create a new PDF document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to PDF document. Dim page As PdfPage = document.Pages.Add() @@ -3547,9 +3900,12 @@ Please refer the sample for flattening the form fields in existing PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Flattening-form-fields-in-an-existing-PDF-document/.NET/Flattening-form-fields-in-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; PdfLoadedFormFieldCollection fields = loadedForm.Fields; @@ -3559,9 +3915,8 @@ loadedTextBoxField.Text = "Text"; //Flatten the whole form. loadedForm.Flatten = true; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -3569,8 +3924,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm = loadedDocument.Form; PdfLoadedFormFieldCollection fields = loadedForm.Fields; @@ -3588,8 +3947,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form Dim fields As PdfLoadedFormFieldCollection = loadedForm.Fields @@ -3619,18 +3982,19 @@ Please refer the code sample to flatten the form fields before saving the PDF do {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Flattening-form-fields-in-an-existing-PDF-document/.NET/Flattening-form-fields-in-an-existing-PDF-document/Program.cs" %} -//Load an existing PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; //Flatten the form fields. loadedForm.FlattenFields(); -//Create memory stream. -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); @@ -3638,6 +4002,10 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load a PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf"); //Get the loaded form. @@ -3654,6 +4022,10 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. @@ -3681,6 +4053,9 @@ The below code snippet illustrates how to set the [ReadOnly](https://help.syncfu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Set-readonly-property-to-a-new-PDF-document/.NET/Set-readonly-property-to-a-new-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -3698,9 +4073,8 @@ textBoxField.Text = "john"; //Add the form field to the document. document.Form.Fields.Add(textBoxField); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the document. +document.Save("Form.pdf"); //Close the document. document.Close(true); @@ -3708,6 +4082,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -3734,7 +4111,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create a new PDF document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to PDF document. Dim page As PdfPage = document.Pages.Add() @@ -3768,17 +4148,19 @@ The below code snippet illustrates how to set the [ReadOnly](https://help.syncfu {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Set-the-ReadOnly-property-to-an-existing-PDF-document/.NET/Set-the-ReadOnly-property-to-an-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; //Set the form as read only. loadedForm.ReadOnly = true; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -3786,8 +4168,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; //Set the form as read only. @@ -3802,8 +4188,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form 'Set the form as read only. @@ -3833,17 +4223,18 @@ The below code illustrates how to import FDF file to PDF. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Importing-FDF-file-to-PDF-document/.NET/Importing-FDF-file-to-PDF-document/Program.cs" %} -//Get stream from an existing PDF document. -FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get stream from an existing PDF document. FileStream fdfStream = new FileStream("ImportFDF.fdf", FileMode.Open, FileAccess.Read); //Import the FDF stream. loadedDocument.Form.ImportDataFDF(fdfStream, true); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -3851,8 +4242,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load an existing document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load the existing form. PdfLoadedForm loadedForm = loadedDocument.Form; //Load the FDF file. @@ -3866,8 +4261,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load an existing document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Load the existing form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form 'Load the FDF file. @@ -3894,10 +4293,12 @@ The below code illustrates how to export FDF file from PDF document. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Export-FDF-file-from-PDF-document/.NET/Export-FDF-file-from-PDF-document/Program.cs" %} -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); -//Load the PDF document from stream. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + +//Load the PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load an existing form. PdfLoadedForm loadedForm = loadedDocument.Form; //Load the FDF file. @@ -3911,8 +4312,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C#" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load an existing document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Load an existing form. PdfLoadedForm loadedForm = loadedDocument.Form; //Export the existing PDF document to FDF file. @@ -3922,10 +4327,14 @@ loadedDocument.Close(true); {% endhighlight %} -{% highlight vb.net tabtitle="VB.NET" %} +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing -'Load an existing document -Dim loadedDocument As New PdfLoadedDocument(fileName) +'Load the PDF document. +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Load an existing form Dim loadedForm As PdfLoadedForm = loadedDocument.Form 'Export the existing PDF document to FDF file @@ -3947,6 +4356,9 @@ You can set the export value of the check box field in PDF forms using [PdfCheck {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a new page to the PDF document. @@ -3985,17 +4397,18 @@ checkBoxField2.BackColor = Color.YellowGreen; // Add to form form.Fields.Add(checkBoxField2); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document. +document.Save("Output.pdf"); +//Close the document. document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a new page to the PDF document. @@ -4043,7 +4456,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Create a new PDF document +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to the PDF document Dim page As PdfPage = document.Pages.Add() @@ -4102,6 +4518,9 @@ The following code example illustrates how to enable or disable unison functiona {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a new page to the PDF document. @@ -4136,17 +4555,18 @@ reportFrequencyRadioList.Items.Add(monthlyItem); // Add the radio button list field to the document's form fields document.Form.Fields.Add(reportFrequencyRadioList); -//Save the document into stream -MemoryStream stream = new MemoryStream(); -document.Save(stream); -stream.Position = 0; -//Closes the document +//Save the document. +document.Save("Output.pdf"); +//Close the document. document.Close(true); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a new page to the PDF document. @@ -4190,7 +4610,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Create a new PDF document +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to the PDF document Dim page As PdfPage = document.Pages.Add() @@ -4273,9 +4696,12 @@ The following code snippet explains how to set appearance to the PDF form fields {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Set-appearance-to-the-PDF-form-fields/.NET/Set-appearance-to-the-PDF-form-fields/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; //Set the default appearance. @@ -4285,9 +4711,8 @@ loadedForm.SetDefaultAppearance(false); PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; loadedTextBoxField.Text ="text"; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -4295,8 +4720,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; //Set the default appearance. @@ -4315,8 +4744,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form 'Set the default appearance. @@ -4371,6 +4804,9 @@ The following code snippet explains how to set the visibility of form fields in {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Creates a new page of the document. @@ -4387,10 +4823,8 @@ firstNameTextBox.Visibility = PdfFormFieldVisibility.Visible; page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55); //Add the textbox in document. document.Form.Fields.Add(firstNameTextBox); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -4398,6 +4832,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Creates a new page of the document. @@ -4414,10 +4851,8 @@ firstNameTextBox.Visibility = PdfFormFieldVisibility.Visible; page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55); //Add the textbox in document. document.Form.Fields.Add(firstNameTextBox); -//Creating the stream object. -MemoryStream stream = new MemoryStream(); -//Save the document as stream. -document.Save(stream); +//Save the document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -4425,7 +4860,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create a new PDF document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Creates a new page and adds it as the last page of the document. Dim page As PdfPage = document.Pages.Add() @@ -4441,10 +4879,9 @@ firstNameTextBox.Visibility = PdfFormFieldVisibility.Visible page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55) 'Add the textbox in document. document.Form.Fields.Add(firstNameTextBox) -'Creating the stream object. -Dim stream As New MemoryStream() -'Save the document as stream. -document.Save(stream) + +'Save the document. +document.Save("Output.pdf") 'Close the document. document.Close(True) @@ -4464,11 +4901,12 @@ The following code example demonstrates how to modify these indicator colors pro {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Customize-indicator-colors/.NET/Customize-indicator-colors/Program.cs" %} -// Open the input PDF file stream. -using (FileStream fileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read)) -{ + using Syncfusion.Pdf; + using Syncfusion.Pdf.Interactive; + using Syncfusion.Pdf.Parsing; + // Load the PDF document from the input stream. - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream); + PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); // Access the existing form fields in the PDF. PdfLoadedForm form = loadedDocument.Form; @@ -4492,20 +4930,20 @@ using (FileStream fileStream = new FileStream("Input.pdf", FileMode.Open, FileAc } // Disable the default appearance to allow custom rendering of form fields. form.SetDefaultAppearance(false); - // Create the output file stream. - using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite)) - { - // Save the modified PDF document to the new file stream. - loadedDocument.Save(outputFileStream); - } + + // Save the modified 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; + // Load the PDF document from the input PDF file. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); @@ -4541,7 +4979,11 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -' Load the PDF document from the input PDF file. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. Dim loadedDocument As New PdfLoadedDocument("Input.pdf") ' Access the form fields in the loaded PDF document. @@ -4585,9 +5027,12 @@ The following code illustrates how to set [AutoResizeText](https://help.syncfusi {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Auto-resize-the-text-of-textboxfield-in-a-PDF/.NET/Auto-resize-the-text-of-textboxfield-in-a-PDF/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -4598,9 +5043,8 @@ loadedField.AutoResizeText = true; //Flatten the form. form.Flatten = true; -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -4608,6 +5052,10 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load an existing document. PdfLoadedDocument doc = new PdfLoadedDocument("SourceForm.pdf"); //Read the text box field. @@ -4629,7 +5077,11 @@ doc.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Load an existing document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + +'Load the PDF document. Dim doc As PdfLoadedDocument = New PdfLoadedDocument("SourceForm.pdf") Dim form As PdfLoadedForm = doc.Form @@ -4663,6 +5115,9 @@ The below code illustrates how to enable the default appearance in new PDF docum {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Enable-default-appearance-in-new-PDF-document/.NET/Enable-default-appearance-in-new-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -4677,9 +5132,8 @@ document.Form.Fields.Add(textBoxField); //Enable the default Appearance. document.Form.SetDefaultAppearance(false); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -document.Save(stream); +//Save the document. +document.Save("Form.pdf"); //Close the document. document.Close(true); @@ -4687,6 +5141,9 @@ document.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; + //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a new page to PDF document. @@ -4710,7 +5167,10 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} -'Create a new PDF document. +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive + +'Load the PDF document. Dim document As New PdfDocument() 'Add a new page to PDF document. Dim page As PdfPage = document.Pages.Add() @@ -4741,9 +5201,12 @@ The below code illustrates how to enable the default appearance in existing PDF {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Forms/Enable-default-appearance-in-existing-PDF-document/.NET/Enable-default-appearance-in-existing-PDF-document/Program.cs" %} +using Syncfusion.Pdf; +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"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -4753,9 +5216,8 @@ loadedTextBoxField.Text = "First Name"; //Enable the default Appearance. loadedDocument.Form.SetDefaultAppearance(false); -//Save the document into stream. -MemoryStream stream = new MemoryStream(); -loadedDocument.Save(stream); +//Save the document. +loadedDocument.Save("flatten.pdf"); //Close the document. loadedDocument.Close(true); @@ -4763,8 +5225,12 @@ loadedDocument.Close(true); {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Pdf; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; + //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); //Get the loaded form. PdfLoadedForm loadedForm = loadedDocument.Form; @@ -4783,8 +5249,12 @@ loadedDocument.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.Pdf +Imports Syncfusion.Pdf.Interactive +Imports Syncfusion.Pdf.Parsing + 'Load the PDF document. -Dim loadedDocument As New PdfLoadedDocument(fileName) +Dim loadedDocument As New PdfLoadedDocument("Input.pdf") 'Get the loaded form. Dim loadedForm As PdfLoadedForm = loadedDocument.Form