Exemplo n.º 1
1
<?php

$p = PDF_new();
PDF_open_file($p);
PDF_set_info($p, "Creator", "coords.php");
PDF_set_info($p, "Author", "Rasmus Lerdorf");
PDF_set_info($p, "Title", "Coordinate Test (PHP)");
PDF_begin_page($p, 595, 842);
PDF_translate($p, 0, 842);
// Move Origin
PDF_scale($p, 1, -1);
// Reflect across horizontal axis
PDF_set_value($p, "horizscaling", -100);
// Mirror
$font = PDF_findfont($p, "Helvetica-Bold", "host", 0);
PDF_setfont($p, $font, -38.0);
PDF_show_xy($p, "Top Left", 10, 40);
PDF_end_page($p);
PDF_set_parameter($p, "openaction", "fitpage");
PDF_close($p);
$buf = PDF_get_buffer($p);
$len = strlen($buf);
Header("Content-type:application/pdf");
Header("Content-Length:{$len}");
Header("Content-Disposition:inline; filename=coords.pdf");
echo $buf;
PDF_delete($p);
Exemplo n.º 2
1
<?php

$p = PDF_new();
/*  open new PDF file; insert a file name to create the PDF on disk */
if (PDF_begin_document($p, "", "") == 0) {
    die("Error: " . PDF_get_errmsg($p));
}
PDF_set_info($p, "Creator", "hello.php");
PDF_set_info($p, "Author", "Rainer Schaaf");
PDF_set_info($p, "Title", "Hello world (PHP)!");
PDF_begin_page_ext($p, 595, 842, "");
$font = PDF_load_font($p, "Helvetica-Bold", "winansi", "");
PDF_setfont($p, $font, 24.0);
PDF_set_text_pos($p, 50, 700);
PDF_show($p, "Hello world!");
PDF_continue_text($p, "(says PHP)");
PDF_end_page_ext($p, "");
PDF_end_document($p, "");
$buf = PDF_get_buffer($p);
$len = strlen($buf);
header("Content-type: application/pdf");
header("Content-Length: {$len}");
header("Content-Disposition: inline; filename=hello.pdf");
print $buf;
PDF_delete($p);
Exemplo n.º 3
0
 function OpenFile()
 {
     $caminho = 'tmp/';
     $lim_dir = opendir('tmp/');
     $fonte = APP_ROOT . DS . 'arquivos/fontes/FreeMonoBold.ttf';
     while ($lim_file = readdir($lim_dir)) {
         if ($lim_file != '.' && $lim_file != '..') {
             if (!substr_count($lim_file, date('Y-m-d'))) {
                 @unlink('tmp/' . $lim_file);
             }
         }
     }
     $caminho .= date('Y-m-d') . '-';
     list($usec, $sec) = explode(' ', microtime());
     $caminho .= substr(md5($usec . $sec), 0, 8);
     $caminho .= '.pdf';
     $this->caminho = APP_ROOT . DS . $caminho;
     $this->LinkArquivo = $caminho;
     $this->pdf = PDF_new();
     pdf_set_parameter($this->pdf, 'FontOutline', 'monospaced=' . $fonte);
     PDF_open_file($this->pdf, $this->caminho);
     PDF_set_info($this->pdf, 'Creator', $this->owner);
     PDF_set_info($this->pdf, 'Author', $this->owner);
     PDF_set_info($this->pdf, 'Title', $this->titulo);
     if ($this->depurar) {
         echo '<b>PDF:</b> Objeto criado!<br>';
         echo '<b>PDF:</b> O objeto foi criado no seguinte local -> ' . $this->LinkArquivo . '<br>';
     }
     $this->OpenPage();
 }
Exemplo n.º 4
0
 * A little PDFlib application to draw an analog clock.
 *
 */
