在 itext 2 中,下面的代码运行良好,在 itext 5 中它失败了。有没有人有如何将图像添加到 PDF 上的图像字段的示例?
这是我的代码...
public static void atsSetFieldImage(AcroFields form, PdfStamper stamper, String fieldName, Image img)
{
try
{
float[] photograph = form.getFieldPositions(fieldName);
Rectangle rect = new Rectangle(photograph[1]
, photograph[2]
, photograph[3]
, photograph[4]);
//Image img = Image.getInstance(imageName);
image1.scaleToFit(rect.getWidth(), rect.getHeight());
image1.setAbsolutePosition(
photograph[1] + (rect.getWidth() - image1.getScaledWidth()) / 2
, photograph[2] + (rect.getHeight() - image1.getScaledHeight()) / 2);
PdfContentByte cb = stamper.getOverContent((int)photograph[0]);
cb.addImage(image1);
}
catch(Exception e)
{
//e.printStackTrace();
}
}