diff --git a/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/Program.cs b/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/Program.cs
index ad2d230d..d590e1d7 100644
--- a/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/Program.cs
+++ b/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/Program.cs
@@ -4,21 +4,19 @@
using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;
-//Load the PDF document.
+//Load the PDF document
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
{
-
//Get the first page of the PDF document
PdfPageBase loadedPage = loadedDocument.Pages[0];
//Create a new popup annotation
- PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(100, 100, 20, 20), "Comment");
+ PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(100, 100, 20, 20), "popup annotation");
//Set the icon for the popup annotation
popupAnnotation.Icon = PdfPopupIcon.Comment;
//Set the color for the popup annotation
popupAnnotation.Color = new PdfColor(Color.Yellow);
//Add the annotation to the page
loadedPage.Annotations.Add(popupAnnotation);
-
//Save the PDF document
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
-}
+}
\ No newline at end of file
diff --git a/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/README.md b/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/README.md
index ae4a404b..521a80bd 100644
--- a/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/README.md
+++ b/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/README.md
@@ -1,6 +1,6 @@
# PDF Annotations
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) provides powerful tools to create, read, and edit PDF documents. This library also includes features to add, edit, and manage annotations in PDF files, enabling effective markup and collaboration.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) provides powerful tools to create, read, and edit PDF documents. This library also includes features to add, edit, and manage annotations in PDF files, enabling effective markup and collaboration.
## Steps to add annotations to a PDF
@@ -12,43 +12,34 @@ Step 2. **Install NuGet package**: Add the [Syncfusion.Pdf.Net.Core](https://www
Step 3. **Include necessary namespaces**: Add the following namespaces to your `Program.cs` file:
- ```csharp
- using Syncfusion.Drawing;
- using Syncfusion.Pdf;
- using Syncfusion.Pdf.Graphics;
- using Syncfusion.Pdf.Interactive;
- using Syncfusion.Pdf.Parsing;
- ```
+```csharp
+using Syncfusion.Drawing;
+using Syncfusion.Pdf;
+using Syncfusion.Pdf.Graphics;
+using Syncfusion.Pdf.Interactive;
+using Syncfusion.Pdf.Parsing;
+```
Step 4. **Code to add annotations**: Use the following code snippet in `Program.cs` to insert annotations into a PDF file:
- ```csharp
- // Create a FileStream object to read the input PDF file
- using (FileStream inputFileStream = new FileStream("input.pdf", FileMode.Open, FileAccess.Read))
- {
- // Load the PDF document from the input stream
- using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream))
- {
- // Access the first page of the PDF document
- PdfPageBase loadedPage = loadedDocument.Pages[0];
-
- // Create a new popup annotation
- PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(100, 100, 20, 20), "Comment");
- // Set the icon for the popup annotation
- popupAnnotation.Icon = PdfPopupIcon.Comment;
- // Set the color for the popup annotation
- popupAnnotation.Color = new PdfColor(Color.Yellow);
- // Add the annotation to the page
- loadedPage.Annotations.Add(popupAnnotation);
-
- // Save the updated document
- using (FileStream outputFileStream = new FileStream("output.pdf", FileMode.Create, FileAccess.Write))
- {
- loadedDocument.Save(outputFileStream);
- }
- }
- }
- ```
+```csharp
+//Load the PDF document
+using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
+{
+ //Get the first page of the PDF document
+ PdfPageBase loadedPage = loadedDocument.Pages[0];
+ //Create a new popup annotation
+ PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(100, 100, 20, 20), "popup annotation");
+ //Set the icon for the popup annotation
+ popupAnnotation.Icon = PdfPopupIcon.Comment;
+ //Set the color for the popup annotation
+ popupAnnotation.Color = new PdfColor(Color.Yellow);
+ //Add the annotation to the page
+ loadedPage.Annotations.Add(popupAnnotation);
+ //Save the PDF document
+ loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
+}
+```
For a complete working example, visit the [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET).
diff --git a/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/Program.cs b/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/Program.cs
index a1e796ab..ee80de90 100644
--- a/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/Program.cs
+++ b/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/Program.cs
@@ -1,21 +1,17 @@
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;
-//Load the PDF document.
+//Load the PDF document
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
{
- // Create a new PdfCompressionOptions object.
+ // Create a new PdfCompressionOptions object
PdfCompressionOptions options = new PdfCompressionOptions();
-
- //Enable the compress image.
+ //Enable the compress image
options.CompressImages = true;
-
- //Set the image quality.
+ //Set the image quality
options.ImageQuality = 50;
-
- // Compress the PDF document.
+ // Compress the PDF document
loadedDocument.Compress(options);
-
//Save the PDF document
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
}
\ No newline at end of file
diff --git a/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/README.md b/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/README.md
index ac2d94c4..84920bec 100644
--- a/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/README.md
+++ b/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/README.md
@@ -1,6 +1,6 @@
# Compressing PDF Files
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) allows users to seamlessly create, read, and edit PDF documents. Additionally, it offers features for compressing PDF files, which helps reduce their size without sacrificing quality—optimizing storage and enhancing the efficiency of file sharing.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) allows users to seamlessly create, read, and edit PDF documents. Additionally, it offers features for compressing PDF files, which helps reduce their size without sacrificing quality—optimizing storage and enhancing the efficiency of file sharing.
## Steps to compress PDF files
@@ -12,47 +12,29 @@ Step 2: **Install the NuGet package**: Add the [Syncfusion.Pdf.Net.Core](https:/
Step 3: **Add required namespaces**: Include the following namespaces in your `Program.cs` file:
- ```csharp
+```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf;
- ```
+```
Step 4: **Implement PDF compression**: Use the following code snippet in `Program.cs` to compress PDF files:
- ```csharp
- // Open a file stream to read the input PDF file
- using (FileStream fileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
- {
- // Load the PDF document from the file stream
- using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
- {
- // Create a new PdfCompressionOptions object
- PdfCompressionOptions options = new PdfCompressionOptions();
-
- // Enable image compression and set the image quality
- options.CompressImages = true;
- options.ImageQuality = 50;
-
- // Enable font optimization
- options.OptimizeFont = true;
-
- // Enable page content optimization
- options.OptimizePageContents = true;
-
- // Remove metadata from the PDF
- options.RemoveMetadata = true;
-
- // Compress the PDF document
- loadedDocument.Compress(options);
-
- // Save the document into a memory stream
- using (MemoryStream outputStream = new MemoryStream())
- {
- loadedDocument.Save(outputStream);
- }
- }
- }
- ```
+```csharp
+ //Load the PDF document
+using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
+{
+ // Create a new PdfCompressionOptions object
+ PdfCompressionOptions options = new PdfCompressionOptions();
+ //Enable the compress image
+ options.CompressImages = true;
+ //Set the image quality
+ options.ImageQuality = 50;
+ // Compress the PDF document
+ loadedDocument.Compress(options);
+ //Save the PDF document
+ loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
+}
+```
You can download a complete working sample from the [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Compression/Compress-the-existing-PDF-document).
diff --git a/Digital Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document/Program.cs b/Digital Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document/Program.cs
index c80129f0..307f7282 100644
--- a/Digital Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document/Program.cs
+++ b/Digital Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document/Program.cs
@@ -1,39 +1,29 @@
using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
-using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
-//Open existing PDF document
+//Load the PDF document
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"Data/Input.pdf"))
{
// Gets the first page of the document
PdfPageBase page = loadedDocument.Pages[0];
-
// Load the certificate from a PFX file with a private key
- FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
- PdfCertificate pdfCert = new PdfCertificate(certificateStream, "syncfusion");
-
+ PdfCertificate pdfCert = new PdfCertificate(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion");
// Create a signature
PdfSignature signature = new PdfSignature(loadedDocument, page, pdfCert, "Signature");
-
// Set signature information
signature.Bounds = new RectangleF(227.6355f, 675.795044f, 150.57901f, 32.58f);
signature.SignedName = "Syncfusion";
signature.ContactInfo = "johndoe@owned.us";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am the author of this document.";
-
// Load the image for the signature field
- FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
+ using FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
PdfBitmap signatureImage = new PdfBitmap(imageStream);
-
// Draw the image on the signature field
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, new RectangleF(0, 0, signature.Bounds.Width, signature.Bounds.Height));
-
// Save the PDF document
- document.Save(Path.GetFullPath(@"Output/Output.pdf"));
- certificateStream.Dispose();
- imageStream.Dispose();
+ loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
}
\ No newline at end of file
diff --git a/Digital Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document/README.md b/Digital Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document/README.md
index 903d7746..05d7bb74 100644
--- a/Digital Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document/README.md
+++ b/Digital Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document/README.md
@@ -1,10 +1,10 @@
# Digital Signature
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) offers powerful capabilities for creating, reading, and editing PDF documents. One of its robust features is the ability to apply digital signatures to PDF files, ensuring document authenticity, integrity, and security.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) offers powerful capabilities for creating, reading, and editing PDF documents. One of its robust features is the ability to apply digital signatures to PDF files, ensuring document authenticity, integrity, and security.
## Steps to add a digital signature to PDF files
-Follow these steps to digitally sign PDF files using the Syncfusion® library:
+Follow these steps to digitally sign PDF files using the Syncfusion® library:
Step 1: **Create a new project**: Start by creating a new C# Console Application project.
@@ -12,59 +12,41 @@ Step 2: **Install the NuGet package**: Add the [Syncfusion.Pdf.Net.Core](https:/
Step 3: **Include necessary namespaces**: Add the following namespaces in your `Program.cs` file:
- ```csharp
- using Syncfusion.Pdf;
- using Syncfusion.Pdf.Graphics;
- using Syncfusion.Pdf.Parsing;
- using Syncfusion.Pdf.Security;
- using Syncfusion.Drawing;
- using Syncfusion.Pdf.Interactive;
- ```
+```csharp
+using Syncfusion.Drawing;
+using Syncfusion.Pdf;
+using Syncfusion.Pdf.Graphics;
+using Syncfusion.Pdf.Parsing;
+using Syncfusion.Pdf.Security;
+```
Step 4: **Add digital signature code**: Use the following code snippet in `Program.cs` to add a digital signature to a PDF file:
- ```csharp
- // Open the existing PDF document as a stream
- using (FileStream inputStream = new FileStream(Path.GetFullPath("Input.pdf"), FileMode.Open, FileAccess.Read))
- {
- // Load the existing PDF document
- PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream);
-
- // Get the first page of the document
- PdfPageBase page = loadedDocument.Pages[0];
-
- // Load the certificate from a PFX file with a private key
- FileStream certificateStream = new FileStream(@"PDF.pfx", FileMode.Open, FileAccess.Read);
- PdfCertificate pdfCert = new PdfCertificate(certificateStream, "syncfusion");
-
- // Create a signature
- PdfSignature signature = new PdfSignature(loadedDocument, page, pdfCert, "Signature");
-
- // Set signature information
- signature.Bounds = new RectangleF(new PointF(0, 0), new SizeF(200, 100));
- signature.ContactInfo = "johndoe@owned.us";
- signature.LocationInfo = "Honolulu, Hawaii";
- signature.Reason = "I am the author of this document.";
-
- // Load the image for the signature field
- FileStream imageStream = new FileStream("signature.png", FileMode.Open, FileAccess.Read);
- PdfBitmap signatureImage = new PdfBitmap(imageStream);
-
- // Draw the image on the signature field
- signature.Appearance.Normal.Graphics.DrawImage(signatureImage, new RectangleF(0, 0, signature.Bounds.Width, signature.Bounds.Height));
-
- // Save the document to a file stream
- using (FileStream outputFileStream = new FileStream("signed.pdf", FileMode.Create, FileAccess.ReadWrite))
- {
- loadedDocument.Save(outputFileStream);
- }
-
- // Close the document
- loadedDocument.Close(true);
- certificateStream.Dispose();
- imageStream.Dispose();
- }
- ```
+```csharp
+//Load the PDF document
+using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"Data/Input.pdf"))
+{
+ // Gets the first page of the document
+ PdfPageBase page = loadedDocument.Pages[0];
+ // Load the certificate from a PFX file with a private key
+ PdfCertificate pdfCert = new PdfCertificate(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion");
+ // Create a signature
+ PdfSignature signature = new PdfSignature(loadedDocument, page, pdfCert, "Signature");
+ // Set signature information
+ signature.Bounds = new RectangleF(227.6355f, 675.795044f, 150.57901f, 32.58f);
+ signature.SignedName = "Syncfusion";
+ signature.ContactInfo = "johndoe@owned.us";
+ signature.LocationInfo = "Honolulu, Hawaii";
+ signature.Reason = "I am the author of this document.";
+ // Load the image for the signature field
+ using FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
+ PdfBitmap signatureImage = new PdfBitmap(imageStream);
+ // Draw the image on the signature field
+ signature.Appearance.Normal.Graphics.DrawImage(signatureImage, new RectangleF(0, 0, signature.Bounds.Width, signature.Bounds.Height));
+ // Save the PDF document
+ loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
+}
+```
For a complete working example, visit the [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Digital%20Signature/Add-a-digital-signature-to-an-existing-document/).
diff --git a/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/Program.cs b/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/Program.cs
index 2c61edff..35875940 100644
--- a/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/Program.cs
+++ b/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/Program.cs
@@ -8,34 +8,28 @@
{
// Add a new page to the PDF document
PdfPage pdfPage = pdfDocument.Pages.Add();
-
- // Set the standard font
+ // Create a standard font
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16);
-
- // Draw the string "Job Application"
+ // Draw the title text on the page
pdfPage.Graphics.DrawString("Job Application", font, PdfBrushes.Black, new PointF(250, 0));
-
- // Change the font size for the form fields
+ // Change the font size for form field labels
font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
-
- // Draw the string "Name"
+ // Draw the label "Name" on the page
pdfPage.Graphics.DrawString("Name", font, PdfBrushes.Black, new PointF(10, 20));
-
- // Create a text box field for name
+ // Create a text box field for entering the name
PdfTextBoxField nameField = new PdfTextBoxField(pdfPage, "Name");
nameField.Bounds = new RectangleF(10, 40, 200, 20);
nameField.ToolTip = "Name";
- pdfDocument.Form.Fields.Add(nameField);
-
- // Draw the string "Email address"
+ // Add the field to the form
+ pdfDocument.Form.Fields.Add(nameField);
+ // Draw the label "Email address" on the page
pdfPage.Graphics.DrawString("Email address", font, PdfBrushes.Black, new PointF(10, 80));
-
- // Create a text box field for email address
+ // Create a text box field for entering the email address
PdfTextBoxField emailField = new PdfTextBoxField(pdfPage, "Email address");
emailField.Bounds = new RectangleF(10, 100, 200, 20);
emailField.ToolTip = "Email address";
- pdfDocument.Form.Fields.Add(emailField);
-
- //Save the PDF document
+ // Add the field to the form
+ pdfDocument.Form.Fields.Add(emailField);
+ // Save the PDF document
pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
}
\ No newline at end of file
diff --git a/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/README.md b/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/README.md
index 7d72f760..a18dce73 100644
--- a/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/README.md
+++ b/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/README.md
@@ -1,6 +1,6 @@
# PDF Forms
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) provides an easy way to create, read, and edit PDF documents. It also includes features for creating, filling, and editing PDF forms, which can include interactive form fields and form data.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) provides an easy way to create, read, and edit PDF documents. It also includes features for creating, filling, and editing PDF forms, which can include interactive form fields and form data.
## Steps to create PDF forms
@@ -12,56 +12,47 @@ Step 2: **Install the NuGet package**: Add the [Syncfusion.Pdf.Net.Core](https:/
Step 3: **Include necessary namespaces**: Add the following namespaces in your `Program.cs` file:
- ```csharp
- using Syncfusion.Drawing;
- using Syncfusion.Pdf;
- using Syncfusion.Pdf.Graphics;
- using Syncfusion.Pdf.Interactive;
- ```
+```csharp
+using Syncfusion.Drawing;
+using Syncfusion.Pdf;
+using Syncfusion.Pdf.Graphics;
+using Syncfusion.Pdf.Interactive;
+```
Step 4: **Create PDF forms**: Implement the following code in `Program.cs` to add a textbox field to a PDF document:
- ```csharp
- // Create a new PDF document
- using (PdfDocument pdfDocument = new PdfDocument())
- {
- // Add a new page to the PDF document
- PdfPage pdfPage = pdfDocument.Pages.Add();
-
- // Set the standard font
- PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16);
-
- // Draw the title "Job Application"
- pdfPage.Graphics.DrawString("Job Application", font, PdfBrushes.Black, new PointF(250, 0));
-
- // Change the font size for form fields
- font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
-
- // Draw the label "Name"
- pdfPage.Graphics.DrawString("Name", font, PdfBrushes.Black, new PointF(10, 20));
-
- // Create a textbox field for the name
- PdfTextBoxField nameField = new PdfTextBoxField(pdfPage, "Name");
- nameField.Bounds = new RectangleF(10, 40, 200, 20);
- nameField.ToolTip = "Name";
- pdfDocument.Form.Fields.Add(nameField);
-
- // Draw the label "Email address"
- pdfPage.Graphics.DrawString("Email address", font, PdfBrushes.Black, new PointF(10, 80));
-
- // Create a textbox field for the email address
- PdfTextBoxField emailField = new PdfTextBoxField(pdfPage, "Email address");
- emailField.Bounds = new RectangleF(10, 100, 200, 20);
- emailField.ToolTip = "Email address";
- pdfDocument.Form.Fields.Add(emailField);
-
- // Save the PDF document to a file stream
- using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create))
- {
- pdfDocument.Save(outputFileStream);
- }
- }
- ```
+```csharp
+// Create a new PDF document
+using (PdfDocument pdfDocument = new PdfDocument())
+{
+ // Add a new page to the PDF document
+ PdfPage pdfPage = pdfDocument.Pages.Add();
+ // Create a standard font
+ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16);
+ // Draw the title text on the page
+ pdfPage.Graphics.DrawString("Job Application", font, PdfBrushes.Black, new PointF(250, 0));
+ // Change the font size for form field labels
+ font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
+ // Draw the label "Name" on the page
+ pdfPage.Graphics.DrawString("Name", font, PdfBrushes.Black, new PointF(10, 20));
+ // Create a text box field for entering the name
+ PdfTextBoxField nameField = new PdfTextBoxField(pdfPage, "Name");
+ nameField.Bounds = new RectangleF(10, 40, 200, 20);
+ nameField.ToolTip = "Name";
+ // Add the field to the form
+ pdfDocument.Form.Fields.Add(nameField);
+ // Draw the label "Email address" on the page
+ pdfPage.Graphics.DrawString("Email address", font, PdfBrushes.Black, new PointF(10, 80));
+ // Create a text box field for entering the email address
+ PdfTextBoxField emailField = new PdfTextBoxField(pdfPage, "Email address");
+ emailField.Bounds = new RectangleF(10, 100, 200, 20);
+ emailField.ToolTip = "Email address";
+ // Add the field to the form
+ pdfDocument.Form.Fields.Add(emailField);
+ // Save the PDF document
+ pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
+}
+```
For a full working example, you can download the sample from the [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Forms/Add-a-textbox-field-to-a-new-PDF-document).
diff --git a/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/Program.cs b/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/Program.cs
index eb715a6c..bffa8493 100644
--- a/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/Program.cs
+++ b/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/Program.cs
@@ -1,18 +1,16 @@
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf;
+using Syncfusion.Drawing;
-//Create a new PDF document.
+//Create a new PDF document
using (PdfDocument document = new PdfDocument())
{
- //Add a page to the document.
+ //Add a page to the document
PdfPage page = document.Pages.Add();
- //Create PDF graphics for the page.
- PdfGraphics graphics = page.Graphics;
- //Set the standard font.
+ // Create a standard font
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
- //Draw the text.
- graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0));
-
+ //Draw the text using page graphics
+ page.Graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
//Save the PDF document
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
}
\ No newline at end of file
diff --git a/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/README.md b/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/README.md
index 4cf58258..71d95ec1 100644
--- a/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/README.md
+++ b/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/README.md
@@ -13,32 +13,26 @@ Step 2: **Install the NuGet package**: Reference the [Syncfusion.Pdf.NET](https:
Step 3: **Include required namespaces**: Add the following namespace in your `Program.cs` file:
```csharp
- using Syncfusion.Pdf;
- using Syncfusion.Pdf.Graphics;
+using Syncfusion.Pdf;
+using Syncfusion.Pdf.Graphics;
+using Syncfusion.Drawing;
```
Step 4: **Create PDF document**: Use the following code snippet in `Program.cs` to merge PDF files:
```csharp
-//Create a new PDF document.
-PdfDocument document = new PdfDocument();
-//Add a page to the document.
-PdfPage page = document.Pages.Add();
-//Create PDF graphics for the page.
-PdfGraphics graphics = page.Graphics;
-//Set the standard font.
-PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
-//Draw the text.
-graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0));
-
-//Create file stream.
-using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
+//Create a new PDF document
+using (PdfDocument document = new PdfDocument())
{
- //Save the PDF document to file stream.
- document.Save(outputFileStream);
+ //Add a page to the document
+ PdfPage page = document.Pages.Add();
+ // Create a standard font
+ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
+ //Draw the text using page graphics
+ page.Graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
+ //Save the PDF document
+ document.Save(Path.GetFullPath(@"Output/Output.pdf"));
}
-//Close the document.
-document.Close(true);
```
You can download a complete working sample from the [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Getting%20Started/.NET/Create_PDF_NET).
diff --git a/HTML to PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document/Program.cs b/HTML to PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document/Program.cs
index 42efaaeb..ae2c8fc3 100644
--- a/HTML to PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document/Program.cs
+++ b/HTML to PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document/Program.cs
@@ -1,17 +1,11 @@
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
-//Initialize HTML to PDF converter.
+//Initialize HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
-//Create blink converter settings
-BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
-
-//Assign Blink converter settings to HTML converter.
-htmlConverter.ConverterSettings = blinkConverterSettings;
-//Convert URL to PDF document.
-PdfDocument document = htmlConverter.Convert("https://www.google.com");
-
-//Save the PDF document
-document.Save(Path.GetFullPath(@"Output/Output.pdf"));
-//Close the document.
-document.Close(true);
+//Convert URL to PDF
+using (PdfDocument document = htmlConverter.Convert("https://www.google.com"))
+{
+ //Save the PDF document
+ document.Save("Output.pdf");
+}
\ No newline at end of file
diff --git a/HTML to PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document/README.md b/HTML to PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document/README.md
index 0644d8c1..f409c94d 100644
--- a/HTML to PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document/README.md
+++ b/HTML to PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document/README.md
@@ -1,6 +1,6 @@
# HTML to PDF Conversion
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) allows you to create, read, and edit PDF documents. It also includes functionality for accurately converting HTML content into PDF files.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) allows you to create, read, and edit PDF documents. It also includes functionality for accurately converting HTML content into PDF files.
## Steps to convert HTML to PDF
@@ -12,31 +12,23 @@ Step 2: **Install the NuGet package**: Add the [Syncfusion.HtmlToPdfConverter.Ne
Step 3: **Include necessary namespaces**: Add the following namespaces in your `Program.cs` file:
- ```csharp
- using Syncfusion.HtmlConverter;
- using Syncfusion.Pdf;
- ```
+```csharp
+using Syncfusion.HtmlConverter;
+using Syncfusion.Pdf;
+```
Step 4: **Convert HTML to PDF**: Implement the following code in `Program.cs` to convert a website URL to a PDF file:
- ```csharp
- //Initialize HTML to PDF converter.
- HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
- //Create blink converter settings
- BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
- //Assign Blink converter settings to HTML converter.
- htmlConverter.ConverterSettings = blinkConverterSettings;
- //Convert URL to PDF document.
- PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com");
- //Create file stream.
- using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
- {
- //Save the PDF document
- document.Save(fileStream);
- }
- //Close the document.
- document.Close(true);
- ```
+```csharp
+//Initialize HTML to PDF converter
+HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
+//Convert URL to PDF
+using (PdfDocument document = htmlConverter.Convert("https://www.google.com"))
+{
+ //Save the PDF document
+ document.Save("Output.pdf");
+}
+```
You can download a complete working sample from the [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/Convert-website-URL-to-PDF-document).
diff --git a/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/Program.cs b/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/Program.cs
index 3f524b31..1c1ece2c 100644
--- a/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/Program.cs
+++ b/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/Program.cs
@@ -2,22 +2,15 @@
// Create an instance of the ImageToPdfConverter class
ImageToPdfConverter imageToPdfConverter = new ImageToPdfConverter();
-
-// Set the page size for the PDF
+// Set the page size for the document
imageToPdfConverter.PageSize = PdfPageSize.A4;
-
-// Set the position of the image in the PDF
+// Set the position of the image in the document
imageToPdfConverter.ImagePosition = PdfImagePosition.TopLeftCornerOfPage;
-
// Create a file stream to read the image file
using (FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read))
+// Convert the image to a PDF document using the ImageToPdfConverter
+using (PdfDocument pdfDocument = imageToPdfConverter.Convert(imageStream))
{
- // Convert the image to a PDF document using the ImageToPdfConverter
- PdfDocument pdfDocument = imageToPdfConverter.Convert(imageStream);
-
- //Save the PDF document to file stream.
+ //Save the PDF document
pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
-
- // Close the document
- pdfDocument.Close(true);
}
\ No newline at end of file
diff --git a/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/README.md b/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/README.md
index b04a9964..c77c01fd 100644
--- a/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/README.md
+++ b/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/README.md
@@ -1,10 +1,10 @@
# Converting Images to PDF
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) offers tools to create, read, and edit PDF documents. It also provides functionality to convert images into PDF files, making it easy to integrate image content into your PDF documents.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) offers tools to create, read, and edit PDF documents. It also provides functionality to convert images into PDF files, making it easy to integrate image content into your PDF documents.
## Steps to convert images to PDF
-Follow these steps to convert an image into a PDF file using the Syncfusion® library:
+Follow these steps to convert an image into a PDF file using the Syncfusion® library:
Step 1: **Create a new project**: Start a new C# Console Application project.
@@ -12,39 +12,28 @@ Step 2: **Install the NuGet package**: Add the [Syncfusion.Pdf.Imaging.Net.Core]
Step 3: **Include necessary namespaces**: Add the following namespace in your `Program.cs` file:
- ```csharp
- using Syncfusion.Pdf;
- ```
+```csharp
+using Syncfusion.Pdf;
+```
Step 4: **Convert image to PDF**: Implement the following code in `Program.cs` to convert an image into a PDF file:
- ```csharp
- // Create an instance of the ImageToPdfConverter class
- var imageToPdfConverter = new ImageToPdfConverter();
-
- // Set the page size for the PDF
- imageToPdfConverter.PageSize = PdfPageSize.A4;
-
- // Set the position of the image in the PDF
- imageToPdfConverter.ImagePosition = PdfImagePosition.TopLeftCornerOfPage;
-
- // Create a file stream to read the image file
- using (var imageStream = new FileStream("Autumn Leaves.jpg", FileMode.Open, FileAccess.Read))
- {
- // Convert the image to a PDF document using the ImageToPdfConverter
- var pdfDocument = imageToPdfConverter.Convert(imageStream);
-
- // Create a file stream for the output PDF file
- using (var outputFileStream = new FileStream(Path.GetFullPath("Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
- {
- // Save the generated PDF document to the output file stream
- pdfDocument.Save(outputFileStream);
- }
-
- // Close the document
- pdfDocument.Close(true);
- }
- ```
+```csharp
+// Create an instance of the ImageToPdfConverter class
+ImageToPdfConverter imageToPdfConverter = new ImageToPdfConverter();
+// Set the page size for the document
+imageToPdfConverter.PageSize = PdfPageSize.A4;
+// Set the position of the image in the document
+imageToPdfConverter.ImagePosition = PdfImagePosition.TopLeftCornerOfPage;
+// Create a file stream to read the image file
+using (FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read))
+// Convert the image to a PDF document using the ImageToPdfConverter
+using (PdfDocument pdfDocument = imageToPdfConverter.Convert(imageStream))
+{
+ //Save the PDF document
+ pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
+}
+```
You can download a complete working sample from the [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Images/Convert_Image_to_PDF/.NET).
diff --git a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Program.cs b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Program.cs
index f54a9b61..47d3348a 100644
--- a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Program.cs
+++ b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Program.cs
@@ -1,17 +1,12 @@
using Syncfusion.Pdf;
-//Create a PDF document
-using (PdfDocument finalDocument = new PdfDocument())
-{
- //Get the stream from an existing PDF document
- using (FileStream firstStream = new FileStream(Path.GetFullPath(@"Data/file1.pdf"), FileMode.Open, FileAccess.Read))
- using (FileStream secondStream = new FileStream(Path.GetFullPath(@"Data/file2.pdf"), FileMode.Open, FileAccess.Read))
- {
- //Create a PDF stream for merging
- Stream[] streams = { firstStream, secondStream };
- //Merge PDF documents
- PdfDocumentBase.Merge(finalDocument, streams);
- //Save the document
- finalDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
- }
+//Creates a new PDF document
+using (PdfDocument document = new PdfDocument())
+{
+ //Creates a string array of source files to be merged
+ string[] source = { Path.GetFullPath(@"Data/file1.pdf"), Path.GetFullPath(@"Data/file2.pdf") };
+ //Merge PDF documents
+ PdfDocument.Merge(document, source);
+ //Saves the PDF document
+ document.Save(Path.GetFullPath(@"Output/Output.pdf"));
}
\ No newline at end of file
diff --git a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/README.md b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/README.md
index 17e889d8..c23b1109 100644
--- a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/README.md
+++ b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/README.md
@@ -1,10 +1,10 @@
# Merging PDF Files
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) allows you to easily create, read, edit, and merge PDF documents. This library provides a straightforward way to combine multiple PDF files into a single document.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) allows you to easily create, read, edit, and merge PDF documents. This library provides a straightforward way to combine multiple PDF files into a single document.
## Steps to merge PDF files
-Follow these steps to merge PDF files using the Syncfusion® library:
+Follow these steps to merge PDF files using the Syncfusion® library:
Step 1: **Create a new project**: Start by creating a new C# Console Application project.
@@ -12,34 +12,24 @@ Step 2: **Install the NuGet package**: Reference the [Syncfusion.Pdf.Net.Core](h
Step 3: **Include required namespaces**: Add the following namespace in your `Program.cs` file:
- ```csharp
- using Syncfusion.Pdf;
- ```
+```csharp
+using Syncfusion.Pdf;
+```
Step 4: **Merge PDF files**: Use the following code snippet in `Program.cs` to merge PDF files:
- ```csharp
- // Create a PDF document for the final merged output
- using (PdfDocument finalDocument = new PdfDocument())
- {
- // Open streams for existing PDF documents
- using (FileStream firstFileStream = new FileStream("File1.pdf", FileMode.Open, FileAccess.Read))
- using (FileStream secondFileStream = new FileStream("File2.pdf", FileMode.Open, FileAccess.Read))
- {
- // Create an array of streams to merge
- Stream[] streams = { firstFileStream, secondFileStream };
-
- // Merge PDF documents into the final document
- PdfDocumentBase.Merge(finalDocument, streams);
-
- // Save the merged document to a file stream
- using (FileStream outputFileStream = new FileStream("MergedDocument.pdf", FileMode.Create, FileAccess.Write))
- {
- finalDocument.Save(outputFileStream);
- }
- }
- }
- ```
+```csharp
+//Creates a new PDF document
+using (PdfDocument document = new PdfDocument())
+{
+ //Creates a string array of source files to be merged
+ string[] source = { Path.GetFullPath(@"Data/file1.pdf"), Path.GetFullPath(@"Data/file2.pdf") };
+ //Merge PDF documents
+ PdfDocument.Merge(document, source);
+ //Saves the PDF document
+ document.Save(Path.GetFullPath(@"Output/Output.pdf"));
+}
+```
You can download a complete working sample from the [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Merge%20PDFs/Merge-multiple-documents-from-stream/).
diff --git a/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/Program.cs b/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/Program.cs
index a0178c19..d8c30e5f 100644
--- a/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/Program.cs
+++ b/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/Program.cs
@@ -4,18 +4,14 @@
// Initialize the OCR processor
using (OCRProcessor processor = new OCRProcessor())
{
- // Load the existing PDF document
+ // Load the PDF document
using (PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
{
// Set OCR language to process
processor.Settings.Language = Languages.English;
-
// Process OCR by providing the PDF document
processor.PerformOCR(pdfLoadedDocument);
-
//Save the PDF document
pdfLoadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
- //Close the document.
- pdfLoadedDocument.Close(true);
}
}
\ No newline at end of file
diff --git a/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/README.md b/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/README.md
index 0fc683a3..a8237ed7 100644
--- a/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/README.md
+++ b/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/README.md
@@ -1,10 +1,10 @@
# OCR on PDF Files
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) enables you to create, read, and edit PDF documents effortlessly. Additionally, the library provides OCR (Optical Character Recognition) capabilities, allowing you to extract text from scanned images within PDF files.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) enables you to create, read, and edit PDF documents effortlessly. Additionally, the library provides OCR (Optical Character Recognition) capabilities, allowing you to extract text from scanned images within PDF files.
## Steps to perform OCR on PDF files
-Follow these steps to apply OCR to PDF files using the Syncfusion® library:
+Follow these steps to apply OCR to PDF files using the Syncfusion® library:
Step 1: **Create a new project**: Set up a new C# Console Application project.
@@ -12,39 +12,29 @@ Step 2: **Install the NuGet package**: Add the [Syncfusion.PDF.OCR.Net.Core](htt
Step 3: **Include necessary namespaces**: Add the following namespaces in your `Program.cs` file:
- ```csharp
- using Syncfusion.OCRProcessor;
- using Syncfusion.Pdf.Parsing;
- ```
+```csharp
+using Syncfusion.OCRProcessor;
+using Syncfusion.Pdf.Parsing;
+```
Step 4: **Implement OCR Processing**: Use the following code snippet in `Program.cs` to perform OCR on a PDF document:
- ```csharp
- // Initialize the OCR processor
- using (OCRProcessor processor = new OCRProcessor())
- {
- // Load the existing PDF document
- using (FileStream stream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
- {
- PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(stream);
-
- // Set the language for OCR processing
- processor.Settings.Language = Languages.English;
-
- // Perform OCR on the PDF document
- processor.PerformOCR(pdfLoadedDocument);
-
- // Save the OCR-processed document
- using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
- {
- pdfLoadedDocument.Save(outputFileStream);
- }
-
- // Close the document
- pdfLoadedDocument.Close(true);
- }
- }
- ```
+```csharp
+// Initialize the OCR processor
+using (OCRProcessor processor = new OCRProcessor())
+{
+ // Load the PDF document
+ using (PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
+ {
+ // Set OCR language to process
+ processor.Settings.Language = Languages.English;
+ // Process OCR by providing the PDF document
+ processor.PerformOCR(pdfLoadedDocument);
+ //Save the PDF document
+ pdfLoadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
+ }
+}
+```
For a complete working sample, you can download the example from the [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/OCR/.NET/Perform-OCR-for-the-entire-PDF-document).
diff --git a/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/Program.cs b/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/Program.cs
index f72727eb..1f749e3e 100644
--- a/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/Program.cs
+++ b/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/Program.cs
@@ -3,60 +3,45 @@
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
-//Load the PDF document.
-PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"));
-
-//Sample level font event handling
-loadedDocument.SubstituteFont += LoadedDocument_SubstituteFont;
+// Load the PDF document
+using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
+{
+ // Handle font substitution during PDF/A conversion
+ loadedDocument.SubstituteFont += LoadedDocument_SubstituteFont;
+ // Convert the document to PDF/A-1B format
+ loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B);
+ // Save the PDF document
+ loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
+}
+// Event handler to substitute missing fonts during conversion
void LoadedDocument_SubstituteFont(object sender, PdfFontEventArgs args)
{
- //Get the font name.
+ // Extract the font name (ignoring style suffixes)
string fontName = args.FontName.Split(',')[0];
-
- //Get the font style.
+ // Determine the font style
PdfFontStyle fontStyle = args.FontStyle;
- SKFontStyle sKFontStyle = SKFontStyle.Normal;
-
- if (fontStyle != PdfFontStyle.Regular)
- {
- if (fontStyle == PdfFontStyle.Bold)
- {
- sKFontStyle = SKFontStyle.Bold;
- }
- else if (fontStyle == PdfFontStyle.Italic)
- {
- sKFontStyle = SKFontStyle.Italic;
- }
- else if (fontStyle == (PdfFontStyle.Italic | PdfFontStyle.Bold))
- {
- sKFontStyle = SKFontStyle.BoldItalic;
- }
- }
-
- SKTypeface typeface = SKTypeface.FromFamilyName(fontName, sKFontStyle);
+ SKFontStyle skFontStyle = SKFontStyle.Normal;
+ // Map PDF font styles to SkiaSharp font styles
+ if (fontStyle == PdfFontStyle.Bold)
+ skFontStyle = SKFontStyle.Bold;
+ else if (fontStyle == PdfFontStyle.Italic)
+ skFontStyle = SKFontStyle.Italic;
+ else if (fontStyle == (PdfFontStyle.Bold | PdfFontStyle.Italic))
+ skFontStyle = SKFontStyle.BoldItalic;
+ // Load the typeface using SkiaSharp
+ SKTypeface typeface = SKTypeface.FromFamilyName(fontName, skFontStyle);
SKStreamAsset typeFaceStream = typeface.OpenStream();
- MemoryStream memoryStream = null;
+ // Create a memory stream from the font data
+ MemoryStream memoryStream = null;
if (typeFaceStream != null && typeFaceStream.Length > 0)
{
- //Create a fontData from the type face stream.
- byte[] fontData = new byte[typeFaceStream.Length - 1];
- typeFaceStream.Read(fontData, typeFaceStream.Length);
+ byte[] fontData = new byte[typeFaceStream.Length];
+ typeFaceStream.Read(fontData, fontData.Length);
typeFaceStream.Dispose();
- //Create a new memory stream from the font data.
memoryStream = new MemoryStream(fontData);
}
-
- //Set the font stream to the event args.
+ // Assign the font stream to the event arguments
args.FontStream = memoryStream;
-}
-
-//Convert the loaded document to PDF/A document
-loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B);
-
-//Save the PDF document to file stream.
-loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
-
-//Close the document.
-loadedDocument.Close(true);
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/README.md b/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/README.md
index 404cb2e3..a45eaff8 100644
--- a/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/README.md
+++ b/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/README.md
@@ -1,10 +1,10 @@
# Convert PDF to PDF/A
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) provides tools for creating, reading, and editing PDF documents. Among its features, the library enables conversion of standard PDF files into the PDF/A format, suitable for long-term archiving and meeting archival standards.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) provides tools for creating, reading, and editing PDF documents. Among its features, the library enables conversion of standard PDF files into the PDF/A format, suitable for long-term archiving and meeting archival standards.
## Steps to convert a PDF to PDF/A
-Follow these steps to convert a PDF document to PDF/A format using the Syncfusion® library:
+Follow these steps to convert a PDF document to PDF/A format using the Syncfusion® library:
Step 1: **Create a new project**: Start by creating a new C# Console Application project.
@@ -12,34 +12,59 @@ Step 2: **Install the NuGet package**: Reference the [Syncfusion.Pdf.Net.Core](h
Step 3: **Include necessary namespaces**: Add the following namespaces in your `Program.cs` file:
- ```csharp
- using Syncfusion.Pdf;
- using Syncfusion.Pdf.Parsing;
- ```
+```csharp
+using SkiaSharp;
+using Syncfusion.Pdf;
+using Syncfusion.Pdf.Graphics;
+using Syncfusion.Pdf.Parsing;
+```
Step 4: **Convert PDF to PDF/A**: Implement the following code in `Program.cs` to perform the conversion:
- ```csharp
- // Load an existing PDF document
- using (FileStream inputPdfStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
- {
- // Initialize PdfLoadedDocument with the input file stream
- PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPdfStream);
-
- // Convert the loaded document to PDF/A format with the specified conformance level
- loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B);
-
- // Save the converted PDF/A document to a new file
- using (FileStream outputPdfStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.Write))
- {
- // Save the modified PDF document to the output file stream
- loadedDocument.Save(outputPdfStream);
- }
-
- // Close the loaded document to release resources
- loadedDocument.Close(true);
- }
- ```
+```csharp
+// Load the PDF document
+using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
+{
+ // Handle font substitution during PDF/A conversion
+ loadedDocument.SubstituteFont += LoadedDocument_SubstituteFont;
+ // Convert the document to PDF/A-1B format
+ loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B);
+ // Save the PDF document
+ loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
+}
+
+// Event handler to substitute missing fonts during conversion
+void LoadedDocument_SubstituteFont(object sender, PdfFontEventArgs args)
+{
+ // Extract the font name (ignoring style suffixes)
+ string fontName = args.FontName.Split(',')[0];
+ // Determine the font style
+ PdfFontStyle fontStyle = args.FontStyle;
+ SKFontStyle skFontStyle = SKFontStyle.Normal;
+ // Map PDF font styles to SkiaSharp font styles
+ if (fontStyle == PdfFontStyle.Bold)
+ skFontStyle = SKFontStyle.Bold;
+ else if (fontStyle == PdfFontStyle.Italic)
+ skFontStyle = SKFontStyle.Italic;
+ else if (fontStyle == (PdfFontStyle.Bold | PdfFontStyle.Italic))
+ skFontStyle = SKFontStyle.BoldItalic;
+ // Load the typeface using SkiaSharp
+ SKTypeface typeface = SKTypeface.FromFamilyName(fontName, skFontStyle);
+ SKStreamAsset typeFaceStream = typeface.OpenStream();
+
+ // Create a memory stream from the font data
+ MemoryStream memoryStream = null;
+ if (typeFaceStream != null && typeFaceStream.Length > 0)
+ {
+ byte[] fontData = new byte[typeFaceStream.Length];
+ typeFaceStream.Read(fontData, fontData.Length);
+ typeFaceStream.Dispose();
+ memoryStream = new MemoryStream(fontData);
+ }
+ // Assign the font stream to the event arguments
+ args.FontStream = memoryStream;
+}
+```
You can download a complete working sample from the [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/PDF%20Conformance/Convert-PDF-to-PDFA-conformance-document).
diff --git a/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/Program.cs b/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/Program.cs
index 83c98267..94091d2e 100644
--- a/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/Program.cs
+++ b/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/Program.cs
@@ -1,19 +1,8 @@
-using Syncfusion.Pdf;
-using Syncfusion.Pdf.Parsing;
+using Syncfusion.Pdf.Parsing;
-//Load the PDF document.
+//Load the PDF document
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
{
- // Iterate over the pages of the loaded document
- for (int pageIndex = 0; pageIndex < loadedDocument.PageCount; pageIndex++)
- {
- // Create a new PdfDocument object to hold the output
- using (PdfDocument outputDocument = new PdfDocument())
- {
- // Import the page from the loadedDocument to the outputDocument
- outputDocument.ImportPage(loadedDocument, pageIndex);
- //Save the PDF document
- outputDocument.Save(Path.GetFullPath(@"Output/" + pageIndex + ".pdf"));
- }
- }
+ //Split the pages into separate documents
+ loadedDocument.Split("Output" + "{0}.pdf");
}
\ No newline at end of file
diff --git a/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/README.md b/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/README.md
index 11ed1c99..1bce113d 100644
--- a/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/README.md
+++ b/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/README.md
@@ -1,6 +1,6 @@
# Split PDF Files
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) allows for creating, reading, and editing PDF documents, as well as splitting them into separate files.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) allows for creating, reading, and editing PDF documents, as well as splitting them into separate files.
## Steps to split PDF files
@@ -10,40 +10,20 @@ Step 2: **Install the NuGet package**: Add the [Syncfusion.Pdf.Net.Core](https:/
Step 3: **Include necessary namespaces**: In your **Program.cs** file, include the following namespaces:
- ```csharp
- using Syncfusion.Pdf.Parsing;
- using Syncfusion.Pdf;
- ```
+```csharp
+using Syncfusion.Pdf.Parsing;
+```
Step 4: **Split the PDF file:** Implement the following code in **Program.cs** to split the PDF file:
- ```csharp
- // Create a FileStream object to read the input PDF file
- using (FileStream inputFileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
- {
- // Load the PDF document from the input stream
- using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream))
- {
- // Iterate over each page of the loaded document
- for (int pageIndex = 0; pageIndex < loadedDocument.PageCount; pageIndex++)
- {
- // Create a new PdfDocument for the output
- using (PdfDocument outputDocument = new PdfDocument())
- {
- // Import the page into the new document
- outputDocument.ImportPage(loadedDocument, pageIndex);
-
- // Create a FileStream to write the output PDF file
- using (FileStream outputFileStream = new FileStream($"Output{pageIndex}.pdf", FileMode.Create, FileAccess.Write))
- {
- // Save the new document to the output stream
- outputDocument.Save(outputFileStream);
- }
- }
- }
- }
- }
- ```
+```csharp
+//Load the PDF document
+using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
+{
+ //Split the pages into separate documents
+ loadedDocument.Split("Output" + "{0}.pdf");
+}
+```
You can download a complete working sample from [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Pages/Splitting-PDF-file-into-individual-pages/).
diff --git a/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/Program.cs b/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/Program.cs
index 7db46273..dcb89f97 100644
--- a/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/Program.cs
+++ b/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/Program.cs
@@ -3,17 +3,17 @@
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Redaction;
-//Load the PDF document.
+//Load the PDF document
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
{
+ // Get the first page of the document
PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;
- //Create a PDF redaction for the page
+ // Define a redaction area and set its color to black
PdfRedaction redaction = new PdfRedaction(new RectangleF(340, 120, 140, 20), Color.Black);
- //Add a redaction object into the redaction collection of loaded page.
+ // Add the redaction to the page
loadedPage.AddRedaction(redaction);
- //Redact the contents from the PDF document.
+ // Apply the redaction to remove content
loadedDocument.Redact();
-
- //Save the PDF document
+ // Save the PDF document
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
}
\ No newline at end of file
diff --git a/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/README.md b/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/README.md
index a5ba7bc0..fa4313e1 100644
--- a/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/README.md
+++ b/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/README.md
@@ -1,6 +1,6 @@
# Redacting PDF Files
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) allows users to create, read, and edit PDFs seamlessly. One of its key features is the ability to redact PDF content, enabling the permanent removal or hiding of sensitive information while maintaining the rest of the document's integrity.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) allows users to create, read, and edit PDFs seamlessly. One of its key features is the ability to redact PDF content, enabling the permanent removal or hiding of sensitive information while maintaining the rest of the document's integrity.
## Steps to Redact PDF Files
@@ -10,42 +10,31 @@ Step 2: **Install the NuGet package**: Add the [Syncfusion.Pdf.Net.Core](https:/
Step 3: **Include necessary namespaces**: Add these namespaces to your **Program.cs** file:
- ```csharp
- using Syncfusion.Pdf.Parsing;
- using Syncfusion.Pdf.Redaction;
- using Syncfusion.Pdf;
- using Syncfusion.Drawing;
- ```
+```csharp
+using Syncfusion.Drawing;
+using Syncfusion.Pdf;
+using Syncfusion.Pdf.Parsing;
+using Syncfusion.Pdf.Redaction;
+```
Step 4: **Implement redaction**: Use the following code in **Program.cs** to perform PDF redaction:
- ```csharp
- using (FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read))
- {
- // Load the PDF document from the input stream
- using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream))
- {
- // Access the first page of the document
- PdfLoadedPage firstPage = loadedDocument.Pages[0] as PdfLoadedPage;
-
- // Define a redaction area
- RectangleF redactionRectangle = new RectangleF(340, 120, 140, 20);
- PdfRedaction redaction = new PdfRedaction(redactionRectangle);
-
- // Apply the redaction to the page
- firstPage.AddRedaction(redaction);
-
- // Execute the redaction
- loadedDocument.Redact();
-
- // Save the redacted document
- using (FileStream outputFileStream = new FileStream("Redact.pdf", FileMode.Create, FileAccess.ReadWrite))
- {
- loadedDocument.Save(outputFileStream);
- }
- }
- }
- ```
+```csharp
+//Load the PDF document
+using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
+{
+ // Get the first page of the document
+ PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;
+ // Define a redaction area and set its color to black
+ PdfRedaction redaction = new PdfRedaction(new RectangleF(340, 120, 140, 20), Color.Black);
+ // Add the redaction to the page
+ loadedPage.AddRedaction(redaction);
+ // Apply the redaction to remove content
+ loadedDocument.Redact();
+ // Save the PDF document
+ loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
+}
+```
You can download a complete working example from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Redaction/Removing-sensitive-content-from-the-PDF-document/).
diff --git a/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/Program.cs b/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/Program.cs
index 420c453b..85fed5de 100644
--- a/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/Program.cs
+++ b/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/Program.cs
@@ -4,17 +4,14 @@
//Load the PDF document.
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
{
- //Gets a security object for the document
+ // Get the security settings of the document
PdfSecurity security = loadedDocument.Security;
-
- // Configure key size and encryption algorithm
+ // Set encryption to AES with a 256-bit key
security.KeySize = PdfEncryptionKeySize.Key256Bit;
security.Algorithm = PdfEncryptionAlgorithm.AES;
-
- // Assign owner and user passwords
+ // Set owner and user passwords for the document
security.OwnerPassword = "owner123";
security.UserPassword = "user123";
-
- //Save the PDF document
+ // Save the secured PDF document
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
}
\ No newline at end of file
diff --git a/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/README.md b/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/README.md
index 27604727..e95bdeca 100644
--- a/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/README.md
+++ b/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/README.md
@@ -1,6 +1,6 @@
# Protect PDF Files
-The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) provides tools for creating, reading, and editing PDF documents. It also allows you to protect your PDF files by applying encryption and setting password-based permissions.
+The Syncfusion® [.NET Core PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net-core/pdf-library) provides tools for creating, reading, and editing PDF documents. It also allows you to protect your PDF files by applying encryption and setting password-based permissions.
## Steps to Protect PDF Files
@@ -10,41 +10,29 @@ Step 2: **Install the NuGet package**: Add the [Syncfusion.Pdf.Net.Core](https:/
Step 3: **Include necessary namespaces**: Add these namespaces in your **Program.cs** file:
- ```csharp
- using Syncfusion.Pdf.Security;
- using Syncfusion.Pdf.Parsing;
- ```
+```csharp
+using Syncfusion.Pdf.Parsing;
+using Syncfusion.Pdf.Security;
+```
Step 4: **Implement encryption**: Use the following code in **Program.cs** to secure your PDF file:
- ```csharp
- // Load the PDF document from a file stream
- using (FileStream inputFileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
- {
- // Load the PDF document
- PdfLoadedDocument document = new PdfLoadedDocument(inputFileStream);
-
- // Access the document's security settings
- PdfSecurity security = document.Security;
-
- // Set key size and encryption algorithm
- security.KeySize = PdfEncryptionKeySize.Key256Bit;
- security.Algorithm = PdfEncryptionAlgorithm.AES;
-
- // Specify owner and user passwords
- security.OwnerPassword = "owner123";
- security.UserPassword = "user123";
-
- // Save the protected PDF document to a file stream
- using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create))
- {
- document.Save(outputFileStream);
- }
-
- // Close the document
- document.Close(true);
- }
- ```
+```csharp
+//Load the PDF document.
+using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
+{
+ // Get the security settings of the document
+ PdfSecurity security = loadedDocument.Security;
+ // Set encryption to AES with a 256-bit key
+ security.KeySize = PdfEncryptionKeySize.Key256Bit;
+ security.Algorithm = PdfEncryptionAlgorithm.AES;
+ // Set owner and user passwords for the document
+ security.OwnerPassword = "owner123";
+ security.UserPassword = "user123";
+ // Save the secured PDF document
+ loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
+}
+```
You can download a complete working example from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Security/Protect-an-existing-PDF-document/).
diff --git a/Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/Program.cs b/Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/Program.cs
index 61e343a8..a749a26c 100644
--- a/Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/Program.cs
+++ b/Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/Program.cs
@@ -1,29 +1,25 @@
using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Grid;
-using System.Data;
-//Create a new PDF document.
+// Create a new PDF document
using (PdfDocument document = new PdfDocument())
{
- //Add a page
+ //Add a page to the document
PdfPage page = document.Pages.Add();
-
- //Create a PdfGrid
+ // Create a PdfGrid
PdfGrid pdfGrid = new PdfGrid();
-
- //Add values to the list
- List