Skip to content
Open
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
@@ -0,0 +1,3 @@
<Solution>
<Project Path="How-to-apply-multiple-signatures-to-a-PDF-in-C#/How-to-apply-multiple-signatures-to-a-PDF-in-C#.csproj" />
</Solution>
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<None Remove="Data\Input.pdf" />
<None Remove="Data\PDF.pfx" />
<None Remove="Data\SignatureFields.pdf" />
<None Remove="Data\Student Signature.jpg" />
<None Remove="Data\Teacher Signature.png" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Data\Input.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Data\PDF.pfx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Data\SignatureFields.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Data\Student Signature.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Data\Teacher Signature.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;

namespace Create_PDF
{
class Program
{
public static void Main(string[] args)
{
//Register your Syncfusion License Key.
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Your License Key");
//Load the PDF and call the SignPDF method.
FileStream fileStream = new FileStream("Data/Input.pdf", FileMode.Open, FileAccess.ReadWrite);
MemoryStream outputStream = SignPDF(fileStream, "signature1", 0);
//Call the SignPDF method again for second signer
MemoryStream outputStream1 = SignPDF(outputStream, "signature2", 1);
//Save the final multi signed PDF document
File.WriteAllBytes(@"SignedDocument.pdf", outputStream1.ToArray());
}

public static MemoryStream SignPDF(Stream inputStream, string signatureName, int pageIndex)
{
// Load the PDF document from the input stream
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream);

// Get the specified page
PdfLoadedPage page = loadedDocument.Pages[pageIndex] as PdfLoadedPage;

// Load the certificate
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
PdfCertificate certificate = new PdfCertificate(certificateStream, "syncfusion");

// Create the signature
PdfSignature signature = new PdfSignature(loadedDocument, page, certificate, signatureName);
signature.Bounds = new Syncfusion.Drawing.RectangleF(400, 740, 90, 20);

// Choose the image based on the signature name
string imagePath = signatureName == "signature1"
? @"Data/Student Signature.jpg"
: @"Data/Teacher Signature.png";

FileStream imageStream = new FileStream(Path.GetFullPath(imagePath), FileMode.Open, FileAccess.Read);
PdfBitmap signatureImage = new PdfBitmap(imageStream);

// Draw the image in the signature appearance
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, 90, 20);

// Save the signed document to a memory stream
MemoryStream outputStream = new MemoryStream();
loadedDocument.Save(outputStream);
loadedDocument.Close(true);
outputStream.Position = 0; // Reset stream position for next use
return outputStream;
}

}
}
Loading