【问题标题】:How to resize the image in pdf using iText.layout如何使用 iText.layout 调整 pdf 中的图像大小
【发布时间】:2021-08-12 06:56:07
【问题描述】:

我想在生成的 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);

现在它看起来像 image1。我想要标题左侧的小图标。

image1

【问题讨论】:

  • 看起来您使用的是 itext 7。在这种情况下,您应该添加 itext7 标记。话虽这么说,通过将AutoScale 设置为true,您告诉itext 忽略您的scaleAbsolute 呼叫,不是吗?

标签: java pdf itext


【解决方案1】:

首先,确保您使用的是com.itextpdf.text.Image 类。 我认为您没有使用 itext 类。

这将是使用 Image 类的 itext 的正确方法:

Image img = Image.getInstance("Path to your image");
img.scaleAbsolute(150,50);

【讨论】:

  • 您似乎使用 itext 5。操作似乎使用 itext 7。
猜你喜欢
  • 1970-01-01
  • 2021-08-30
  • 1970-01-01
  • 1970-01-01
  • 2021-04-20
  • 2014-05-19
  • 2021-05-18
  • 2019-10-23
  • 2015-06-20
相关资源
最近更新 更多