How to insert invisible text into a PDF?

前端 未结 3 1144
-上瘾入骨i
-上瘾入骨i 2020-12-21 09:22

UPDATE: Please see https://softwarerecs.stackexchange.com/questions/71464/java-library-to-insert-invisible-text-into-a-pdf instead.

I want to insert invisible text i

相关标签:
3条回答
  • 2020-12-21 09:53

    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.

    0 讨论(0)
  • 2020-12-21 10:01

    3 options. My answers are itext-specific, but you should be able to translate the underlying methods to any sufficiently advance PDF library.

    1. Text render mode 3: "No stroke, no fill". With iText: myPdfContentByte.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE);
    2. Draw the text behind something. You're presumably using scanned page images. iText myPdfStamper.getUnderContent(pageNum) makes this easy, and will let you draw the text under the scan. Other libraries that let you access a page's contents might require you to add your text 'in the raw' at the beginning of an existing content stream. You'll want to check out the "PDF Spec" (google that, you'll be fine) for details. Chapter 9 is all about text rendering.
    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.
    0 讨论(0)
  • 2020-12-21 10:13

    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.

    0 讨论(0)
提交回复
热议问题