[英]Why doesn't my Path show up when I programmatically add segments to the path in Silverlight 2?
[英]Why doesn't an Image show up when I add it to a Document using iTextSharp?
上下文:我正在打開一個包含AcroForm字段的現有交互式PDF表單。 我試圖將圖像添加到PDF表單的矩形字段中,如下所示:
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中。
您正在使用我的書籍中所述的“創建PDF文檔的5個步驟”來創建文檔。
這與您實際要執行的操作矛盾:我想在AcroForm字段定義的占位符中添加一個Image。
您為什么要說要一件事情,然后做其他事情? 甘拜下風。 可能是因為您不想閱讀文檔。
您需要這樣的東西:
回答您的問題: 為什么我的圖像沒有顯示在文檔中?
支持現有文檔中字段的坐標為:左下角x = 600,y = 600和右上角x = 700,y = 700,那么您將圖像添加到頁面可見區域之外重新創建。 當您使用new Document();
,您正在創建一個文檔,其左下角為x = 0,y = 0,右上角為x = 595,y = 842。
在這種情況下,您要將圖像添加到文檔中,但是它不可見,因為您已將其添加到定義頁面的矩形之外。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.