我已經進行了全面搜索,但所有檔案都側重于 Java 答案,這些答案在 .NET 版本中沒有相同的方法。我正在嘗試將影像插入 PDF 上的特定位置,但無法正確插入它們。我可以獲得準確的 X/Y 坐標,但是當它插入 PDF 時,它只將它們全部插入到第一頁。
我還發現高度和寬度與他們要替換的欄位不一樣。我的監視視窗中的變數顯示正確的高度和寬度,但它最終在 PDF 上被壓縮。當我使用它時,這不是 itextSharp 的問題。
var widgets = toSet.GetWidgets(); // toSet is the field to get position from
Rectangle position = widgets[0].GetRectangle().ToRectangle();
PdfPage page = widgets[0].GetPage();
if (position == null)
{
throw new ApplicationException("Error locating field");
}
// set bottom left corner and width/height of field
float width = position.GetWidth();
float height = position.GetHeight();
float llx = position.GetX();
float lly = position.GetY();
// resize signature image, set position of bottom left corner to x and y coordinates
image.ScaleToFit(width, height);
image.SetFixedPosition(llx, lly);// I want to put the page number in this method override
doc.Add(image);
image.SetFixedPosition() 方法有一個覆寫整數頁碼,但我無法以編程方式從欄位中找到頁碼。它還迫使我設定寬度,我想保持寬度與我設定的高度成比例。
uj5u.com熱心網友回復:
確定頁碼
根據您的代碼,您已經有一個頁面物件,PdfPage page,并且正在檔案中尋找它的頁碼。您可以使用該PdfDocument方法
public virtual int GetPageNumber(PdfPage page)
為了那個原因。
僅設定影像的目標頁碼
此外,您有一個影像物件,Image image并且只想為其設定頁面。您可以使用該Image方法
public virtual Image SetPageNumber(int pageNumber)
為了那個原因。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/428364.html
下一篇:ExceptionConverter:java.io.IOException:嘗試使用iText創建PDF時流已關閉
