PHP/PDF/Pdf Lib

Материал из Web эксперт
Перейти к: навигация, поиск

A Skeleton PDF Document Using PDFLib

 
<?php
    define("PAGE_WIDTH", 612);
    define("PAGE_HEIGHT", 792);
    $pdf = pdf_new();
    pdf_begin_document($pdf, "", "");
    pdf_begin_page($pdf, PAGE_WIDTH, PAGE_HEIGHT);
    /* Code to display content in the page here */
    pdf_end_page($pdf);
    pdf_end_document($pdf, "");
    $data = pdf_get_buffer($pdf);
    header("Content-type: application/pdf");
    header("Content-disposition: inline; filename=example1.pdf");
    header("Content-length: " . strlen($data));
    echo $data;
?>



Defining Patterns in PDFLib

 
<?php
    define("PAGE_WIDTH", 612);
    define("PAGE_HEIGHT", 792);
    $pdf = pdf_new();
    pdf_begin_document($pdf, "", "");
    $pattern = pdf_begin_pattern($pdf, 21, 21, 22, 22, 1);
    pdf_setcolor($pdf, "stroke", "rgb", 0.0, 0.0, 1.0, 0);
    pdf_circle($pdf, 11, 11, 10);
    pdf_stroke($pdf);
    pdf_end_pattern($pdf);
    pdf_begin_page($pdf, PAGE_WIDTH, PAGE_HEIGHT);
    pdf_setcolor($pdf, "fill", "pattern", $pattern, 0, 0, 0);
    pdf_circle($pdf, PAGE_WIDTH/2, PAGE_HEIGHT/2, 150);
    pdf_fill_stroke($pdf);
    pdf_end_page($pdf);
    pdf_end_document($pdf, "");
    $data = pdf_get_buffer($pdf);
    header("Content-type: application/pdf");
    header("Content-disposition: inline; filename=mypdf.pdf");
    header("Content-length: " . strlen($data));
    echo $data;
?>



"Hello, World!" Using PDFLib

 
<?php
    define("PAGE_WIDTH", 612);
    define("PAGE_HEIGHT", 792);
    $pdf = pdf_new();
    pdf_begin_document($pdf, "", "");
    pdf_begin_page($pdf, PAGE_WIDTH, PAGE_HEIGHT);
    $font = pdf_findfont($pdf, "Helvetica", "auto", false);
    pdf_setfont($pdf, $font, 30);
    pdf_show_xy($pdf, "PHP Unleashed", 10, PAGE_HEIGHT-40);
    pdf_setfont($pdf, $font, 12);
    pdf_show_xy($pdf, "Hello, World!", 10,PAGE_HEIGHT-55);
    pdf_end_page($pdf);
    pdf_end_document($pdf, "");
    $data = pdf_get_buffer($pdf);
    header("Content-type: application/pdf");
    header("Content-disposition: inline; filename=mypdf.pdf");
    header("Content-length: " . strlen($data));
    echo $data;
?>