<?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);
/** * Sets Number of Pages Contained Within the Order PDF. The Functions Looks * Up the SKU in the multi_page_sku Database Table, if Present, Downloads the PDF * and Gets the Page Count. If the SKU is Not in the Table, Defaults to 1. * * @access private * @return void */ private function _setPageCount() { $this->_orderArray['pageCount'] = 1; if (PresswiseDB::getInstance()->isMultiImageSku($this->_orderArray['productID']) === true) { file_put_contents(PDF_TMP_DIR . DIRECTORY_SEPARATOR . PDF_CURRENT_PDF, file_get_contents($this->_orderArray['fileF'])); $p = PDF_new(); PDF_set_parameter($p, 'errorpolicy', 'return'); PDF_set_parameter($p, 'SearchPath', PDF_TMP_DIR); $doc = PDF_open_pdi_document($p, PDF_CURRENT_PDF, 'requiredmode=minimum'); if ($doc == 0) { $this->isErrors = true; $this->_errors = 'Error Counting Pages: ' . PDF_get_errmsg($p); } else { $this->_orderArray['pageCount'] = PDF_pcos_get_number($p, $doc, 'length:pages'); } } }
<?php /* $Id: pdfclock.php 14574 2005-10-29 16:27:43Z bonefish $ * 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);
<?php $p = PDF_new(); PDF_open_file($p); PDF_begin_page($p, 595, 842); $font = PDF_findfont($p, "Helvetica-Bold", "host", 0); PDF_setfont($p, $font, 38.0); PDF_set_parameter($p, "overline", "true"); PDF_show_xy($p, "Overlined Text", 50, 780); PDF_set_parameter($p, "overline", "false"); PDF_set_parameter($p, "underline", "true"); PDF_continue_text($p, "Underlined Text"); PDF_set_parameter($p, "strikeout", "true"); PDF_continue_text($p, "Underlined strikeout Text"); PDF_set_parameter($p, "underline", "false"); PDF_set_parameter($p, "strikeout", "false"); PDF_setcolor($p, "fill", "rgb", 1.0, 0.1, 0.1); PDF_continue_text($p, "Red Text"); PDF_setcolor($p, "fill", "rgb", 0, 0, 0); PDF_set_value($p, "textrendering", 1); PDF_setcolor($p, "stroke", "rgb", 0, 0.5, 0); PDF_continue_text($p, "Green Outlined Text"); PDF_set_value($p, "textrendering", 2); PDF_setcolor($p, "fill", "rgb", 0, 0.2, 0.8); PDF_setlinewidth($p, 2); PDF_continue_text($p, "Green Outlined Blue Text"); PDF_end_page($p); PDF_close($p); $buf = PDF_get_buffer($p); $len = strlen($buf); Header("Content-type:application/pdf");
/** * Output the the via the integrated layout engine * * Outputs the text via the integrated layout engine at the * specified coordinates, alignment and leading. * * @param float $xpos The left starting position * @param float $ypos The top starting position * @param string $alignment "left"/"right"/"center" * @param float $leading The text leading * * @access public */ function puttext($xpos, $ypos, $alignment, $leading) { if (!$this->layoutvalid) { $this->getrequiredlinenum(); } $alignment = strtolower($alignment); if ($leading == 0) { $leading = $this->fontsize; } $linenum = sizeof($this->lines); $height = $linenum * $this->fontsize + ($linenum - 1) * ($leading - $this->fontsize); // DEBUG //PDF_setcolor($this->pdf, "both", "rgb", 1, 0, 0, 0); //PDF_rect($this->pdf, $xpos, $ypos-$height, $this->width, $height); //PDF_fill($this->pdf); //PDF_setcolor($this->pdf, "both", "rgb", 0, 0, 0, 0); $font = PDF_findfont($this->pdf, $this->fontface, 'host', 0); PDF_setfont($this->pdf, $font, $this->fontsize); PDF_set_parameter($this->pdf, "underline", "false"); PDF_set_parameter($this->pdf, "overline", "false"); PDF_set_parameter($this->pdf, "strikeout", "false"); if (is_array($this->fontparset)) { foreach ($this->fontparset as $par) { PDF_set_parameter($this->pdf, $par, "true"); } } // Decrease the vertical position of the text, as the // passed x/y-coordinates specify the left top corner // of the text whereas PDF_show_xy() uses the coordinates // for the text baseline $ascender = PDF_get_value($this->pdf, "ascender", $font) * $this->fontsize; $ypos -= $ascender + 1; $this->setcolor($this->fontcolor); for ($i = 0; $i < sizeof($this->lines); $i++) { $line =& $this->lines[$i]; $linewidth =& $this->linewidths[$i]; // DEBUG //PDF_show_xy($this->pdf, $linewidth, 0, $ypos); switch ($alignment) { default: case "left": PDF_show_xy($this->pdf, "{$line}", $xpos, $ypos); break; case "right": PDF_show_xy($this->pdf, $line, $xpos + $this->width - $linewidth, $ypos); break; case "center": PDF_show_xy($this->pdf, $line, $xpos + ($this->width - $linewidth) / 2, $ypos); break; } $ypos -= $leading; } $this->buffer = ""; }
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"); } $page = PDF_open_pdi_page($p, $manual, $pageno, ""); if (!$page) { die("Error: " . PDF_get_errmsg($p)); } $optlist = sprintf("scale %f", 1 / $maxrow); PDF_fit_pdi_page($p, $page, $width / $maxcol * $col, ($row + 1) * $height / $maxrow, $optlist); PDF_close_pdi_page($p, $page);
function writeTable($table, $x, $y, $arrCol, $arrAlign, $line_max = 256, $start_no = 1, $last_color_flg = false) { $this->openPage(); $table = ereg_replace("\n\$", "", $table); $arrRet = split("\n", $table); if ($line_max > count($arrRet) - $start_no) { $line_max = count($arrRet) - $start_no; } // タイトル有効 if ($this->grid_enable) { // グリッドの描画 $this->writeGrid($x, $y, $arrCol, $line_max, $last_color_flg); } // UnicodeエンコーディングとしてUTF-8を設定 PDF_set_parameter($this->pdf, "textformat", "utf8"); // タイトル有効 if ($this->title_enable) { if (count($this->arrHeaderColSize) > 0 && count($this->arrHeaderAlign) > 0) { list($linecol, $aligncol, $width) = $this->getTableOption($this->arrHeaderColSize, $this->arrHeaderAlign); } else { list($linecol, $aligncol, $width) = $this->getTableOption($arrCol, $arrAlign); } // タイトル行の書き込み $option = "ruler {" . $linecol . "} "; $option .= "tabalignment {" . $aligncol . "} "; $fontsize = $this->fontsize; $option .= "hortabmethod ruler leading=150% fontname=HeiseiKakuGo-W5 fontsize={$fontsize} encoding=UniJIS-UCS2-H"; $this->writeTableData($table, $x, $y, $width, 0, 0, $option); } list($linecol, $aligncol, $width) = $this->getTableOption($arrCol, $arrAlign); // データ行の書き込み $option = "ruler {" . $linecol . "} "; $option .= "tabalignment {" . $aligncol . "} "; $option .= "hortabmethod ruler leading=150% fontname=HeiseiMin-W3 fontsize={$this->fontsize} encoding=UniJIS-UCS2-H"; if ($start_no <= 0) { $start_no = 1; $end_no = $line_max; } else { $end_no = $start_no + $line_max - 1; } $y += $this->fontsize * 1.5; list($ret_x, $ret_y) = $this->writeTableData($table, $x, $y, $width, $start_no, $end_no, $option); return array($ret_x, $ret_y); }
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; }
<?php $p = PDF_new(); PDF_open_file($p); PDF_set_info($p, "Creator", "hello.php"); PDF_set_info($p, "Author", "Rasmus Lerdorf"); PDF_set_info($p, "Title", "Hello world (PHP)"); PDF_begin_page($p, 595, 842); PDF_set_parameter($p, "FontOutline", "CANDY==/usr/share/fonts/truetype/CANDY.ttf"); $font = PDF_findfont($p, "CANDY", "host", 1); PDF_setfont($p, $font, 78.0); PDF_set_value($p, "textrendering", 2); PDF_setcolor($p, "fill", "rgb", 0.8, 0.8, 0); PDF_setcolor($p, "stroke", "rgb", 0, 0, 0.5); PDF_set_text_pos($p, 20, 780); PDF_continue_text($p, "� � � � � � � � �"); PDF_continue_text($p, "This is a test"); PDF_end_page($p); 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=candy.pdf"); echo $buf; PDF_delete($p);