2016-06-01 104 views
-1

问题修订和澄清(感谢布鲁诺指向我在正确的方向) -使用占位符将预定义位置的图片添加到现有的pdf表单中。

这篇文章最初是在严重睡眠剥夺和阅读后,我看到它可能会混淆。我想确保其他人将来可以使用这种解决方案,而不必花费大量时间来解决这个问题。

这是我的问题,下面有答案解决它。 我有一个pdf格式,我需要添加一个图像到一个特定的位置,我已经把一个占位符。我怎样才能做到这一点?

+0

迈克尔,你正在做一些令人难以置信的错误,违背所有常识(甚至可能违反PAdES-6)。您*滥用*数字签名字段添加签名的光栅图像而不应用数字签名。如果有人以当前状态回答你的问题,那么这个人可能是你试图欺骗你的客户的同谋。因此,请澄清您的问题:您为什么要用非数字签名的图像替换数字签名字段? –

+0

我当然不是想做错事。我对此有点新,并且非常感激你会引导我走向正确的方向。我想我大大误解了这个解决方案。 http://stackoverflow.com/questions/20660839/add-signature-image-on-pdf-without-digitally-signing-it-using-itextsharp。我试图完成的是采取从我的通过Topaz签名板或(移动)JSignature字段应用。一旦数字签名,我试图将其存储在硬拷贝形式。如果我阅读你的电子签名书,它是否会涵盖这种合法性? –

+0

@MichaelHoward PDF AcroForm签名字段最初设计用于基于X.509证书,PKI等的数字签名,而不是用于图像。从同时存在基于PKI的数字签名的法律框架的角度来看,您的方法可能会有问题。然而在我看来,只要所有人都意识到使用签名图像替换签名域的PDF不具有比使用Photoshop粘贴某些签名图像的文档图像更合法的价值,那么就没有问题了。 – mkl

回答

0

仅适用于未来可能正在寻找关于如何将预定义的特定位置图像添加到已有的.pdf表单中的答案的人,以下是答案。

  //This codes works for those who have a pre-created pdf form with a button in the location and size you want your image. 
        //I reccomend acrobat pro, thought it has a monthly cost. There are additional free PDF editors 
        //instantiate a new PdfStamper that will create a new file from my existing form. The Reader reads in your template and the stamper makes a copy 
    //FileToPath and FileFromPath are strings i created above that hold the path     
    using (PdfStamper stamper = new PdfStamper(new PdfReader(fileFromPath), File.Create(FileToPath"))) 
        { 
         //get my buttons positions current location and height btn1 is the name of my button that exists in the pdf already 
         AcroFields.FieldPosition fieldPosition = stamper.AcroFields.GetFieldPositions("btn1")[0]; 
         //create a new button utilze the field position to set it's location. FYI this is a rectangle. I reccomend you read about those 
         //it will save you tons of time to understand them. 
         PushbuttonField imageField = new 
//btn1Replaced is what I named the new button that will overwrite the old place holder button 
PushbuttonField(stamper.Writer, fieldPosition.position, "btn1Replaced"); 
         //Here I set they layout from my old button to my new one 
         imageField.Layout = PushbuttonField.LAYOUT_ICON_ONLY; 
         //grab the image you want in your pdf imgPath is a string I wrone above to grab the image 
         iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance("imgPath"); 
         //set your buttons image property to be your image you just grabbed 
         imageField.Image = img; 
         //always scale to the size of the button 
         imageField.ScaleIcon = PushbuttonField.SCALE_ICON_ALWAYS; 
         imageField.ProportionalIcon = false; 
         //make sure your button is read only and then it will not act like a button, it will act like an image. 
         imageField.Options = BaseField.READ_ONLY; 
         //Get rid of the old button 
         stamper.AcroFields.RemoveField("btn1"); 
         //add my button and make sure it is on the correct page 
         stamper.AddAnnotation(imageField.Field, fieldPosition.page); 

         stamper.Close();