2

I have used tools like qpdf and pdfinfo from the poppler-utils to get information about PDF documents. However I am looking for a way to get more specific information like the width of margins, the font families used, etc. pdfinfo does not get this info and neither does qpdf. qpdf does however have a --json option which converts the PDF into its JSON representation. I am only slightly familiar with JSON but I could not find any property called "Margin" or "Font-Family". Is information like this even recorded in the PDF format?

I wasn't sure if this a question fit for this board or StackOverflow, because if there are programmatic ways to extract this information (like a C or Python library), I would be willing to use those as well. Any suggestions?

My primary aim is to be able to replicate all the margin/font information from a document (assuming they are consistent and have been made from a program like TeX or LaTeX), so I can reproduce their exact style. Right now, I have to use a facility offered by my PDF viewer using a cursor to calculate margins (or any kind of length) using coordinates and as for the fonts, I have to guess them.

1
  • 1
    PDF is a one way road, most PDF files simply don't contain the information you are looking for, it's already considered lucky if the text can be copy-pasted without errors... you'd have to render and crop detect to guess at margins (gs -sDEVICE=bbox), and use a font detection tool for much the same (for embedded fonts that don't retain any info on their origin). Sep 14, 2021 at 18:15

1 Answer 1

1

However I am looking for a way to get more specific information like the width of margins

The PDF format basically describes where to place glyphs ("letters") on the page (among other things, but that's the bulk). You can process this information yourself and from that calculate the margins, or you could render it with ghostscript etc. to an image and process that the recover margins, but "what are the margins" as such is not in the PDF. There is bounding box information, though.

the font families used

That information may or may not be in the PDF - fonts are named, but fonts can be included as a whole, and if the naming is automatic with generated names, it'll be hard to identify the font.

because if there are programmatic ways to extract this information (like a C or Python library), I would be willing to use those as well.

Have a look at mupdf which comes with a library and a CLI tool mutool. You can use this to decompress the streams inside the PDF, then you can just open the resulting file in an editor. The PDF specification is e.g. here.

My primary aim is to be able to replicate all the margin/font information from a document (assuming they are consistent and have been made from a program like TeX or LaTeX), so I can reproduce their exact style.

That is going to be extremely difficult, unless the LaTeX source is processed via a particular toolchain, and uses a particular PDF style. Though you may get lucky in identifying the fonts if you know the source is LaTeX.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .