上下文:我打開一個包含AcroForm字段的現有交互式PDF表單。我試圖圖像中的PDF表單中添加一個矩形場是這樣的:爲什麼使用iTextSharp將圖像添加到文檔時不顯示圖像?
string path = HttpContext.Current.Server.MapPath("includes");
string newFile = HttpContext.Current.Server.MapPath("Tmp") + "/completed_gray" +".pdf";
string imagepath = HttpContext.Current.Server.MapPath("Tmp");
Document doc = new Document();
try {
PdfWriter.GetInstance(doc, new FileStream(newFile, FileMode.Open));
doc.Open();
iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(imagepath + "/CUstomRep_Eng_Col_1_V1.png");
iTextSharp.text.Rectangle rect = pdfStamper.AcroFields.GetFieldPositions("img_1_space")[0].position;
gif.ScaleAbsolute(rect.Width, rect.Height);
gif.SetAbsolutePosition(rect.Left, rect.Bottom);
doc.Add(gif);
}
catch (Exception ex) {
//Log error;
}
finally {
doc.Close();
}
在生成的PDF圖像不顯示。
請閱讀關於一些格式問題和http://meta.stackexchange.com/questions/10647/how-do-i-write-a-good-title –
我syour問題 - 你看到一個錯誤?什麼是錯誤信息? – criticalfix
此外:你說你正在填寫一個現有的PDF,你正在使用Document和PdfWriter類?很明顯,你沒有閱讀文檔,否則,你會使用PdfStamper! –