Mark Stephens Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Understanding the PDF file Format – Space is a special character

54 sec read

The PDF text stream contains the instructions to draw the actual contents of the PDF. One of these instructions is the Tj command, which takes a text string. So (Hello)Tj will write the word Hello onto the PDF page at the current co-ordinate location.

Things get more interesting if you were to use (Hello World)Tj because space is a special value. When a space character is detected, some additional commands come into play. The Tw command specifies a space to be added when there is a gap between words. This allows you to have extra spacing between words for fine control over word position.

In theory you could add the Tw value when you find the value 32 (standard space value). The problem is that the character values can be mapped onto any character. So what happens if space is not a space?

In reality, you need to check that this is a genuine space by looking at the what it maps onto as a character value. If it is not a real space you need to ignore it (and of course you need to keep an eye at what the real space character is). The PDF file format can be complex at times!

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!

Mark Stephens Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Resaving Acrobat Forms in the Browser

With the removal of Acrobat Reader support in Chrome and other browsers, we have seen a big increase in the number of clients asking...
Mark Stephens
1 min read

PDF XFA – Sending data as an Email

This simple article explains how to send XFA form data as an email in two possible ways. Why does the client need to send data as...
suda
1 min read

Editing XFA files in Adobe LifeCycle to allow direct…

At IDR Solutions I spend alot of time working on XFA for our Java PDF Library and PDF to HTML5 Converter and during this...
suda
2 min read

Leave a Reply

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