我需要在线将PDF用户的签名(例如您在信用卡上的签名)添加到PDF文档中。我该怎么做?这类任务的最佳实践是什么?
答案 0 :(得分:5)
您可以使用iTextSharp来执行此操作。这样的东西对你有用:
PdfReader pdfReader = null;
PdfStamper pdfStamper = null;
// Open the PDF file to be signed
pdfReader = new PdfReader(this.signFile.FullName);
// Output stream to write the stamped PDF to
using (FileStream outStream = new FileStream(targetFilename, FileMode.Create))
{
try
{
// Stamper to stamp the PDF with a signature
pdfStamper = new PdfStamper(pdfReader, outStream);
// Load signature image
iTextSharp.text.Image sigImg = iTextSharp.text.Image.GetInstance(SIGNATURE_IMAGE_PATH);
// Scale image to fit
sigImg.ScaleToFit(MAX_WIDTH, MAX_HEIGHT);
// Set signature position on page
sigImg.SetAbsolutePosition(POS_X, POS_X);
// Add signatures to desired page
PdfContentByte over = pdfStamper.GetOverContent(PAGE_NUM_TO_SIGN);
over.AddImage(sigImg);
}
finally
{
// Clean up
if (pdfStamper != null)
pdfStamper.Close();
if (pdfReader != null)
pdfReader.Close();
}
}
答案 1 :(得分:3)
您需要使用JavaScript实现某些操作。你可以使用一些JQuery插件。这是一个例子;
http://motyar.blogspot.com/2010/01/draw-with-jquery.html
对于pdf部分,您可以使用一些pdf转换工具,如ITextSharp