Page 295 - Open Soource Technologies 304.indd
P. 295

Unit 12: Portable Document Format



            12.2.1 Initializing the Document                                                      Notes
            In above Example, we started by calling pdf_new( ), to create a new PDF data structure, followed
            by pdf_open_file( ) , to open a new document. pdf_open_file( ) takes an optional second argument
            that, when set, specifies the filename to which to write the PDF data:
            pdf_open_file(pdf [, filename ]);
            The output of pdf_open_file( ) is sent to stdout if the filename is “-”. If no filename argument
            is provided, the PDF data is written to a memory buffer, which can later be fetched by calling
            pdf_get_buffer( ). The latter approach is the one we used in above Example.
            12.2.2 Setting Metadata

            The pdf_set_info( ) function inserts information fields into the PDF file:
            pdf_set_info(pdf, fieldname, value);
            There are five standard field names: Subject, Author, Title, Creator, and Keywords. You can
            also add arbitrary information fields.
            In addition to informational fields, the pdflib library has various parameters that you can change
            with pdf_get_parameter( ) and pdf_set_parameter( ):
            $value = pdf_get_parameter(pdf, name); pdf_set_parameter(pdf, name, value);
            A useful parameter to set is openaction, which lets you specify the zoom (magnification) of
            the file when it’s opened. The values “fitpage”, “fitwidth”, and “fitheight” fit the file to the
            complete page, the width of the page, and the height of the page, respectively. If you don’t set
            open action, your document is displayed at whatever zoom the viewer had set at the time the
            document was opened.
            12.2.3 Creating a Page

            A page starts with a call to pdf_begin_page ( ) and ends with a call to pdf_end_page ( ):
            pdf_end_page(pdf);
            You specify the paper size in points in the call to pdf_begin_page ( ). Table 12.1 shows some
            typical sizes.

                                        Table 12.1: Paper Sizes


                                   Page format   Width   Height
                                   US-Letter     612     792
                                   US-Legal      612     1008
                                   US-Ledger     1224    792
                                   11 x 17       792     1224
                                   A0            2380    3368
                                   A1            1684    2380
                                   A2            1190    1684
                                   A3            842     1190
                                   A4            595     842
                                   A5            421     595
                                   A6            297     421
                                   B5            501     709



                                             LOVELY PROFESSIONAL UNIVERSITY                                   289
   290   291   292   293   294   295   296   297   298   299   300