$RADIUS = 200.0;
$MARGIN = 20.0;
$p = PDF_new();
/* create a new PDFlib object */
/*  open new PDF file; insert a file name to create the PDF on disk */
if (PDF_open_file($p, "") == 0) {
    die("Error: " . PDF_get_errmsg($p));
}
/* This line is required to avoid problems on Japanese systems */
PDF_set_parameter($p, "hypertextencoding", "winansi");
PDF_set_info($p, "Creator", "pdfclock.php");
PDF_set_info($p, "Author", "Rainer Schaaf");
PDF_set_info($p, "Title", "PDF clock (PHP)");
/* start a new page     */
PDF_begin_page($p, 2 * ($RADIUS + $MARGIN), 2 * ($RADIUS + $MARGIN));
PDF_translate($p, $RADIUS + $MARGIN, $RADIUS + $MARGIN);
PDF_setcolor($p, "fillstroke", "rgb", 0.0, 0.0, 1.0, 0.0);
PDF_save($p);
/* minute strokes */
PDF_setlinewidth($p, 2.0);
for ($alpha = 0; $alpha < 360; $alpha += 6) {
    PDF_rotate($p, 6.0);
    PDF_moveto($p, $RADIUS, 0.0);
    PDF_lineto($p, $RADIUS - $MARGIN / 3, 0.0);
    PDF_stroke($p);
}
PDF_restore($p);
PDF_save($p);
Exemplo n.º 5
0
define("YINCR", 2 * FONTSIZE);
define("XINCR", 2 * FONTSIZE);
/* create a new PDFlib object */
$p = PDF_new();
/* open new PDF file */
if (PDF_open_file($p, "") == 0) {
    die("Error: " . PDF_get_errmsg($p));
}
PDF_set_parameter($p, "openaction", "fitpage");
PDF_set_parameter($p, "fontwarning", "true");
PDF_set_parameter($p, "SearchPath", $searchpath);
/* This line is required to avoid problems on Japanese systems */
PDF_set_parameter($p, "hypertextencoding", "winansi");
PDF_set_info($p, "Creator", "chartab.php");
PDF_set_info($p, "Author", "Thomas Merz");
PDF_set_info($p, "Title", "Character table (PHP)");
/* loop over all encodings */
for ($page = 0; $page < count($encodings); $page++) {
    PDF_begin_page($p, 595, 842);
    /* start a new page */
    /* print the heading and generate the bookmark */
    $font = PDF_load_font($p, "Helvetica", "winansi", "");
    PDF_setfont($p, $font, FONTSIZE);
    $buf = sprintf("%s (%s) %sembedded", $fontname, $encodings[$page], $embed ? "" : "not ");
    PDF_show_xy($p, $buf, LEFT - XINCR, TOP + 3 * YINCR);
    PDF_add_bookmark($p, $buf, 0, 0);
    /* print the row and column captions */
    PDF_setfont($p, $font, 2 * FONTSIZE / 3);
    for ($row = 0; $row < 16; $row++) {
        $buf = sprintf("x%X", $row);
        PDF_show_xy($p, $buf, LEFT + $row * XINCR, TOP + YINCR);
Exemplo n.º 6
0
# $Id: image.php 14574 2005-10-29 16:27:43Z bonefish $
/* This is where font/image/PDF input files live. Adjust as necessary. */
$searchpath = "../data";
$p = PDF_new();
/* create a new PDFlib object */
PDF_set_parameter($p, "SearchPath", $searchpath);
/*  open new PDF file; insert a file name to create the PDF on disk */
if (PDF_open_file($p, "") == 0) {
    die("Error: " . PDF_get_errmsg($p));
}
/* This line is required to avoid problems on Japanese systems */
PDF_set_parameter($p, "hypertextencoding", "winansi");
PDF_set_info($p, "Creator", "image.php");
PDF_set_info($p, "Author", "Rainer Schaaf");
PDF_set_info($p, "Title", "image sample (PHP)");
$imagefile = "nesrin.jpg";
$image = PDF_load_image($p, "auto", $imagefile, "");
if (!$image) {
    die("Error: " . PDF_get_errmsg($p));
}
/* dummy page size, will be adjusted by PDF_fit_image() */
PDF_begin_page($p, 10, 10);
PDF_fit_image($p, $image, 0, 0, "adjustpage");
PDF_close_image($p, $image);
PDF_end_page($p);
/* close page           */
PDF_close($p);
/* close PDF document   */
$buf = PDF_get_buffer($p);
$len = strlen($buf);
Exemplo n.º 7
0
 * Note that this directory must also contain the LuciduxSans font outline
 * and metrics files.
 */
$searchpath = "../data";
$data = array("name" => "Victor Kraxi", "business.title" => "Chief Paper Officer", "business.address.line1" => "17, Aviation Road", "business.address.city" => "Paperfield", "business.telephone.voice" => "phone +1 234 567-89", "business.telephone.fax" => "fax +1 234 567-98", "business.email" => "*****@*****.**", "business.homepage" => "www.kraxi.com");
$p = PDF_new();
/*  open new PDF file; insert a file name to create the PDF on disk */
if (PDF_open_file($p, "") == 0) {
    die("Error: " . PDF_get_errmsg($p));
}
PDF_set_parameter($p, "SearchPath", $searchpath);
/* This line is required to avoid problems on Japanese systems */
PDF_set_parameter($p, "hypertextencoding", "winansi");
PDF_set_info($p, "Creator", "businesscard.php");
PDF_set_info($p, "Author", "Thomas Merz");
PDF_set_info($p, "Title", "PDFlib block processing sample (PHP)");
$blockcontainer = PDF_open_pdi($p, $infile, "", 0);
if ($blockcontainer == 0) {
    die("Error: " . PDF_get_errmsg($p));
}
$page = PDF_open_pdi_page($p, $blockcontainer, 1, "");
if ($page == 0) {
    die("Error: " . PDF_get_errmsg($p));
}
PDF_begin_page($p, 20, 20);
/* dummy page size */
/* This will adjust the page size to the block container's size. */
PDF_fit_pdi_page($p, $page, 0, 0, "adjustpage");
/* Fill all text blocks with dynamic data */
foreach ($data as $key => $value) {
    if (PDF_fill_textblock($p, $page, $key, $value, "embedding encoding=winansi") == 0) {
Exemplo n.º 8
0
$width = 500.0;
$height = 770.0;
$startpage = 1;
$endpage = 4;
$p = PDF_new();
/* create a new PDFlib object */
/*  open new PDF file; insert a file name to create the PDF on disk */
if (PDF_open_file($p, "") == 0) {
    die("Error: " . PDF_get_errmsg($p));
}
PDF_set_parameter($p, "SearchPath", $searchpath);
/* This line is required to avoid problems on Japanese systems */
PDF_set_parameter($p, "hypertextencoding", "winansi");
PDF_set_info($p, "Creator", "quickreference.php");
PDF_set_info($p, "Author", "Thomas Merz");
PDF_set_info($p, "Title", "mini imposition demo (php)");
$manual = PDF_open_pdi($p, $infile, "", 0);
if (!$manual) {
    die("Error: " . PDF_get_errmsg($p));
}
$row = 0;
$col = 0;
PDF_set_parameter($p, "topdown", "true");
for ($pageno = $startpage; $pageno <= $endpage; $pageno++) {
    if ($row == 0 && $col == 0) {
        PDF_begin_page($p, $width, $height);
        $font = PDF_load_font($p, "Helvetica-Bold", "winansi", "");
        PDF_setfont($p, $font, 18);
        PDF_set_text_pos($p, 24, 24);
        PDF_show($p, "PDFlib Quick Reference");
    }
Exemplo n.º 9
0
}
foreach ($invoice as $row) {
    $cnt = 0;
    foreach ($row as $item) {
        echo $item;
        $u[$cnt] = $item;
        $cnt++;
    }
}
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_info($mypdf, "Creator", "Online Bus Service");
PDF_set_info($mypdf, "Author", "Mukesh Kumar");
PDF_set_info($mypdf, "Title", "Speedticket");
PDF_set_info($mypdf, "Subject", "Ticket");
PDF_set_info($mypdf, "Keywords", "Bus Ticket");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 12);
PDF_setcolor($mypdf, "stroke", "rgb", 0.5, 0.5, 0.5, 1);
PDF_moveto($mypdf, 50, 810);
PDF_lineto($mypdf, 500, 810);
PDF_stroke($mypdf);
PDF_moveto($mypdf, 50, 100);
PDF_lineto($mypdf, 500, 100);
PDF_stroke($mypdf);
PDF_show_xy($mypdf, "Online Bus Ticket", 200, 800);
PDF_show_xy($mypdf, "Your Ticket Details", 70, 700);
PDF_continue_text($mypdf, "Bus Details");
PDF_continue_text($mypdf, "Bus ID: " . $b[0] . " Bus Name:" . $b[1] . " From: " . $b[2] . " To: " . $b[3]);
PDF_continue_text($mypdf, "Departure: " . $b[4] . " Arrival:" . $b[5] . " Type: " . $b[6] . "Seats:" . $b[7]);
Exemplo n.º 10
0
function carl_merge_pdfs_pdflib($pdffiles, $titles = array(), $metadata = array(), $metadata_encoding = 'UTF-8')
{
    if (gettype($pdffiles) != 'array') {
        trigger_error('$pdffiles must be an array');
        return false;
    }
    if (!function_exists('PDF_new')) {
        trigger_error('You must have PDFlib installed in order to run carl_merge_pdfs()');
        return false;
    }
    if (empty($pdffiles)) {
        return NULL;
    }
    $i = 0;
    $indoc = 0;
    $pdfver = '1.0';
    $maxpdfver = '1.0';
    $p = PDF_new();
    if (defined('PDFLIB_LICENSE_KEY_FILE')) {
        PDF_set_parameter($p, 'licensefile', PDFLIB_LICENSE_KEY_FILE);
    } else {
        trigger_error('Please define the constant PDFLIB_LICENSE_KEY_FILE with the filesystem location of your PDFlib license keys.');
    }
    /* This means we must check return values of load_font() etc. */
    //PDF_set_parameter($p, 'errorpolicy', 'return');
    /* -----------------------------------------------------------------
     * Loop over all input documents to retrieve the highest PDF version
     * used
     * -----------------------------------------------------------------
     */
    foreach ($pdffiles as $pdffile) {
        /* Open the input PDF */
        if (function_exists('PDF_open_pdi_document')) {
            $indoc = PDF_open_pdi_document($p, $pdffile, '');
        } else {
            $indoc = PDF_open_pdi($p, $pdffile, '', 0);
        }
        // pre-pecl 2.1
        if ($indoc < 1) {
            trigger_error('Error: ' . PDF_get_errmsg($p));
            continue;
        }
        /* Retrieve the PDF version of the current document. If it is higher 
         * than the maximum version retrieved until now make it to be the
         * maximum version.
         */
        if (function_exists('PDF_pcos_get_number')) {
            $pdfver = PDF_pcos_get_number($p, $indoc, 'pdfversion') / 10;
        } else {
            $pdfver = PDF_get_pdi_value($p, 'version', $indoc, 0, 0) / 10;
        }
        if ($pdfver > $maxpdfver) {
            $maxpdfver = $pdfver;
        }
        /* Close the input document.
         * Depending on the number of PDFs and memory strategy, PDI handles
         * to all documents could also be kept open between the first and
         * second run (requires more memory, but runs faster). We close all
         * PDFs after checking the version number, and reopen them in the
         * second loop (requires less memory, but is slower).
         */
        if (function_exists('PDF_close_pdi_document')) {
            PDF_close_pdi_document($p, $indoc);
        } else {
            PDF_close_pdi($p, $indoc);
        }
        // pre-pecl 2.1
    }
    /* ---------------------------------------------------------------
     * Open the output document with the maximum PDF version retrieved
     * --------------------------------------------------------------- 
     */
    if ($maxpdfver > '1.0') {
        $optlist = 'compatibility=' . $maxpdfver;
    } else {
        $optlist = '';
    }
    if (PDF_begin_document($p, '', $optlist) == -1) {
        trigger_error('Error: ' . PDF_get_errmsg($p));
    }
    foreach ($metadata as $key => $value) {
        PDF_set_info($p, $key, $value);
    }
    //PDF_set_info($p, 'Creator', 'Test Creator');
    //PDF_set_info($p, 'Title', $title . ' $Revision: 1.1 $');
    //echo '4 ';
    /* --------------------------------------------------------------------
     * Loop over all input documents to merge them into the output document       * used
     * --------------------------------------------------------------------
     */
    foreach ($pdffiles as $pdffile) {
        $endpage = $pageno = $page = 0;
        /* Open the input PDF */
        if (function_exists('PDF_open_pdi_document')) {
            $indoc = PDF_open_pdi_document($p, $pdffile, '');
        } else {
            $indoc = PDF_open_pdi($p, $pdffile, '', 0);
        }
        // pre-pecl 2.1
        if ($indoc < 1) {
            trigger_error('Error: ' . PDF_get_errmsg($p));
            continue;
        }
        if (function_exists('PDF_pcos_get_number')) {
            $endpage = (int) PDF_pcos_get_number($p, $indoc, '/Root/Pages/Count');
        } else {
            $endpage = (int) PDF_get_pdi_value($p, '/Root/Pages/Count', $indoc, 0, 0);
        }
        // pre-pecl 2.1
        /* Loop over all pages of the input document */
        for ($pageno = 1; $pageno <= $endpage; $pageno++) {
            $page = PDF_open_pdi_page($p, $indoc, $pageno, '');
            if ($page == 0) {
                trigger_error('Error: ' . PDF_get_errmsg($p));
                continue;
            }
            /* Dummy page size; will be adjusted later */
            PDF_begin_page_ext($p, 10, 10, '');
            /* Create a bookmark with the file name */
            if ($pageno == 1) {
                if (isset($titles[$pdffile])) {
                    $bookmark = pack('H*', 'feff') . mb_convert_encoding($titles[$pdffile], 'UTF-16', $metadata_encoding);
                } else {
                    $bookmark = pack('H*', 'feff') . mb_convert_encoding($pdffile, 'UTF-16', $metadata_encoding);
                }
                /* if(isset($titles[$pdffile]))
                				$bookmark = $titles[$pdffile];
                			else
                				$bookmark = $pdffile; */
                PDF_create_bookmark($p, $bookmark, '');
            }
            /* Place the imported page on the output page, and
             * adjust the page size
             */
            PDF_fit_pdi_page($p, $page, 0, 0, 'adjustpage');
            PDF_close_pdi_page($p, $page);
            PDF_end_page_ext($p, '');
        }
        /* Close the input document */
        if (function_exists('PDF_close_pdi_document')) {
            PDF_close_pdi_document($p, $indoc);
        } else {
            PDF_close_pdi($p, $indoc);
        }
        // pre-pecl 2.1
    }
    PDF_end_document($p, '');
    $buffer = PDF_get_buffer($p);
    pdf_delete($p);
    return $buffer;
}