PDFBOX, Reading a pdf line by line and extracting text properties

耗尽温柔 提交于 2019-12-01 14:40:38

extract the text properties such as bold,italic, from each line. How can I achieve this with pdfbox library

Properties such as bold and italic are not first-class properties in a PDF.

Bold or italic writing in PDFs is achieved either using

  • different fonts (which is the better way); in this case one can try to determine whether or not the fonts are bold or italic by

    • looking at the font name: it may contain a substring "bold", "italic", "oblique"...

    • looking at some optional properties of the font, e.g. font weight...

    • inspecting embedded font file.

    Neither of these methods is fool-proof; or

  • using the same font as for non-bold, non-italic text but using special techniques to make them appear bold or italic (aka poor man's bold), e.g.

    • not only filling the glyph contours but also drawing a thicker line along it for a bold impression,

    • drawing the glyph twice, the second time slightly displaced, also for a bold impression,

    • using a text or transformation matrix to slant the letters for an italic impression.

By overriding the PDFTextStripper methods with such tests accordingly, you may achieve a fairly good guess rate for styles during PDF text extraction.

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