Приглашаем посетить
CSS (css.find-info.ru)

Section 17.2.  Adding More Pages and More Style

Previous
Table of Contents
Next

17.2. Adding More Pages and More Style

Adding more pages is done by calling pdf_begin_page( ) and pdf_end_page( ) repeatedly, like this:

    for ($i = 1; $i < 10; ++$i) {
            pdf_begin_page($pdf, 595, 842);
            pdf_setfont($pdf, $font, 30);
            pdf_show_xy($pdf, "This is page $i", 50, 750);
            pdf_end_page($pdf);
    }

A good start is to have a selection of typefaces ready for various parts of your document. In our first example, we have just oneTimes-Roman is stored in $font. However, that could be easily modified to this:

    $times = pdf_findfont($pdf, "Times-Roman", "host");
    $timesb = pdf_findfont($pdf, "Times-Bold", "host");
    $timesi = pdf_findfont($pdf, "Times-Italic", "host");

Combined with the use of pdf_setfont( )'s third parameter, we can create headers and subheaders like this:

    for ($i = 1; $i < 10; ++$i) {
            pdf_begin_page($pdf, 595, 842);

            pdf_setfont($pdf, $times, 24);
            pdf_show_xy($pdf, "This is page $i", 50, 750);

            pdf_setfont($pdf, $timesb, 16);
            pdf_show_xy($pdf, "Subheader", 100, 700);

            pdf_setfont($pdf, $timesi, 16);
            pdf_show_xy($pdf, "This is some standard text.", 100, 700);

            pdf_end_page($pdf);
    }

We can even throw in the pdf_setcolor( ) function, which takes two text values followed by color values for its fourth, fifth, sixth, and (optionally) its seventh parameters, and uses them to set the color of fills and objects that follow.

Try adding this line just before the first pdf_setfont( )...

    pdf_setcolor($pdf, "both", "rgb", 1.0 - (0.1 * $i), 0.0, 0.0);

And adding this line just before the second pdf_setfont( )...

    pdf_setcolor($pdf, "both", "rgb", 0.0, 0.0, 0.0 + (0.1 * $i));

The "both" in there means "Set both fill and stroke color" (recommended most of the time), and the "rgb" means "We're going to provide red, green, and blue values for the value." If you'd rather provide CMYK, specify "cmyk" instead of "rgb" and add the extra color value. The PDF generated from that code should have a top header that starts off red and fades into black, and a second-level header and main text that starts off black and fades into blue.


Previous
Table of Contents
Next