How to insert invisible text into a PDF?

二次信任 提交于 2019-12-18 08:59:21

问题


I want to insert invisible text into an existing PDF file, to make it searchable.

What library should I use?
I would appreciate links to specific API methods to use.

Free, ideally open source.
Thanks a lot!

(For the curious: I want to automatically OCR incoming scanned papers and make them searcheable, in an Alfresco repository)


回答1:


3 options.

  1. Text render mode 3: "No stroke, no fill". myPdfContentByte.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE);
  2. Draw the text behind something. You've presumably got scanned images of the pages. iText's myPdfStamper.getUnderContent(pageNum) will let you draw the text under the scan.
  3. Draw the text outside the page's media or crop box. If you just want some random PDF-savvy search engine to turn up your page this will work, but if you want people looking at the PDF to see the appropriate text selection box... not so much.



回答2:


This shows how to create a PDF document containing text and this shows how to add an image. Add the text first and then add the image on top of it - the text will become 'invisible' to the end user but will remain searchable by search engines. This may also be useful.




回答3:


You do not have to render the text invisible. Just render them in the appropriate place but overlay the scanned image on the text. Or, you could render the text over the image and set alpha value of the color of the the stroke and brush to zero.



来源:https://stackoverflow.com/questions/5138286/how-to-insert-invisible-text-into-a-pdf

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