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.

3 reasons why PDF commands inside a PDF matter

1 min read

A PDF file consists of instructions to draw the page onto a screen. This is normally done by a computer program so it places a great deal of importance on how well written the drawing code is. The PDF file format includes a wide range of commands so that the key difference is often how well the drawing program makes use of different commands.

I was examining a PDF file last week which included a square box drawn with rounded corners. The PDF file format includes commands to draw lines and circle segments, so it can be draw with 4 line commands and 4 curve commands. Curves have start and end points and control points so they are easy to construct and change. This shape did not use curve commands though and instead used 200 line commands – the corners were drawn as a set of tiny lines which look like a curve. This matters for 3 reasons:-

1. It actually makes it harder to draw a smooth line. With a curve, the renderer can optimise the curve which is not possible with lots of smaller lines.

2. It makes a larger, slower file. The file is much larger and it will render slower.

3. The file is much harder to edit. Instead of 1 curve, you would need to hack the file if you wanted to alter the corners.

So you end up with the worst of all worlds – larger, slower files which are much harder to edit. How good are your PDF files?

This post is part of our “Understanding the PDF File Format” series. In each article, we discuss a PDF feature, bug, gotcha or tip. 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!

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

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.

Leave a Reply

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

IDRsolutions Ltd 2019. All rights reserved.