Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
تتيح لك فئة PdfFileSignature إضافة توقيع في ملف PDF. تحتاج إلى إنشاء كائن من فئة PdfFileSignature باستخدام ملفات PDF المدخلة والمخرجة. تحتاج أيضًا إلى إنشاء كائن Rectangle في المكان الذي تريد إضافة التوقيع فيه، ومن أجل ضبط المظهر يمكنك تحديد صورة باستخدام خاصية SignatureAppearance لكائن PdfFileSignature. توفر Aspose.Pdf.Facades أيضًا أنواعًا مختلفة من التوقيعات مثل PKCS#1 و PKCS#7 و PKCS#7Detached. لإنشاء توقيع من نوع معين، تحتاج إلى إنشاء كائن من الفئة المحددة مثل PKCS1 أو PKCS7 أو PKCS7Detached باستخدام ملف الشهادة وكلمة المرور.
بمجرد إنشاء كائن من نوع توقيع معين، يمكنك استخدام طريقة Sign لفئة PdfFileSignature لتوقيع ملف PDF وتمرير كائن التوقيع المحدد إلى هذه الفئة. يمكنك أيضًا تحديد خصائص أخرى لهذه الطريقة. أخيرًا، تحتاج إلى حفظ ملف PDF الموقع باستخدام طريقة Save لفئة PdfFileSignature. يوضح الكود التالي كيفية إضافة توقيع في ملف PDF.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddPdfFileSignature()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
using (var pdFileSignature = new Aspose.Pdf.Facades.PdfFileSignature())
{
// Bind PDF document
pdFileSignature.BindPdf(dataDir + "input.pdf");
// Create a rectangle for signature location
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(10, 10, 300, 50);
// Set signature appearance
pdFileSignature.SignatureAppearance = dataDir + "aspose-logo.png";
// Create any of the three signature types
var signature = new PKCS1(dataDir + "rsa_cert.pfx", "12345"); // PKCS#1
pdFileSignature.Sign(1, "I'm document author", "test01@aspose-pdf-demo.local", "Aspose Pdf Demo, Australia", true, rect, signature);
// Save PDF document
pdFileSignature.Save(dataDir + "DigitallySign_out.pdf");
}
}
يوضح مثال الكود التالي القدرة على توقيع مستند بتوقيعين. في مثالنا، وضعنا التوقيع الأول على الصفحة الأولى، والثاني على الصفحة الثانية. يمكنك تحديد الصفحات التي تحتاجها.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddTwoSignature()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
using (var pdFileSignature = new Aspose.Pdf.Facades.PdfFileSignature())
{
// Bind PDF document
pdFileSignature.BindPdf(dataDir + "input.pdf");
// Create a rectangle for 1st signature location
System.Drawing.Rectangle rect1 = new System.Drawing.Rectangle(10, 10, 300, 50);
// Create 1st signature object
var signature1 = new Aspose.Pdf.Forms.PKCS1(dataDir + "rsa_cert.pfx", "12345"); // PKCS#1
pdFileSignature.Sign(1, "I'm document author", "test@aspose-pdf-demo.local", "Aspose Pdf Demo, Australia", true, rect1, signature1);
pdFileSignature.Save(dataDir + "DigitallySign_out.pdf");
// Sign with 2nd signature
// Bind PDF document
pdFileSignature.BindPdf(dataDir + "DigitallySign_out.pdf");
// Create a rectangle for 2nd signature location
System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(10, 10, 300, 50);
// Create 2nd signature object
var signature2 = new Aspose.Pdf.Forms.PKCS1(dataDir + "rsa_cert.pfx", "12345"); // PKCS#1
pdFileSignature.Sign(2, "I'm document reviewer", "test02@aspose-pdf-demo.local", "Aspose Pdf Demo, Australia", true, rect2, signature2);
// Save PDF document
pdFileSignature.Save(dataDir + "DigitallySign2_out.pdf");
}
}
للمستندات التي تحتوي على نماذج أو أكروفورمز تحتاج إلى توقيع، انظر المثال التالي. تحتاج إلى إنشاء كائن من فئة PdfFileSignature باستخدام ملفات PDF المدخلة والمخرجة. استخدم BindPdf للربط. أنشئ توقيعًا مع القدرة على إضافة الخصائص المطلوبة. في مثالنا، هي ‘Reason’ و ‘CustomAppearance’.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddPdfFileSignatureField()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
using (var pdFileSignature = new Aspose.Pdf.Facades.PdfFileSignature())
{
// Bind PDF document
pdFileSignature.BindPdf(dataDir + "input.pdf");
// Create any of the three signature types
var signature = new Aspose.Pdf.Forms.PKCS1(dataDir + "rsa_cert.pfx", "12345")
{
Reason = "Sign as Author",
CustomAppearance = new Aspose.Pdf.Forms.SignatureCustomAppearance
{
FontSize = 6,
FontFamilyName = "Calibri"
}
}; // PKCS#1
pdFileSignature.Sign("Signature1", signature);
// Save PDF document
pdFileSignature.Save(dataDir + "DigitallySign_out.pdf");
}
}
إذا كان مستندنا يحتوي على حقلين، فإن خوارزمية توقيعه مشابهة للمثال الأول.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddPdfFileSignatureField2()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
using (var pdFileSignature = new Aspose.Pdf.Facades.PdfFileSignature())
{
// Bind PDF document
pdfFileSignature.BindPdf(dataDir + "input.pdf");
// Create any of the three signature types
var signature1 = new Aspose.Pdf.Forms.PKCS1(dataDir + "rsa_cert.pfx", "12345")
{
Reason = "Sign as Author",
CustomAppearance = new Aspose.Pdf.Forms.SignatureCustomAppearance
{
FontSize = 6
}
}; // PKCS#1
pdFileSignature.Sign("Signature1", signature1);
// Save PDF document
pdFileSignature.Save(dataDir + "DigitallySign_out.pdf");
// Bind PDF document
pdFileSignature.BindPdf(dataDir + "DigitallySign_out.pdf");
// Create any of the three signature types
var signature2 = new Aspose.Pdf.Forms.PKCS1(dataDir + "rsa_cert.pfx", "12345")
{
Reason = "Sign as Reviwer",
CustomAppearance = new SignatureCustomAppearance
{
FontSize = 6
}
}; // PKCS#1
pdFileSignature.Sign("Signature2", signature2);
// Save PDF document
pdFileSignature.Save(dataDir + "DigitallySign2_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.