Page 1 of 1

[RESOLVED] Make PDF API

Posted: Thu May 28, 2015 7:43 pm
by xtianos
Folks,

Out of ambition I guess, could anyone point me to a tutorial where I can learn how to write my own PHP API to create my own PDFs? I realize that there are multiple APIs available out there; however, I would like to learn how to create my own so I can increase my knowledge of PHP and of any other additional languages I might need to learn in the process. Thanks in advance.

Re: Make PDF API

Posted: Thu May 28, 2015 8:04 pm
by requinix
Exactly how "create my own" do you mean? Learning how to construct a PDF byte by byte? Or learning how to use a third-party converter?

The former will suck. The latter is what everybody else does.

Re: Make PDF API

Posted: Thu May 28, 2015 11:52 pm
by xtianos
It would be the former.

Re: Make PDF API

Posted: Fri May 29, 2015 3:23 am
by requinix
Alrighty.

I don't know PDFs personally but I've done stuff like this before. First step is locating the PDF specification, which has changed over time so there's a few versions and no doubt some in development. Read through and understand the gist of it. I then start writing classes for the various structures within - nothing fancy, basically just member variables to hold data. Then basic code like constructors and some helper methods.
The goal is to generate a small PDF with a couple words in it. Simplest of simple. Then add support for things as you go.

Re: Make PDF API

Posted: Fri May 29, 2015 8:55 am
by xtianos
Roger that! I guess now it's time to hunt down the ISO specification. Thanks for the help.

Re: [RESOLVED] Make PDF API

Posted: Fri May 29, 2015 2:15 pm
by Christopher
There are two parts to this design:

1. The design of the code that holds the data representation of the PDF internally and allows operations to that data.

2. The design of the code that writes the data to a file.

3. The design of the API the programmer uses to access the library.

Evolving toward good designs is going to be important. You might want to look at existing PDF libraries to see what they have done. And since the PDF spec is so large, you need to support a common subset of features first and then keep adding support.

And then there is the whole issue of reading PDFs that involves multiple header, bodies and trailers ...