Search code examples
phpbackgroundpdflib

PDFlib library PHP background image


I'm using PDFlib library PHP to write PDF.

Can I put an image as a background for a whole page? If so, how can I do it?


Solution

  • In general you should do something like this:

    $image = $p->load_image("auto", $imagefile, "");
    if ($image == 0) {
        die("Error: " .  $p->get_errmsg());
    }
    $p->begin_page_ext(0, 0, "width=595 height=842");
    $p->fit_image($image 0, 0, "boxsize { 595 842} fitmethod=entire");
    

    If you do this before placing the text in the PDF you will get it as background image.

    You may have a look at http://www.pdflib.com/pdflib-cookbook/images/ for more image related examples and check chapter 7.3 in the documentation "PDFlib-tutorial.pdf".