public static void Run() { try { // ExStart:SuppressLocationAndReason // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures(); string inPfxFile = dataDir + "certificate.pfx"; string inFile = dataDir + "input.pdf"; string outFile = dataDir + "output.pdf"; using (Aspose.Pdf.Facades.PdfFileSignature pdfSign = new Aspose.Pdf.Facades.PdfFileSignature()) { pdfSign.BindPdf(inFile); //create a rectangle for signature location System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100); //create any of the three signature types PKCS1 signature = new PKCS1(inPfxFile, "12345"); // sign the PDF file pdfSign.Sign(1, "", "Contact", "", true, rect, signature); //save output PDF file pdfSign.Save(outFile); } // ExEnd:SuppressLocationAndReason } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { try { // ExStart:ChangeLanguageInDigitalSignText // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures(); string inPfxFile = dataDir + "certificate.pfx"; string inFile = dataDir + "input.pdf"; string outFile = dataDir + "output.pdf"; using (Aspose.Pdf.Facades.PdfFileSignature pdfSign = new Aspose.Pdf.Facades.PdfFileSignature()) { pdfSign.BindPdf(inFile); //create a rectangle for signature location System.Drawing.Rectangle rect = new System.Drawing.Rectangle(310, 45, 200, 50); //create any of the three signature types PKCS7 pkcs = new PKCS7(inPfxFile, "12345"); pkcs.Reason = "Pruebas Firma"; pkcs.ContactInfo = "Contacto Pruebas"; pkcs.Location = "Población (Provincia)"; pkcs.Date = DateTime.Now; SignatureCustomAppearance signatureCustomAppearance = new SignatureCustomAppearance(); signatureCustomAppearance.DateSignedAtLabel = "Fecha"; signatureCustomAppearance.DigitalSignedLabel = "Digitalmente firmado por"; signatureCustomAppearance.ReasonLabel = "Razón"; signatureCustomAppearance.LocationLabel = "Localización"; signatureCustomAppearance.FontFamilyName = "Arial"; signatureCustomAppearance.FontSize = 10d; signatureCustomAppearance.Culture = CultureInfo.InvariantCulture; signatureCustomAppearance.DateTimeFormat = "yyyy.MM.dd HH:mm:ss"; pkcs.CustomAppearance = signatureCustomAppearance; // sign the PDF file pdfSign.Sign(1, true, rect, pkcs); //save output PDF file pdfSign.Save(outFile); // ExEnd:ChangeLanguageInDigitalSignText } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
internal static void SignPdfDocument(string filename, string certificate, string password) { var path = $"original\\{filename}"; var certPath = $"certificates\\{certificate}"; var authority = "Υπουργείο Εσωτερικών"; var contactInfo = "Ιωάννου Κωνσταντίνος"; var location = "Αθήνα"; var reason = "ΑΠ: 4322/12"; using (Aspose.Pdf.Document doc = new Aspose.Pdf.Document(path)) { var signature = new Aspose.Pdf.Facades.PdfFileSignature(doc); // Create digital signature PKCS7 sig = new PKCS7(certPath, password); // Use PKCS7/PKCS7Detached objects sig.Authority = authority; sig.ContactInfo = contactInfo; sig.Location = location; sig.Reason = reason; sig.ShowProperties = false; // Set signature position var size = 50; var llx = doc.Pages[1].Rect.URX - size - 10; var lly = doc.Pages[1].Rect.URY - size - 10; var urx = doc.Pages[1].Rect.URX - 10; var ury = doc.Pages[1].Rect.URY - 10; var rect = new Aspose.Pdf.Rectangle(llx, lly, urx, ury); // Set signature background image var lines = new List <string>() { authority, reason, contactInfo, location }; signature.SignatureAppearanceStream = createSigningImage("sign_stamp.png", lines); // Sign the document signature.Sign(1, true, rect.ToRect(), sig); // Save output PDF file var outputPath = $"revised\\signed_{filename}"; signature.Save(outputPath); } Console.WriteLine("signed...."); }
internal static void ExportPdfFile(string filename) { try { var path = $"original\\{filename}"; var author = "Ευάγγελος Λιάτσας"; var docid = Guid.NewGuid(); var title = filename + " - Δοκιμή PDF διαχείριση"; var document = new Aspose.Pdf.Document(path); // Check for password protection var info = new Aspose.Pdf.Facades.PdfFileInfo(document); // Determine if the source PDF is encrypted if (info.IsEncrypted) { throw new Exception("The PDF file is password protected..."); } var pdfSign = new Aspose.Pdf.Facades.PdfFileSignature(document); if (pdfSign.ContainsSignature()) { var signees = pdfSign.GetSignNames(); foreach (var signee in signees) { Console.WriteLine($"Is digitally signed by {signee} ..."); } } else { // add footer to each sheet var footerText = string.Empty; if (author != null) { footerText = String.Format("Διανομή μέσω 'ΙΡΙΔΑ' με UID: {0} στις {1}", docid, DateTime.Now.ToString("dd/MM/yy HH:mm")); } // Create footer Aspose.Pdf.TextStamp textStamp = new Aspose.Pdf.TextStamp(footerText); // Set properties of the stamp textStamp.BottomMargin = 10; textStamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center; textStamp.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Bottom; // Add footer on all pages foreach (Aspose.Pdf.Page page in document.Pages) { page.AddStamp(textStamp); } Console.WriteLine("added footer ..."); } //set file metadata document.Info.Title = title; if (author != null) { document.Info.Author = author; } var final = new MemoryStream(); document.Save(final); using (FileStream file = new FileStream($"revised\\export_{filename}", FileMode.Create, System.IO.FileAccess.Write)) final.WriteTo(file); } catch (Exception exc) { Console.WriteLine(exc); } }