在 iText 中页面大小不同的 pdf 文件中插入水印时出现问题
当我尝试在绝对位置添加图像作为水印时,绝对 X=10f 且绝对 y =矩形.getLeft()+ (rectangle.getWidth()-image.getPlainWidth());
对于某些页面大小,在绝对 X=10f 时不会添加图像,必须将其增加到 300f 或更高。如何正确获取左侧的绝对位置。
When I am trying to add a image as watermark at absolute position while absoluteX=10f and absolute y = rectangle.getLeft()+ (rectangle.getWidth()-image.getPlainWidth());
For some page-sizes, the image does not get added at absoluteX=10f have to increase it to 300f or more. How to correctly fetch the absolute position for the left.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要检查页面的裁剪框并相对于该框放置文本。另请注意,左下角不必为 0,0,并且页面可以旋转。
我见过以三种方式生成横向页面:
11"x8.5"
8.5x11 @ 90 度
8.5x11 @ 270 度
(幸运的是,我从未见过 11x8.5 @ 180 度,否则我可能不得不在一般原则上严重伤害某人)
“肖像”页面几乎普遍生成为 8.5“x11”(或任何您的测量值)是)。在我的>使用 PDF 十年了,我还没有看到旋转的纵向页面。合法,但愚蠢。
因此,为了获得正确的框并将文本旋转到位,您需要类似的东西:
我经常发现我必须将页面大小放大相当多才能找出我的转换出了问题的地方。对媒体框上的每个边框说+1000(如果存在则进行裁剪)。
现在,当你搞砸了你的转变时(我不可避免地会这样做),你将能够看到你是如何搞砸的,并修复它。
You need to check the page's crop box and position your text relative to that. Note also that the bottom left corner need not be 0,0, and that pages can be rotated.
I've seen landscape pages generated three ways:
11"x8.5"
8.5x11 @ 90 degrees
8.5x11 @ 270 degrees
(fortunately I've never seen 11x8.5 @ 180, or I might have to Severely Harm someone on general principles)
"Portrait" pages are nigh-universally generated as 8.5"x11" (or whatever your measurements might be). In my > a decade working with PDF, I have yet to see a rotated portrait page. Legal, but stupid.
So, to get your correct bbox and rotate your text into position, you'd need something like:
I often find I have to blow the page size up by Quite A Bit in order to find out where I'm going wrong with my transformations. Say +1000 to each border on the media box (and crop if present).
Now, when you screw up your transformations (I inevitably do), you'll be able to see HOW you screwed up, and fix it.