Skip to content

Commit 6542a4f

Browse files
Merge pull request #212 from SyncfusionExamples/989216
989216: Modified the interactive sample code and readme files.
2 parents e2cc2df + 778c855 commit 6542a4f

File tree

34 files changed

+549
-805
lines changed
  • Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document
  • Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document
  • Digital Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document
  • Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document
  • Getting Started/.NET/Create_PDF_NET/Create_PDF_NET
  • HTML to PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document
  • Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF
  • Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream
  • OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document
  • PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document
  • Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages
  • Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document
  • Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document
  • Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF
  • Tagged PDF/Add-tag-for-the-text-element-in-PDF-document/.NET/Add-tag-for-the-text-element-in-PDF-document
  • Text Extraction/Extract-text-from-the-entire-PDF-document/.NET/Extract-text-from-the-entire-PDF-document
  • Watermark/Add-text-watermark-in-an-existing-PDF-document/.NET/Add-text-watermark-in-an-existing-PDF-document

34 files changed

+549
-805
lines changed

Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/Program.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44
using Syncfusion.Pdf.Interactive;
55
using Syncfusion.Pdf.Parsing;
66

7-
//Load the PDF document.
7+
//Load the PDF document
88
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
99
{
10-
1110
//Get the first page of the PDF document
1211
PdfPageBase loadedPage = loadedDocument.Pages[0];
1312
//Create a new popup annotation
14-
PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(100, 100, 20, 20), "Comment");
13+
PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(100, 100, 20, 20), "popup annotation");
1514
//Set the icon for the popup annotation
1615
popupAnnotation.Icon = PdfPopupIcon.Comment;
1716
//Set the color for the popup annotation
1817
popupAnnotation.Color = new PdfColor(Color.Yellow);
1918
//Add the annotation to the page
2019
loadedPage.Annotations.Add(popupAnnotation);
21-
2220
//Save the PDF document
2321
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
24-
}
22+
}

Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/README.md

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PDF Annotations
22

3-
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.
3+
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.
44

55
## Steps to add annotations to a PDF
66

@@ -12,43 +12,34 @@ Step 2. **Install NuGet package**: Add the [Syncfusion.Pdf.Net.Core](https://www
1212

1313
Step 3. **Include necessary namespaces**: Add the following namespaces to your `Program.cs` file:
1414

15-
```csharp
16-
using Syncfusion.Drawing;
17-
using Syncfusion.Pdf;
18-
using Syncfusion.Pdf.Graphics;
19-
using Syncfusion.Pdf.Interactive;
20-
using Syncfusion.Pdf.Parsing;
21-
```
15+
```csharp
16+
using Syncfusion.Drawing;
17+
using Syncfusion.Pdf;
18+
using Syncfusion.Pdf.Graphics;
19+
using Syncfusion.Pdf.Interactive;
20+
using Syncfusion.Pdf.Parsing;
21+
```
2222

2323
Step 4. **Code to add annotations**: Use the following code snippet in `Program.cs` to insert annotations into a PDF file:
2424

25-
```csharp
26-
// Create a FileStream object to read the input PDF file
27-
using (FileStream inputFileStream = new FileStream("input.pdf", FileMode.Open, FileAccess.Read))
28-
{
29-
// Load the PDF document from the input stream
30-
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream))
31-
{
32-
// Access the first page of the PDF document
33-
PdfPageBase loadedPage = loadedDocument.Pages[0];
34-
35-
// Create a new popup annotation
36-
PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(100, 100, 20, 20), "Comment");
37-
// Set the icon for the popup annotation
38-
popupAnnotation.Icon = PdfPopupIcon.Comment;
39-
// Set the color for the popup annotation
40-
popupAnnotation.Color = new PdfColor(Color.Yellow);
41-
// Add the annotation to the page
42-
loadedPage.Annotations.Add(popupAnnotation);
43-
44-
// Save the updated document
45-
using (FileStream outputFileStream = new FileStream("output.pdf", FileMode.Create, FileAccess.Write))
46-
{
47-
loadedDocument.Save(outputFileStream);
48-
}
49-
}
50-
}
51-
```
25+
```csharp
26+
//Load the PDF document
27+
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
28+
{
29+
//Get the first page of the PDF document
30+
PdfPageBase loadedPage = loadedDocument.Pages[0];
31+
//Create a new popup annotation
32+
PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(100, 100, 20, 20), "popup annotation");
33+
//Set the icon for the popup annotation
34+
popupAnnotation.Icon = PdfPopupIcon.Comment;
35+
//Set the color for the popup annotation
36+
popupAnnotation.Color = new PdfColor(Color.Yellow);
37+
//Add the annotation to the page
38+
loadedPage.Annotations.Add(popupAnnotation);
39+
//Save the PDF document
40+
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
41+
}
42+
```
5243

5344
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).
5445

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
using Syncfusion.Pdf;
22
using Syncfusion.Pdf.Parsing;
33

