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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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<sup>&reg;</sup> [.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

Expand All @@ -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).

Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Compressing PDF Files

The Syncfusion&reg; [.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<sup>&reg;</sup> [.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

Expand All @@ -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).

Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]";
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"));
}
Original file line number Diff line number Diff line change
@@ -1,70 +1,52 @@
# Digital Signature

The Syncfusion&reg; [.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<sup>&reg;</sup> [.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&reg; library:
Follow these steps to digitally sign PDF files using the Syncfusion<sup>&reg;</sup> library:

Step 1: **Create a new project**: Start by creating a new C# Console Application project.

Step 2: **Install the NuGet package**: Add the [Syncfusion.Pdf.Net.Core](https://www.nuget.org/packages/Syncfusion.Pdf.Net.Core/) package to your project from [NuGet.org](https://www.nuget.org/).

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 = "[email protected]";
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 = "[email protected]";
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/).

Expand Down
Loading
Loading