How to find images in a PDF and draw another on top of it

非 Y 不嫁゛ 提交于 2020-01-25 01:22:28

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/15639593/how-to-find-images-in-a-pdf-and-draw-another-on-top-of-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!