4-
//Load the PDF document.
4+
//Load the PDF document
55
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
66
{
7-
// Create a new PdfCompressionOptions object.
7+
// Create a new PdfCompressionOptions object
88
PdfCompressionOptions options = new PdfCompressionOptions();
9-
10-
//Enable the compress image.
9+
//Enable the compress image
1110
options.CompressImages = true;
12-
13-
//Set the image quality.
11+
//Set the image quality
1412
options.ImageQuality = 50;
15-
16-
// Compress the PDF document.
13+
// Compress the PDF document
1714
loadedDocument.Compress(options);
18-
1915
//Save the PDF document
2016
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
2117
}

Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/README.md

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Compressing PDF Files
22

3-
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.
3+
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.
44

55
## Steps to compress PDF files
66

@@ -12,47 +12,29 @@ Step 2: **Install the NuGet package**: Add the [Syncfusion.Pdf.Net.Core](https:/
1212

1313
Step 3: **Add required namespaces**: Include the following namespaces in your `Program.cs` file:
1414

15-
```csharp
15+
```csharp
1616
using Syncfusion.Pdf.Parsing;
1717
using Syncfusion.Pdf;
18-
```
18+
```
1919

2020
Step 4: **Implement PDF compression**: Use the following code snippet in `Program.cs` to compress PDF files:
2121

22-
```csharp
23-
// Open a file stream to read the input PDF file
24-
using (FileStream fileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
25-
{
26-
// Load the PDF document from the file stream
27-
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
28-
{
29-
// Create a new PdfCompressionOptions object
30-
PdfCompressionOptions options = new PdfCompressionOptions();
31-
32-
// Enable image compression and set the image quality
33-
options.CompressImages = true;
34-
options.ImageQuality = 50;
35-
36-
// Enable font optimization
37-
options.OptimizeFont = true;
38-
39-
// Enable page content optimization
40-
options.OptimizePageContents = true;
41-
42-
// Remove metadata from the PDF
43-
options.RemoveMetadata = true;
44-
45-
// Compress the PDF document
46-
loadedDocument.Compress(options);
47-
48-
// Save the document into a memory stream
49-
using (MemoryStream outputStream = new MemoryStream())
50-
{
51-
loadedDocument.Save(outputStream);
52-
}
53-
}
54-
}
55-
```
22+
```csharp
23+
//Load the PDF document
24+
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
25+
{
26+
// Create a new PdfCompressionOptions object
27+
PdfCompressionOptions options = new PdfCompressionOptions();
28+
//Enable the compress image
29+
options.CompressImages = true;
30+
//Set the image quality
31+
options.ImageQuality = 50;
32+
// Compress the PDF document
33+
loadedDocument.Compress(options);
34+
//Save the PDF document
35+
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
36+
}
37+
```
5638

5739
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).
5840

Original file line numberDiff line numberDiff line change
@@ -1,39 +1,29 @@
11
using Syncfusion.Drawing;
22
using Syncfusion.Pdf;
33
using Syncfusion.Pdf.Graphics;
4-
using Syncfusion.Pdf.Interactive;
54
using Syncfusion.Pdf.Parsing;
65
using Syncfusion.Pdf.Security;
76

8-
//Open existing PDF document
7+
//Load the PDF document
98
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"Data/Input.pdf"))
109
{
1110
// Gets the first page of the document
1211
PdfPageBase page = loadedDocument.Pages[0];
13-
1412
// Load the certificate from a PFX file with a private key
15-
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
16-
PdfCertificate pdfCert = new PdfCertificate(certificateStream, "syncfusion");
17-
13+
PdfCertificate pdfCert = new PdfCertificate(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion");
1814
// Create a signature
1915
PdfSignature signature = new PdfSignature(loadedDocument, page, pdfCert, "Signature");
20-
2116
// Set signature information
2217
signature.Bounds = new RectangleF(227.6355f, 675.795044f, 150.57901f, 32.58f);
2318
signature.SignedName = "Syncfusion";
2419
signature.ContactInfo = "[email protected]";
2520
signature.LocationInfo = "Honolulu, Hawaii";
2621
signature.Reason = "I am the author of this document.";
27-
2822
// Load the image for the signature field
29-
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
23+
using FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
3024
PdfBitmap signatureImage = new PdfBitmap(imageStream);
31-
3225
// Draw the image on the signature field
3326
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, new RectangleF(0, 0, signature.Bounds.Width, signature.Bounds.Height));
34-
3527
// Save the PDF document
36-
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
37-
certificateStream.Dispose();
38-
imageStream.Dispose();
28+
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
3929
}

Digital Signature/Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document/README.md

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,52 @@
11
# Digital Signature
22

3-
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.
3+
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.
44

55
## Steps to add a digital signature to PDF files
66

7-
Follow these steps to digitally sign PDF files using the Syncfusion&reg; library:
7+
Follow these steps to digitally sign PDF files using the Syncfusion<sup>&reg;</sup> library:
88

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

1111
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/).
1212

1313
Step 3: **Include necessary namespaces**: Add the following namespaces in your `Program.cs` file:
1414

15-
```csharp
16-
using Syncfusion.Pdf;
17-
using Syncfusion.Pdf.Graphics;
18-
using Syncfusion.Pdf.Parsing;
19-
using Syncfusion.Pdf.Security;
20-
using Syncfusion.Drawing;
21-
using Syncfusion.Pdf.Interactive;
22-
```
15+
```csharp
16+
using Syncfusion.Drawing;
17+
using Syncfusion.Pdf;
18+
using Syncfusion.Pdf.Graphics;
19+
using Syncfusion.Pdf.Parsing;
20+
using Syncfusion.Pdf.Security;
21+
```
2322

2423
Step 4: **Add digital signature code**: Use the following code snippet in `Program.cs` to add a digital signature to a PDF file:
2524

26-
```csharp
27-
// Open the existing PDF document as a stream
28-
using (FileStream inputStream = new FileStream(Path.GetFullPath("Input.pdf"), FileMode.Open, FileAccess.Read))
29-
{
30-
// Load the existing PDF document
31-
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream);
32-
33-
// Get the first page of the document
34-
PdfPageBase page = loadedDocument.Pages[0];
35-
36-
// Load the certificate from a PFX file with a private key
37-
FileStream certificateStream = new FileStream(@"PDF.pfx", FileMode.Open, FileAccess.Read);
38-
PdfCertificate pdfCert = new PdfCertificate(certificateStream, "syncfusion");
39-
40-
// Create a signature
41-
PdfSignature signature = new PdfSignature(loadedDocument, page, pdfCert, "Signature");
42-
43-
// Set signature information
44-
signature.Bounds = new RectangleF(new PointF(0, 0), new SizeF(200, 100));
45-
signature.ContactInfo = "[email protected]";
46-
signature.LocationInfo = "Honolulu, Hawaii";
47-
signature.Reason = "I am the author of this document.";
48-
49-
// Load the image for the signature field
50-
FileStream imageStream = new FileStream("signature.png", FileMode.Open, FileAccess.Read);
51-
PdfBitmap signatureImage = new PdfBitmap(imageStream);
52-
53-
// Draw the image on the signature field
54-
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, new RectangleF(0, 0, signature.Bounds.Width, signature.Bounds.Height));
55-
56-
// Save the document to a file stream
57-
using (FileStream outputFileStream = new FileStream("signed.pdf", FileMode.Create, FileAccess.ReadWrite))
58-
{
59-
loadedDocument.Save(outputFileStream);
60-
}
61-
62-
// Close the document
63-
loadedDocument.Close(true);
64-
certificateStream.Dispose();
65-
imageStream.Dispose();
66-
}
67-
```
25+
```csharp
26+
//Load the PDF document
27+
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"Data/Input.pdf"))
28+
{
29+
// Gets the first page of the document
30+
PdfPageBase page = loadedDocument.Pages[0];
31+
// Load the certificate from a PFX file with a private key
32+
PdfCertificate pdfCert = new PdfCertificate(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion");
33+
// Create a signature
34+
PdfSignature signature = new PdfSignature(loadedDocument, page, pdfCert, "Signature");
35+
// Set signature information
36+
signature.Bounds = new RectangleF(227.6355f, 675.795044f, 150.57901f, 32.58f);
37+
signature.SignedName = "Syncfusion";
38+
signature.ContactInfo = "[email protected]";
39+
signature.LocationInfo = "Honolulu, Hawaii";
40+
signature.Reason = "I am the author of this document.";
41+
// Load the image for the signature field
42+
using FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
43+
PdfBitmap signatureImage = new PdfBitmap(imageStream);
44+
// Draw the image on the signature field
45+
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, new RectangleF(0, 0, signature.Bounds.Width, signature.Bounds.Height));
46+
// Save the PDF document
47+
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
48+
}
49+
```
6850

6951
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/).
7052

0 commit comments

Comments
 (0)