Section 17.5. Adding Document Data


17.5. 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 of pdf_set_info( ), which takes a key and a value as its second and third parameters. The standard keys for use are 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 metadataadd these three lines just below pdf_open_file( ):

     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 the finished script, you should see the note sticking out quite obviously. The metadata will be there too, but it is likely to be hidden away under a menu somewhere.



PHP in a Nutshell
Ubuntu Unleashed
ISBN: 596100671
EAN: 2147483647
Year: 2003
Pages: 249

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net