-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
908771_ug: volume 3 UG documentations revamped samples.
- Loading branch information
1 parent
edb1ceb
commit 574e461
Showing
7 changed files
with
14 additions
and
73 deletions.
There are no files selected for viewing
Binary file modified
BIN
+6.3 KB
(140%)
...documents-externally/.NET/Create-LTV-when-signing-PDF-documents-externally/Data/Input.pdf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+22.9 KB
Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/Input.pdf
Binary file not shown.
Binary file removed
BIN
-2.78 KB
Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/PDF.pfx
Binary file not shown.
Binary file removed
BIN
-20.9 KB
...Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/syncfusion_logo.png
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 10 additions & 41 deletions
51
Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,26 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
using Syncfusion.Drawing; | ||
using Syncfusion.Pdf; | ||
using Syncfusion.Pdf.Graphics; | ||
using Syncfusion.Pdf.Parsing; | ||
using Syncfusion.Pdf.Security; | ||
|
||
//Creates a new PDF document. | ||
PdfDocument document = new PdfDocument(); | ||
|
||
//Adds a new page. | ||
PdfPageBase page = document.Pages.Add(); | ||
|
||
//Create graphics for the page. | ||
PdfGraphics graphics = page.Graphics; | ||
|
||
//Creates a certificate instance from PFX file with private key. | ||
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read); | ||
PdfCertificate pdfCert = new PdfCertificate(certificateStream, "DigitalPass123"); | ||
|
||
//Creates a digital signature. | ||
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature"); | ||
signature.Settings.CryptographicStandard = CryptographicStandard.CADES; | ||
signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA256; | ||
|
||
|
||
//Sets an image for signature field. | ||
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/syncfusion_logo.png"), FileMode.Open, FileAccess.Read); | ||
|
||
//Sets an image for signature field. | ||
PdfBitmap image = new PdfBitmap(imageStream); | ||
|
||
//Adds time stamp by using the server URI and credentials. | ||
signature.TimeStampServer = new TimeStampServer(new Uri("http://time.certum.pl/ ")); | ||
//Get the stream from the document. | ||
FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); | ||
//Load an existing PDF document. | ||
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); | ||
//Gets the first signature field of the PDF document | ||
PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; | ||
PdfSignature signature = signatureField.Signature; | ||
|
||
//Enable LTV on Signature. | ||
signature.EnableLtv = true; | ||
|
||
//Sets signature info. | ||
signature.Bounds = new RectangleF(new PointF(0, 0), image.PhysicalDimension); | ||
signature.ContactInfo = "[email protected]"; | ||
signature.LocationInfo = "Honolulu, Hawaii"; | ||
signature.Reason = "I am author of this document."; | ||
|
||
//Draws the signature image. | ||
signature.Appearance.Normal.Graphics.DrawImage(image, 0, 0); | ||
|
||
//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); | ||
loadedDocument.Save(outputFileStream); | ||
} | ||
|
||
//Close the document. | ||
document.Close(true); | ||
loadedDocument.Close(true); | ||
|