Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

PDF Text – An Overview

1 min read


PDF text is a subject which causes much confusion. People look at PDF files and they are a fantastic way to present content. If setup correctly, you can be sure they will appear exactly as you intended (with none of that horrid wrong formatting you get in Microsoft Word if the user does not have your fonts). They are secure, self-contained and cross-platform.

The problem comes with extraction. People look at the text layout. Because the human eye is very good at working out the flow of the page, they assume that this information is all in the file.

The PDF file is really a form of Vector graphic – it contains a whole load of commands to draw shapes, images and text. So long as the end result looks correct that is the key requirement. Often the text will be in the correct order but there is no guarantee. Nothing in PDF specification enforces any standardization.

Complex structures such as tables exist because your brain perceives them on the finished document – there is nothing describing them in the PDF beyond a set of draw String commands at certain locations.

I was sent a PDF file once created with a tool which obviously started life as a plotter. With a plotter, the slowest activity is to change the pen on the plotter, so where possible you try to draw all the black lines first, then change the pen. In this PDF, all the bold text on the page was drawn first, and then the rest, font by font. It looked perfect to view, but it was very messy inside.

You can extract text from PDF files , but you have to allow for all of these possibilities and there is no heuristics capable of handling all the possible options. The more general you make the algorithm the less able it becomes. In our software we took the decision to try and provide some solutions focused on specific tasks (ie keywords, tables, flowing text). Many times this works perfectly, but it is always a guessing game.

If you are creating PDF files and want the text to be extracted, you should use Adobe’s Structured Content feature. This does include tagging information in the PDF making it possible to extract a perfect XML version of the page – but it needs to be switched on to be in the file.

Otherwise, remember that a PDF is essentially a Vector graphic and while it may look perfectly structured, that the structure is probably your brains perception of the picture and not in the file.

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

Did you know...

IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?

It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Enabling SVG Gzip Compression on Apache and NGINX

Gzip compression is a widely supported method of reducing the size of the content sent from a web server in order to improve the...
Leon Atherton
47 sec read

One Reply to “PDF Text – An Overview”

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2020. All rights reserved.