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,33 +4,27 @@
using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;

//Get stream from an existing PDF document.
FileStream docStream = new FileStream(Path.GetFullPath(@"Data/input.pdf"), FileMode.Open, FileAccess.Read);

//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);

//Creates a rectangle.
RectangleF rectangle = new RectangleF(10, 40, 30, 30);

//Creates a new popup annotation.
PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(rectangle, "Test popup annotation");
popupAnnotation.Border.Width = 4;
popupAnnotation.Border.HorizontalRadius = 20;
popupAnnotation.Border.VerticalRadius = 30;

//Sets the pdf popup icon.
popupAnnotation.Icon = PdfPopupIcon.NewParagraph;

//Adds the annotation to loaded page.
loadedDocument.Pages[0].Annotations.Add(popupAnnotation);

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
//Create FileStream object to read the input PDF file
using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/input.pdf"), FileMode.Open, FileAccess.Read))
{
//Save the PDF document to file stream.
loadedDocument.Save(outputFileStream);
//Load the PDF document from the input stream
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream))
{
//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");
//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);
//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
loadedDocument.Save(outputFileStream);
}
}
}

//Close the document.
loadedDocument.Close(true);
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,39 @@
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;

//Get stream from an existing PDF document.
FileStream docStream = new FileStream(Path.GetFullPath(@"Data/imageDoc.pdf"), FileMode.Open, FileAccess.Read);

//Load the existing PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);

//Create a new compression option.
PdfCompressionOptions options = new PdfCompressionOptions();

//Enable the compress image.
options.CompressImages = true;

//Set the image quality.
options.ImageQuality = 50;

//Assign the compression option to the document
loadedDocument.Compress(options);

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
loadedDocument.Save(outputFileStream);
}

//Close the document.
loadedDocument.Close(true);
// Open a file stream to read the input PDF file.
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/imageDoc.pdf"), FileMode.Open, FileAccess.Read))
{
// Create a new PdfLoadedDocument object from the file stream.
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
{
// Create a new PdfCompressionOptions object.
PdfCompressionOptions options = new PdfCompressionOptions();

// Enable image compression and set 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);

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,41 @@
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;

//Load the PDF document.
FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Open existing PDF document as stream
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read))
{
// Load the existing PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream);

//Gets the page.
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
// Gets the first page of the document
PdfPageBase page = loadedDocument.Pages[0];

//Creates a signature field with properties.
PdfSignatureField signatureField = new PdfSignatureField(page, "SignatureField");
signatureField.Bounds = new RectangleF(0, 0, 100, 100);
signatureField.Signature = new PdfSignature();
// 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, "password123");

//Adds certificate to the signature field.
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
signatureField.Signature.Certificate = new PdfCertificate(certificateStream, "syncfusion");
signatureField.Signature.Reason = "I am author of this document";
// Create a signature
PdfSignature signature = new PdfSignature(loadedDocument, page, pdfCert, "Signature");

//Adds the field.
loadedDocument.Form.Fields.Add(signatureField);
// 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.";

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
loadedDocument.Save(outputFileStream);
}
// Load the image for the signature field
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 document to a file stream
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
loadedDocument.Save(outputFileStream);
}

//Close the document.
loadedDocument.Close(true);
//Close the document.
loadedDocument.Close(true);
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
// See https://aka.ms/new-console-template for more information

using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Interactive;

//Create a new PDF document.
PdfDocument document = new PdfDocument();
// Create a new PDF document
using (PdfDocument pdfDocument = new PdfDocument())
{
// Add a new page to the PDF document
PdfPage pdfPage = pdfDocument.Pages.Add();

//Add a new page to the PDF document.
PdfPage page = document.Pages.Add();
// Set the standard font
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16);

//Create a textbox field and add the properties.
PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName");
textBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 0, 100, 20);
textBoxField.ToolTip = "First Name";
// Draw the string "Job Application"
pdfPage.Graphics.DrawString("Job Application", font, PdfBrushes.Black, new PointF(250, 0));

//Add the form field to the document.
document.Form.Fields.Add(textBoxField);
// Change the font size for the form fields
font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
document.Save(outputFileStream);
}
// Draw the string "Name"
pdfPage.Graphics.DrawString("Name", font, PdfBrushes.Black, new PointF(10, 20));

// Create a text box field for name
PdfTextBoxField nameField = new PdfTextBoxField(pdfPage, "Name");
nameField.Bounds = new RectangleF(10, 40, 200, 20);
nameField.ToolTip = "Name";
pdfDocument.Form.Fields.Add(nameField);

//Close the document.
document.Close(true);
// Draw the string "Email address"
pdfPage.Graphics.DrawString("Email address", font, PdfBrushes.Black, new PointF(10, 80));

// Create a text box field for 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);

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
pdfDocument.Save(outputFileStream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@

//Initialize HTML to PDF converter.
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
//Set command line arugument to run without the sandbox.
blinkConverterSettings.CommandLineArguments.Add("--no-sandbox");
blinkConverterSettings.CommandLineArguments.Add("--disable-setuid-sandbox");
}
//Assign Blink converter settings to HTML converter.
htmlConverter.ConverterSettings = blinkConverterSettings;
//Convert URL to PDF document.
PdfDocument document = htmlConverter.Convert("https://www.google.com");

//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))
{
Expand Down
25 changes: 25 additions & 0 deletions Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert_Image_to_PDF", "Convert_Image_to_PDF\Convert_Image_to_PDF.csproj", "{AFAD39C6-48B5-4416-B8FD-F532728F46FC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AFAD39C6-48B5-4416-B8FD-F532728F46FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFAD39C6-48B5-4416-B8FD-F532728F46FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFAD39C6-48B5-4416-B8FD-F532728F46FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFAD39C6-48B5-4416-B8FD-F532728F46FC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {53851137-F7F3-4EFF-BA66-898C77ADF8E3}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="*" />
</ItemGroup>

</Project>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
27 changes: 27 additions & 0 deletions Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Syncfusion.Pdf;

// Create an instance of the ImageToPdfConverter class
ImageToPdfConverter 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 (FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read))
{
// Convert the image to a PDF document using the ImageToPdfConverter
PdfDocument pdfDocument = imageToPdfConverter.Convert(imageStream);

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
pdfDocument.Save(outputFileStream);
}

// Close the document
pdfDocument.Close(true);
}
Loading
Loading