function create_pdf($data, $filename = '', $stream = TRUE, $papersize = 'letter', $orientation = 'portrait') { require_once "dompdf/dompdf_config.inc.php"; $dompdf = new DOMPDF(); $dompdf->load_html(' '); $dompdf->render(); $canvas = $dompdf->get_canvas(); $font = Font_Metrics::get_font("helvetica"); $fontBold = Font_Metrics::get_font("helvetica", "bold"); $row = 1; $y = 25; for ($i = 0; $i < count($data); $i++) { if (strpos($data[$i], "STUDENT") !== FALSE) { $canvas->text(40, $y += 15, $data[$i], $fontBold, 10, array(0, 0, 0)); } elseif (strpos($data[$i], "COLLEGE") !== FALSE || strpos($data[$i], "UNIVERSITY") !== FALSE) { $canvas->text(40, $y += 15, $data[$i], $fontBold, 10, array(0, 0, 0)); } elseif (strpos($data[$i], "__") !== FALSE || $data[$i] == " ") { $canvas->text(40, $y += 9, $data[$i], $font, 10, array(0, 0, 0)); } else { $canvas->text(40, $y += 15, $data[$i], $font, 10, array(0, 0, 0)); } if ($y > 730) { $dompdf->get_canvas()->new_page(); $y = 50; } } if ($stream) { $dompdf->stream($filename . ".pdf"); } else { return $dompdf->output(); } }
function pdf_create($html, $filename, $stream = TRUE) { $dompdf = new DOMPDF(); $dompdf->set_paper("A4"); $dompdf->load_html($html); $dompdf->render(); $canvas = $dompdf->get_canvas(); // get height and width of page $w = $canvas->get_width(); $h = $canvas->get_height(); // get font $font = Font_Metrics::get_font("helvetica", "normal"); $txtHeight = Font_Metrics::get_font_height($font, 7); //draw line for signature manager $mnline = $h - 10 * $txtHeight - 24; $colormn = array(0, 0, 0); $canvas->line(20, $mnline, $w - 470, $mnline, $colormn, 1); //text for signature Requestor/HOD $textmn = "Requestor/HOD"; $widthmn = Font_Metrics::get_text_width($textmn, $font, 12); $canvas->text($w - $widthmn - 480, $mnline, $textmn, $font, 12); // draw a line along the bottom $y = $h - 2 * $txtHeight - 24; $color = array(0, 0, 0); $canvas->line(16, $y, $w - 16, $y, $color, 1); //draw line for GM/Manager //$canvas->line(270, $mnline, $w - 240, $mnline, $colormn, 1); $canvas->line(330, $mnline, $w - 170, $mnline, $colormn, 1); $texthr = "GM/Manager"; $widthhr = Font_Metrics::get_text_width($texthr, $font, 12); $canvas->text($w - $widthmn - 160, $mnline, $texthr, $font, 12); //draw line for HR //$canvas->line(270, $mnline, $w - 240, $mnline, $colormn, 1); $canvas->line(180, $mnline, $w - 310, $mnline, $colormn, 1); $texthr = "HR"; $widthhr = Font_Metrics::get_text_width($texthr, $font, 12); $canvas->text($w - $widthmn - 325, $mnline, $texthr, $font, 12); //draw line for IT Officer $canvas->line(470, $mnline, $w - 20, $mnline, $colormn, 1); $textIT = "IT Officer"; $canvas->text($w - $widthmn - 30, $mnline, $textIT, $font, 12); // set page number on the left side //$canvas->page_text(16, $y, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 8, $color); $canvas->page_text($w - 324, $y, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 8, $color); // set additional text $text = "ESRNL PORTAL"; $width = Font_Metrics::get_text_width($text, $font, 8); $canvas->text($w - $width - 16, $y, $text, $font, 8); if ($stream) { $dompdf->stream($filename . ".pdf"); } else { $CI =& get_instance(); $CI->load->helper('file'); write_file($filename, $dompdf->output()); } }
function insert($code) { $this->_dompdf->get_canvas()->javascript($code); }
/** * Class constructor * * @param DOMPDF $dompdf The current dompdf instance */ function __construct(DOMPDF $dompdf) { $this->_dompdf = $dompdf; $this->_canvas = $dompdf->get_canvas(); }
} $dompdf->load_html($str); } else { $dompdf->load_html_file($file); } if (isset($base_path)) { $dompdf->set_base_path($base_path); } $dompdf->set_paper($paper, $orientation); $dompdf->render(); if ($_dompdf_show_warnings) { global $_dompdf_warnings; foreach ($_dompdf_warnings as $msg) { echo $msg . "\n"; } echo $dompdf->get_canvas()->get_cpdf()->messages; flush(); } if ($save_file) { // if ( !is_writable($outfile) ) // throw new DOMPDF_Exception("'$outfile' is not writable."); if (strtolower(DOMPDF_PDF_BACKEND) === "gd") { $outfile = str_replace(".pdf", ".png", $outfile); } list($proto, $host, $path, $file) = explode_url($outfile); if ($proto != "") { // i.e. not file:// $outfile = $file; } // just save it locally, FIXME? could save it like wget: ./host/basepath/file $outfile = realpath(dirname($outfile)) . DIRECTORY_SEPARATOR . basename($outfile);
<p>Recomendaciones al Item de ensayo Nº VARIABLE</p> <br /><br /> <br /><br /> <br /><br /> <section> <p>Recomendaciones para el cultivo de cambur cobrero establecido:</p> <br /> <p>VARIABLE</p> </section> <p align="center"> Nombre del ing</p> <br /> <p align="center">Los resultados del análisis corresponden únicamente a las muestras consignadas. <br />El presente informe no presenta enmienda ni tachadura.</p> </body> </html>'; $html = utf8_decode($html); $dompdf = new DOMPDF(); $dompdf->load_html($html); $dompdf->render(); $canvas = $dompdf->get_canvas(); $footer = $canvas->open_object(); $w = $canvas->get_width(); $h = $canvas->get_height(); $font = Font_Metrics::get_font("arial", "bold"); $canvas->page_text($w - 553, $h - 78, "____________________________________________________________________________________________________________________________________________________________________", $font, 6, array(0, 0, 0)); $canvas->page_text($w - 550, $h - 70, "El Instituto Nacional de Investigaciones Agrícolas, antes FONAIAP, es un instituto autónomo adscrito al Ministerio del Poder Popular para la Agricultura y Tierras, dedicado a la investigación científica", $font, 6, array(0, 0, 0)); $canvas->page_text($w - 530, $h - 63, " agrícola, desarrollo tecnológico, asesoramiento y prestación de servicios especializados. Dirección: Presidencia: Av. Universidad. Esquina El Chorro. Torre MCT. Piso 08. La Hoyada. Caracas -", $font, 6, array(0, 0, 0)); $canvas->page_text($w - 530, $h - 56, "Venezuela. Teléfonos (58 212) 5646466 - 5640355 - 5643862. Fax (58 212) 2103681. Gerencia General: Av. Universidad, vía El Limón, Maracay, Estado Aragua, Teléfonos (58 243) 2404911 -", $font, 6, array(0, 0, 0)); $canvas->page_text($w - 500, $h - 49, " 2404642 - 2404772 – 2404762. Fax (58 243) 2404732. INIA Mérida: Av Urdaneta Edif. INIA-Mérida, Mérida estado Mérida. Telefax: (58 274) 2630090 / 2637941 ", $font, 6, array(0, 0, 0)); $canvas->close_object(); $canvas->add_object($footer, "all"); $dompdf->PDF::loadView("ejemplo.php", array("Attachment" => 0));
function pdf_create($html, $filename, $stream) { /* require_once("dompdf/dompdf_config.inc.php"); spl_autoload_register('DOMPDF_autoload'); //$dompdf = new DOMPDF(); //$dompdf->set_paper("a4", "portrait"); //$dompdf->load_html($html); $html = 'asdfhgfh Ξ'; //$html = utf8_encode($html); $dompdf = new DOMPDF(); $html = iconv('UTF-8','Windows-1250',$html); $dompdf->load_html($html); $dompdf->render(); $pdf = $dompdf->output(); if ($stream) { $dompdf->stream($filename.".pdf"); }else { ini_set('error_reporting', E_ALL); if(!write_file("./files/temp/".$filename.".pdf", $pdf)) { echo "files/temp/".$filename.".pdf". ' -> PDF could not be saved! Check your server settings!'; die(); } } */ if (!function_exists('dompdf_usage')) { function dompdf_usage() { $default_paper_size = DOMPDF_DEFAULT_PAPER_SIZE; echo <<<EOD Usage: {$_SERVER["argv"][0]} [options] html_file html_file can be a filename, a url if fopen_wrappers are enabled, or the '-' character to read from standard input. Options: -h Show this message -l List available paper sizes -p size Paper size; something like 'letter', 'A4', 'legal', etc. The default is '{$default_paper_size}' -o orientation Either 'portrait' or 'landscape'. Default is 'portrait' -b path Set the 'document root' of the html_file. Relative urls (for stylesheets) are resolved using this directory. Default is the directory of html_file. -f file The output filename. Default is the input [html_file].pdf -v Verbose: display html parsing warnings and file not found errors. -d Very verbose: display oodles of debugging output: every frame in the tree printed to stdout. -t Comma separated list of debugging types (page-break,reflow,split) EOD; exit; } } /** * Parses command line options * * @return array The command line options */ if (!function_exists('getoptions')) { function getoptions() { $opts = array(); if ($_SERVER["argc"] == 1) { return $opts; } $i = 1; while ($i < $_SERVER["argc"]) { switch ($_SERVER["argv"][$i]) { case "--help": case "-h": $opts["h"] = true; $i++; break; case "-l": $opts["l"] = true; $i++; break; case "-p": if (!isset($_SERVER["argv"][$i + 1])) { die("-p switch requires a size parameter\n"); } $opts["p"] = $_SERVER["argv"][$i + 1]; $i += 2; break; case "-o": if (!isset($_SERVER["argv"][$i + 1])) { die("-o switch requires an orientation parameter\n"); } $opts["o"] = $_SERVER["argv"][$i + 1]; $i += 2; break; case "-b": if (!isset($_SERVER["argv"][$i + 1])) { die("-b switch requires a path parameter\n"); } $opts["b"] = $_SERVER["argv"][$i + 1]; $i += 2; break; case "-f": if (!isset($_SERVER["argv"][$i + 1])) { die("-f switch requires a filename parameter\n"); } $opts["f"] = $_SERVER["argv"][$i + 1]; $i += 2; break; case "-v": $opts["v"] = true; $i++; break; case "-d": $opts["d"] = true; $i++; break; case "-t": if (!isset($_SERVER['argv'][$i + 1])) { die("-t switch requires a comma separated list of types\n"); } $opts["t"] = $_SERVER['argv'][$i + 1]; $i += 2; break; default: $opts["filename"] = $_SERVER["argv"][$i]; $i++; break; } } return $opts; } } require_once "dompdf/dompdf_config.inc.php"; global $_dompdf_show_warnings, $_dompdf_debug, $_DOMPDF_DEBUG_TYPES; $sapi = php_sapi_name(); $options = array(); switch ($sapi) { case "cli": $opts = getoptions(); if (isset($opts["h"]) || !isset($opts["filename"]) && !isset($opts["l"])) { dompdf_usage(); exit; } if (isset($opts["l"])) { echo "\nUnderstood paper sizes:\n"; foreach (array_keys(CPDF_Adapter::$PAPER_SIZES) as $size) { echo " " . mb_strtoupper($size) . "\n"; } exit; } $file = $opts["filename"]; if (isset($opts["p"])) { $paper = $opts["p"]; } else { $paper = DOMPDF_DEFAULT_PAPER_SIZE; } if (isset($opts["o"])) { $orientation = $opts["o"]; } else { $orientation = "portrait"; } if (isset($opts["b"])) { $base_path = $opts["b"]; } if (isset($opts["f"])) { $outfile = $opts["f"]; } else { if ($file === "-") { $outfile = "dompdf_out.pdf"; } else { $outfile = str_ireplace(array(".html", ".htm", ".php"), "", $file) . ".pdf"; } } if (isset($opts["v"])) { $_dompdf_show_warnings = true; } if (isset($opts["d"])) { $_dompdf_show_warnings = true; $_dompdf_debug = true; } if (isset($opts['t'])) { $arr = split(',', $opts['t']); $types = array(); foreach ($arr as $type) { $types[trim($type)] = 1; } $_DOMPDF_DEBUG_TYPES = $types; } $save_file = true; break; default: if (isset($_GET["input_file"])) { $file = rawurldecode($_GET["input_file"]); } else { //throw new DOMPDF_Exception("An input file is required (i.e. input_file _GET variable)."); if (isset($_GET["paper"])) { $paper = rawurldecode($_GET["paper"]); } else { $paper = DOMPDF_DEFAULT_PAPER_SIZE; } } if (isset($_GET["orientation"])) { $orientation = rawurldecode($_GET["orientation"]); } else { $orientation = "portrait"; } if (isset($_GET["base_path"])) { $base_path = rawurldecode($_GET["base_path"]); $file = $base_path . $file; # Set the input file } if (isset($_GET["options"])) { $options = $_GET["options"]; } /* $file_parts = explode_url($file); /* Check to see if the input file is local and, if so, that the base path falls within that specified by DOMDPF_CHROOT if(($file_parts['protocol'] == '' || $file_parts['protocol'] === 'file://')) { $file = realpath($file); if ( strpos($file, DOMPDF_CHROOT) !== 0 ) { throw new DOMPDF_Exception("Permission denied on $file. The file could not be found under the directory specified by DOMPDF_CHROOT."); } } */ $outfile = $filename . ".pdf"; # Don't allow them to set the output file $save_file = false; # Don't save the file break; } $dompdf = new DOMPDF(); /* Uncomment the line below in order to activate special characters (Chiniese, Korean,...)*/ /* $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); */ $dompdf->load_html($html); if (isset($base_path)) { $dompdf->set_base_path($base_path); } $dompdf->set_paper($paper, $orientation); $dompdf->render(); if ($_dompdf_show_warnings) { global $_dompdf_warnings; foreach ($_dompdf_warnings as $msg) { echo $msg . "\n"; } echo $dompdf->get_canvas()->get_cpdf()->messages; flush(); } if ($save_file) { // if ( !is_writable($outfile) ) // throw new DOMPDF_Exception("'$outfile' is not writable."); ini_set('error_reporting', E_ALL); if (!write_file("./files/temp/" . $filename . ".pdf", $pdf)) { echo "files/temp/" . $filename . ".pdf" . ' -> PDF could not be saved! Check your server settings!'; die; } } if (!headers_sent()) { if ($stream) { $dompdf->stream($outfile, $options); } else { $pdf = $dompdf->output(); ini_set('error_reporting', E_ALL); if (!write_file("./files/temp/" . $filename . ".pdf", $pdf)) { echo "files/temp/" . $filename . ".pdf" . ' -> PDF could not be saved! Check your server settings!'; die; } } } }
/** * Create PDF * * @access public * @return void */ function create($mode = 'download') { if (is_null($this->html)) { show_error("HTML is not set"); } if (is_null($this->path)) { show_error("Path is not set"); } if (is_null($this->paper_size)) { show_error("Paper size not set"); } if (is_null($this->orientation)) { show_error("Orientation not set"); } //Load the DOMPDF libary require_once "dompdf/dompdf_config.inc.php"; $dompdf = new DOMPDF(); $dompdf->load_html($this->html); $dompdf->set_paper($this->paper_size, $this->orientation); $dompdf->render(); $canvas = $dompdf->get_canvas(); $font = Font_Metrics::get_font("helvetica", "bold"); $canvas->page_text(380, 570, "Página {PAGE_NUM} de {PAGE_COUNT}", $font, 8, array(0, 0, 0)); if ($mode == 'save') { $this->CI->load->helper('file'); if (write_file($this->path . $this->filename, $dompdf->output())) { return $this->path . $this->filename; } else { show_error("PDF could not be written to the path"); } } else { if ($dompdf->stream($this->filename)) { return TRUE; } else { show_error("PDF could not be streamed"); } } }
/** * {@inheritdoc} */ public function setHeader($text) { $canvas = $this->generator->get_canvas(); $canvas->page_text(72, 18, "Header: {PAGE_COUNT}", "", 11, array(0, 0, 0)); }
/** * Effectue le rendu du contenu html en pdf * * @return void */ function render() { $this->dompdf->load_html($this->html); $this->dompdf->render(); if (CHtmlToPDFConverter::$_page_ordonnance) { $this->dompdf->get_canvas()->page_text(273, 730, "Page {PAGE_NUM} / {PAGE_COUNT}", Font_Metrics::get_font("arial"), 10); } $this->result = $this->dompdf->output(); }
function pdf_create($html, $filename = '', $stream = FALSE) { require_once APPPATH . "third-party/dompdf_config.inc.php"; //Require Loader Class n Config spl_autoload_register('DOMPDF_autoload'); //Autoload Resource ini_set("memory_limit", "999M"); ini_set("max_execution_time", "999"); $dompdf = new DOMPDF(); //Instansiasi $dompdf->load_html($html); //Load HTML File untuk dirender // $dompdf->set_base_path(realpath($css)); $dompdf->set_paper(array(0, 0, 8.5 * 72, 13.5 * 72), "portrait"); //array(0,0, 8.5 * 72, 11 * 72) $dompdf->render(); //Proses Rendering File $canvas = $dompdf->get_canvas(); $font = Font_Metrics::get_font("helvetica", "bold"); $canvas->page_text(830, 578, "Halaman: {PAGE_NUM} dari {PAGE_COUNT}", $font, 8, array(0, 0, 0)); if ($stream == TRUE) { $dompdf->stream($filename, array('Attachment' => 0)); } else { $CI =& get_instance(); $CI->load->helper('file'); write_file($filename, $dompdf->output()); //file name adalah ABSOLUTE PATH dari tempat menyimpan file PDF } }