如何在PDF中查找图像并在其上绘制其他图像 [英] How to find images in a PDF and draw another on top of it

查看:64
本文介绍了如何在PDF中查找图像并在其上绘制其他图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将Word文档转换为PDF的程序.转换后,我想在新的PDF中找到所有图像.如果图像具有特定尺寸(200x100),则我想在其顶部绘制另一个图像.更好的是,如果我可以创建一个签名字段并在其上方绘制.

请帮忙吗?

解决方案

请首先尝试以下示例: RenderListener 接口的实现. >

要满足您的要求,您应该编写自己的 RenderListener 实现,更具体地说,是一种为您提供图像坐标的方法. iText将通过 ImageRenderInfo 对象为您提供这些坐标,更具体地讲,是 Matrix 对象,该对象由 getCTM() 方法.可以使用普通的高中代数来解释该矩阵. I31和I32给您X和Y位置.在大多数情况下,I11和I22会为您提供宽度和高度(除非图像旋转).

一旦有了X,Y,宽度和高度,绘制任何想要的东西就很容易.如果要添加签名字段,请阅读我编写的数字签名手册.

I have a program that convert Word docs to PDFs. After conversion, I want to find all images in the new PDF. If the image is of a specific dimension (200x100), then I want to draw another image on top of it. Better yet, if I can create a signature field and draw on top of it.

Any help please?

解决方案

First try this example: ExtractImages

I know this example doesn't do what you need, but take a look at the MyImageRenderListener class that is used. This is an implementation of the RenderListener interface.

To meet your requirement, you should write your own RenderListener implementation, more specifically one that gives you the coordinates of the images. iText will give you these coordinates through the ImageRenderInfo object, more specifically as a Matrix object returned by the getCTM() method. This matrix can be interpreted using ordinary high-school algebra. I31 and I32 give you the X and Y position. In most cases I11 and I22 will give you the width and the height (unless the image is rotated).

Once you have X, Y, width and height, drawing whatever you want is easy. If you want to add a signature field, please read the digital signatures manual I wrote.

这篇关于如何在PDF中查找图像并在其上绘制其他图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