chika Chika is a sales and marketing specialist at IDR Solutions, focusing on business opportunities, client relationships and product promotion. She represents the company at conferences and industry events, where she speaks about PDF document solutions for Java developers. In her free time she enjoy Pilates, content creation and bible study sessions with friends.

Updated Create a Non-Working PDF

1 min read


Part 3: Create a Non-Working PDF (click to expand)

In the previous article of this series, we learn to use a text editor to structure and create a PDF file. The only problem with the PDF we are going to make is that it is not going to work. It will however give us an error message we can understand in Acrobat PDF viewer. This is going to form the basis for creating a working PDF file in the posts that follow. The ingredients you require are: a text editor, a hex editor (I’m going to use HxD) and a at least partially functioning human brain. Preferably your own.

We are going to create all the parts I mentioned in the last article in a text editor and figure out the address of the things we put in our file using the HxD. We can also see what error messages we can produce from Acrobat.

Firstly I’m gonna make a new blank file called myPdf.pdf. Just because I can I’m gonna load it in Acrobat to see what it says:

“Adobe Reader could not open ‘myPdf.pdf’ because it is either not a supported file type or because the file has been damaged.”

Hardly surprising, but if you get this message from a supposedly working PDF in the future you can be sure its a bit knackered.

Now I’m adding the header part, which only requires a version number in the form: %PDF-2.0. Next we have the body sections where all the objects go. For this section we’re just have one object: Object number 1 and its going to be a dictionary object (that we are not going to put anything in…yet!).

%PDF-2.0
1 0 obj << >>
endobj

Next we want the Cross Reference Table section. First we need the xref keyword. Then the number of the first object in our list and the amount of objects in our file. So far we have two objects: 1 0 obj that is in our body section and object 0 which is the head of the linked list that I described in Part 2. So we end up with a line with 0 2 on it.

xref
0 2
0000000000 65535 f
0000000010 00000 n

Next you need the final part which is the trailer section:

trailer << /Size 2 /Root 1 0 R >>
startxref
33
%%EOF

If you open this in Acrobat you’ll get a different kind of error. If you hold down Ctrl while clicking OK you see another part of the error message: “Expected a dict object.”




Our software libraries allow you to

Convert PDF files to HTML
Use PDF Forms in a web browser
Convert PDF Documents to an image
Work with PDF Documents in Java
Read and write HEIC and other Image formats in Java
chika Chika is a sales and marketing specialist at IDR Solutions, focusing on business opportunities, client relationships and product promotion. She represents the company at conferences and industry events, where she speaks about PDF document solutions for Java developers. In her free time she enjoy Pilates, content creation and bible study sessions with friends.

Updated Part 6: Graphics State

Part 6: Graphics State (click to expand) It would be nice to get some color on the screen this time round and in doing...
chika
1 min read

Updated Part 5: Path Objects

Part 5: Path Objects (click to expand) A PDF is drawn using a load of commands that sit in stream objects. With these commands...
chika
1 min read

Updated Part 4: Hello World PDF

Part 4: Hello World PDF (click to expand) Back when dinosaurs roamed the earth I talked about the different objects that are used to...
chika
1 min read