我已经搜索了所有这些文档,但是所有的文档都集中在.NET版本中没有相同方法的Java上。我试图将图片插入到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()方法具有接受整数页号的覆盖,但我无法编程地从字段中找到页码。它也迫使我设置一个宽度,我想保持宽度与高度成比例,这是我正在设置的。
发布于 2022-02-18 13:47:13
确定页码
根据您的代码,您已经有了一个页面对象PdfPage page
,并且正在文档中查找它的页码。您可以使用PdfDocument
方法
public virtual int GetPageNumber(PdfPage page)
就为了这个。
只设置图像的目标页码
另外,您还有一个图像对象Image image
,并且只想为它设置页面。您可以使用Image
方法
public virtual Image SetPageNumber(int pageNumber)
就为了这个。
https://stackoverflow.com/questions/71164716
复制相似问题