【问题标题】:Place image at bottom left corner of pdf with iText使用 iText 将图像放在 pdf 的左下角
【发布时间】:2016-11-30 14:28:39
【问题描述】:

我在将图像放置在 PDF 文档的左下角时遇到了一些问题。

这是我的代码:

 PdfReader reader = new PdfReader("source.pdf");
 PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(pdfTarget));

 Image qrImg = Image.getInstance("qrcode.png");
 qrImg.setAbsolutePosition(0,0);

 // place the image at the i-th page
 PdfContentByte content = stamper.getOverContent(i);
 content.addImage(qrImg);

这适用于我尝试过的几乎所有 pdf 文档,除非您可以在此处找到单个文档:https://ufile.io/50016

对于本文档,左下角从 (50,50) 开始,因此绝对位置应为 (50,50),这对于所有其他 pdf 都不正确。

我找不到将图像放置在 (0,0) 或任何其他固定绝对位置的方法,导致始终将其放置在左下角。 有什么建议吗?

【问题讨论】:

    标签: image pdf position itext coordinates


    【解决方案1】:

    Pdf 文档使用名为 MediaBox 的键来描述页面。这是页面的原始大小。还有一个名为 CropBox 的键定义了页面的可见区域。在您的文档中,裁剪框从 54,55.4 开始,这是您必须应用到图像的偏移量。检查PdfReader.getCropBox() 以获取尺寸。

    【讨论】:

    • 这就是我所需要的。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 2022-01-08
    • 1970-01-01
    • 2017-12-19
    • 1970-01-01
    • 2014-10-01
    相关资源
    最近更新 更多