java如何使用iText在pdf中调整图像大小。布局
我想在生成的pdf文件中,除了标题之外,再添加一个应用程序的徽标。我使用下面的代码这样做,但图像没有缩小。感谢您的帮助
// Creating Paragraphs
String heading = "Declaration Letter";
Paragraph head = new Paragraph(heading).setBold().setFontSize(20);
Paragraph paragraph1 = new Paragraph();
paragraph1.add("This is to certify that the Product Serial Number ");
// Adding paragraphs to document
ImageData data = ImageDataFactory.create("img.png");
Image image = new Image(data);
// set Absolute Position
//image.setFixedPosition(450f, 10f);
image.scaleAbsolute(20f, 20f);
// set Scaling
image.setAutoScaleHeight(true);
image.setAutoScaleWidth(true);
document.add(image);
document.add(head);
document.add(space);
document.add(space);
document.add(paragraph1);
现在看起来像是图1。我想要标题左边的小图标
# 1 楼答案
首先,确保您使用的是
com.itextpdf.text.Image
类。 我认为您没有使用itext
类对于
itext
的Image
类,这将是正确的方法: