Hudzilla.org - the homepage of Paul Hudson
Contents > Multimedia > Creating PDF documents Wish List | Report Bug | About Me ]

11.4.6     Adding document data: pdf_add_note(), pdf_set_info()

This is NOT the latest copy of this book; click here for the latest version.

bool pdf_add_note ( resource pdfdoc, float lowerleft_y, float lowerleft_y, float upperright_x, float upperright_y, string contents, string title, string icon, int open)

bool pdf_set_info ( resource pdfdoc, string key, string value)

Owing to the fact that PDFs are designed to be read like normal, printed documents, Adobe have incorporated into the PDF format 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 use:

pdf_add_note($pdf, 100, 500, 700, 600, "You can create notes very 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 co-ordinates, and the upper-right X and upper-right Y co-ordinates 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. Note that once the PDF is loaded, your reader is often free to move these notes around and edit the text inside them.

So, in the line above, we add a 600x100 note box which 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 of pdf_set_info(), which takes a key and a value as its second and third parameters. The standard keys for use as "Subject", "Title", "Creator", "Author", and "Keywords", but you are also able to add your own keys such as "Modified", "Created", etc.

Now we can finish off our script by adding in some meta-data - add these three lines just below pdf_open_file() and save the modified version as pdf5.php:

pdf_set_info($pdf, "Creator", "TelRev");
pdf_set_info($pdf, "Title", "PHP PDF 101");
pdf_set_info($pdf, "MyInfo", "You can write what you please here");

When you read the PDF generated by pdf5.php you should see the note sticking out quite obviously. The meta-data will be there too, but it is likely to be hidden away under a menu somewhere.





<< 11.4.5 PDF special effects: pdf_rotate() and pdf_skew()   11.4.7 PDF Conclusion >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Be the first to add a comment to this chapter!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is nine plus zero?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow