Adding Document Data

PDFs are designed to be read like normal printed documents, so Adobe incorporated the ability to add notes in the same manner one might scribble in a margin.

These notes, which can be edited and re-edited by readers, can also be created using PHP by calling the function pdf_add_note(). Here is an example of its use:

    pdf_add_note($pdf, 100, 500, 700, 600, "You can create notes easily
            using pdf_add_note()", "Sticky notes", "note", 1);

The second, third, fourth, and fifth parameters are, respectively, the lower-left X and lower-left Y coordinates, and the upper-right X and upper-right Y coordinates of the note boundaries. The sixth and seventh parameters are the text to put inside the note and the title to place at the top, and the final two parameters decide the icon used to display the note when closed, and whether or not the note starts open. Once the PDF is loaded, your reader is usually free to move these notes around and edit the text inside them.

In the line above, we add a 600x100 note box that is already open (use 1 to specify the note is open, and 0 to specify it is closed). Instead of note as the penultimate parameter, we have various other options: comment, insert, paragraph, newparagraph, key, or help. In several PDF readers, this parameter has no effect and can be just left as note.

Another important facet to improving the usefulness of documents is to provide meta-data regarding who created the document, and when. This can be achieved through the use ...

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.