public function render($view = null, $layout = null) { try { ob_start(); if (defined('DOMPDF_TEMP_DIR')) { $dir = new SplFileInfo(DOMPDF_TEMP_DIR); if (!$dir->isDir() || !$dir->isWritable()) { trigger_error(__('%s is not writable', DOMPDF_TEMP_DIR), E_USER_WARNING); } } $errors = ob_get_contents(); ob_end_clean(); $download = false; $name = pathinfo($this->here, PATHINFO_BASENAME); $paperOrientation = 'portrait'; $paperSize = 'letter'; extract($this->viewVars, EXTR_IF_EXISTS); $dompdf = new DOMPDF(); $dompdf->load_html($errors . parent::render($view, $layout), Configure::read('App.encoding')); $dompdf->set_protocol(''); $dompdf->set_protocol(WWW_ROOT); $dompdf->set_base_path('/'); $dompdf->set_paper($paperSize, $paperOrientation); $dompdf->render(); $dompdf->stream($name, array('Attachment' => $download)); } catch (Exception $e) { $this->request->params['ext'] = 'html'; throw $e; } }
/** * Préparation de dompdf pour la conversion * * @param string $format format de la page * @param string $orientation orientation de la page * * @return void */ function prepare($format, $orientation) { CAppUI::requireModuleFile("dPcompteRendu", "dompdf_config"); CAppUI::requireLibraryFile("dompdf/dompdf_config.inc"); $this->dompdf = new dompdf(); $this->dompdf->set_base_path(realpath(dirname(__FILE__) . "/../../../../")); $this->dompdf->set_paper($format, $orientation); if (CAppUI::conf("dPcompteRendu CCompteRendu dompdf_host")) { $this->dompdf->set_protocol(isset($_SERVER["HTTPS"]) ? "https://" : "http://"); $this->dompdf->set_host($_SERVER["SERVER_NAME"]); } }
/** * * @param \Illuminate\Config\Repository $config * @param \Illuminate\Filesystem\Filesystem $files * @param \Illuminate\View\Factory $view * @param string $publicPath */ public function __construct(ConfigRepository $config, Filesystem $files, $view, $publicPath) { $this->config = $config; $this->files = $files; $this->view = $view; $this->public_path = $publicPath; $this->showWarnings = $this->config->get('laravel-dompdf::show_warnings', false); //To prevent old configs from not working.. if ($this->config->has('laravel-dompdf::paper')) { $this->paper = $this->config->get('laravel-dompdf::paper'); } else { $this->paper = DOMPDF_DEFAULT_PAPER_SIZE; } $this->orientation = $this->config->get('laravel-dompdf::orientation') ?: 'portrait'; $this->dompdf = new \DOMPDF(); $this->dompdf->set_base_path(realpath($publicPath)); }
/** * gerar PDF da Danfe. * * @param null $encoding * @return string */ public function getPDF($encoding = null) { require_once __DIR__ . '/DomPDF/bootstrap.php'; $html = $this->getHTML(); $html = $this->convertEntities($html); $pdf = new \DOMPDF(); $pdf->set_base_path(__DIR__); $pdf->load_html($html); $pdf->set_paper('A4', 'portrait'); $pdf->render(); return $pdf->output(); }
/** * Create a PDF * * The minimum required to create a PDF is some HTML provided as a string. * This is easily done in CI by providing the contents of a view. * * Example: * ------------------------------------------------------ * $this->load->helper('pdf_creation'); * $html = $this->load->view( * 'pdf_template', * ( isset( $view_data ) ) ? $view_data : '', * TRUE * ); * pdf_create( $html ); * ------------------------------------------------------ * * @param string HTML to be used for making a PDF * @param array Configuration options */ function pdf_create($html, $config = array()) { $defaults = array('output_type' => 'stream', 'filename' => microtime(TRUE) . '.pdf', 'upload_dir' => FCPATH . 'upload_directory/pdfs/', 'load_html' => TRUE, 'html_encoding' => '', 'load_html_file' => FALSE, 'output_compression' => 1, 'set_base_path' => FALSE, 'set_paper' => FALSE, 'paper_size' => 'letter', 'paper_orientation' => 'portrait', 'stream_compression' => 1, 'stream_attachment' => 1); // Set options from defaults and incoming config array $options = array_merge($defaults, $config); // Remove any previously created headers if (is_php('5.3.0') && $options['output_type'] == 'stream') { header_remove(); } // Load dompdf require_once "dompdf/dompdf_config.inc.php"; // Create a dompdf object $dompdf = new DOMPDF(); // Set supplied base path if ($options['set_base_path'] !== FALSE) { $dompdf->set_base_path($options['set_base_path']); } // Set supplied paper if ($options['set_paper'] !== FALSE) { $dompdf->set_paper($options['paper_size'], $options['paper_orientation']); } // Load the HTML that will be turned into a PDF if ($options['load_html_file'] !== FALSE) { // Loads an HTML file $dompdf->load_html_file($html); } else { // Loads an HTML string $dompdf->load_html($html, $options['html_encoding']); } // Create the PDF $dompdf->render(); // If destination is the browser if ($options['output_type'] == 'stream') { $dompdf->stream($options['filename'], array('compress' => $options['stream_compression'], 'Attachment' => $options['stream_attachment'])); } else { if ($options['output_type'] == 'string') { return $dompdf->output($options['output_compression']); } else { // Get an instance of CI $CI =& get_instance(); // Create upload directories if they don't exist if (!is_dir($options['upload_path'])) { mkdir($options['upload_path'], 0777, TRUE); } // Load the CI file helper $CI->load->helper('file'); // Save the file write_file($options['upload_path'] . $options['filename'], $dompdf->output()); } } }
/** * Register the service provider. * * @throws \Exception * @return void */ public function register() { $configPath = __DIR__ . '/../config/dompdf.php'; $this->mergeConfigFrom($configPath, 'dompdf'); $this->app->bind('dompdf', function ($app) { $dompdf = new \DOMPDF(); $dompdf->set_base_path(realpath(base_path('public'))); return $dompdf; }); $this->app->alias('dompdf', 'DOMPDF'); $this->app->bind('dompdf.wrapper', function ($app) { return new PDF($app['dompdf'], $app['config'], $app['files'], $app['view']); }); }
function pdf_create($html, $filename = '', $stream = TRUE) { require_once "dompdf/dompdf_config.inc.php"; $new_filename = str_replace("/", "_", $filename); $dompdf = new DOMPDF(); $dompdf->load_html($html); $dompdf->set_base_path(base_url() . 'assets/css/style-surat.css'); $dompdf->render(); if ($stream) { $dompdf->stream($new_filename . ".pdf"); } else { //return $dompdf->output(); $output = $dompdf->output(); $file_to_save = FCPATH . 'assets/surat_acara/' . $new_filename . '.pdf'; file_put_contents($file_to_save, $output); } }
function print_pdf($filename, $html, $force_download, $paper_size = "A4", $orientation = "portrait") { //$CI =& get_instance(); //$CI->load->library('Pdflib'); require_once APPPATH . "/third_party/dompdf/dompdf_config.inc.php"; ob_start(); $dompdf = new DOMPDF(); $dompdf->load_html($html); $dompdf->set_base_path(base_url() . 'inc/css/'); $dompdf->set_paper($paper_size, $orientation); $dompdf->render(); if ($force_download) { $dompdf->stream($filename . ".pdf"); } else { $dompdf->stream($filename . ".pdf", array('Attachment' => 0)); } }
public function render($view = null, $layout = null) { try { ob_start(); if (defined('DOMPDF_TEMP_DIR')) { $dir = new SplFileInfo(DOMPDF_TEMP_DIR); if (!$dir->isDir() || !$dir->isWritable()) { trigger_error(__('%s is not writable', DOMPDF_TEMP_DIR), E_USER_WARNING); } } $errors = ob_get_contents(); ob_end_clean(); $download = false; $name = pathinfo($this->here, PATHINFO_BASENAME); $paperOrientation = 'portrait'; $paperSize = 'letter'; $preData = null; $postData = null; extract($this->viewVars, EXTR_IF_EXISTS); $dompdf = new DOMPDF(); $dompdf->set_protocol(''); $dompdf->set_protocol(WWW_ROOT); $dompdf->set_base_path('/'); $dompdf->set_paper($paperSize, $paperOrientation); if (!empty($preData) || !empty($postData)) { App::import('Vendor', 'Dompdf.PDFMerger', true, array(), 'PDFMerger' . DS . 'PDFMerger.php'); $merger = new PDFMerger(); if (!empty($preData)) { $merger->addPdfData($preData, DOMPDF_TEMP_DIR); } //Get the static information sheet $merger->addPdfData(file_get_contents("../View/Courses/survey_explanation.pdf"), DOMPDF_TEMP_DIR); if (!empty($postData)) { $merger->addPdfData($postData, DOMPDF_TEMP_DIR); } $merger->merge($download ? 'download' : 'browser'); } else { $dompdf->stream($name, array('Attachment' => $download)); } } catch (Exception $e) { $this->request->params['ext'] = 'html'; throw $e; } }
/** * @return string */ public function actionIndex() { $model = new ApplicantForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $fileName = time() . '.pdf'; $filePath = Yii::getAlias('@webroot/files/' . time() . '.pdf'); $this->layout = 'pdf'; $this->view->params['css'] = [file_get_contents(Yii::getAlias('@webroot/css/pdf.css'))]; $html = $this->render('pdf', ['model' => $model]); $pdf = new \DOMPDF(); $pdf->set_base_path(Yii::$app->assetManager->getBundle(BootstrapAsset::className())->basePath . '/css'); $pdf->load_html($html); $pdf->render(); $output = $pdf->output(); file_put_contents($filePath, $output); Yii::$app->session->setFlash('reportGenerated'); Yii::$app->session->setFlash('reportURL', Url::to(['files/' . $fileName])); return $this->refresh(); } return $this->render('index', ['model' => $model]); }
/** * get a PDF version of the invoice * * @return null */ function OnlineStore_invoicePdf() { $id = (int) $_REQUEST['id']; $order = dbRow('select invoice, meta, user_id from online_store_orders where id=' . $id); $ok = false; if ($order) { if ($order['user_id'] == $_SESSION['userdata']['id']) { $ok = true; } $meta = json_decode($order['meta'], true); if (isset($_REQUEST['auth']) && isset($meta['auth-md5']) && $meta['auth-md5'] == $_REQUEST['auth']) { $ok = true; } } if (!$ok) { Core_quit(); } $inv = $order['invoice']; // { check if it's already stored as a PDF if (isset($meta['invoice-type']) && $meta['invoice-type'] == 'pdf') { $pdf = base64_decode($inv); header('Content-type: application/pdf'); echo $pdf; Core_quit(); } // } // { else generate a PDF and output it $pdfFile = USERBASE . '/ww.cache/online-store/invoice-pdf-' . $id; if (!file_exists($pdfFile)) { $html = OnlineStore_invoiceGet($id); require_once $_SERVER['DOCUMENT_ROOT'] . '/ww.incs/dompdf/dompdf_config.inc.php'; $dompdf = new DOMPDF(); $dompdf->set_base_path($_SERVER['DOCUMENT_ROOT']); $dompdf->load_html(utf8_decode(str_replace('€', '€', $html)), 'UTF-8'); $dompdf->set_paper('a4'); $dompdf->render(); file_put_contents($pdfFile, $dompdf->output()); } header('Content-type: application/pdf'); $fp = fopen($pdfFile, 'r'); fpassthru($fp); fclose($fp); Core_quit(); // } }
function _formatOutput($content = '', $return = FALSE) { if ($this->request_type == 'pdf') { $this->output->set_header('Content-Type: text/html'); require_once DOCROOT . '/' . APPPATH . 'libraries/dompdf/dompdf_config.inc.php'; $output = $this->layout->wrap($content, $return); $title = $this->layout->getTitle() . '.pdf'; if ($this->input->get('output')) { echo $output; } else { $dompdf = new DOMPDF(); $dompdf->set_base_path(DOCROOT); $dompdf->load_html($output); $dompdf->render(); $dompdf->stream($title); } } else { $this->layout->addMeta('author', $this->SITE_CONF['author']); $this->layout->addMeta('generator', $this->SITE_CONF['application_name'] . ' ' . $this->SITE_CONF['application_version']); $this->layout->addMeta('cms', $this->SITE_CONF['application']); $this->layout->addMeta('cms-version', $this->SITE_CONF['application_version']); $this->layout->addMeta('cms-pagegenerated', date(DATE_DB_FORMAT)); $this->layout->addMeta('cms-sitepath', SITEPATH); $this->layout->addMeta('cms-requestpath', $this->request_path); $output = $this->layout->wrap($content, $return); if ($return) { return $output; } else { echo $output; } } }
/** * Generate export file of current result */ protected function _genExport($pt_subject, $ps_template, $ps_output_filename, $ps_title = null) { $this->view->setVar('t_subject', $pt_subject); if (substr($ps_template, 0, 5) === '_pdf_') { $va_template_info = caGetPrintTemplateDetails('summary', substr($ps_template, 5)); } elseif (substr($ps_template, 0, 9) === '_display_') { $vn_display_id = substr($ps_template, 9); $t_display = new ca_bundle_displays($vn_display_id); if ($vn_display_id && $t_display->haveAccessToDisplay($this->request->getUserID(), __CA_BUNDLE_DISPLAY_READ_ACCESS__)) { $this->view->setVar('t_display', $t_display); $this->view->setVar('display_id', $vn_display_id); $va_display_list = array(); $va_placements = $t_display->getPlacements(array('settingsOnly' => true)); foreach ($va_placements as $vn_placement_id => $va_display_item) { $va_settings = caUnserializeForDatabase($va_display_item['settings']); // get column header text $vs_header = $va_display_item['display']; if (isset($va_settings['label']) && is_array($va_settings['label'])) { $va_tmp = caExtractValuesByUserLocale(array($va_settings['label'])); if ($vs_tmp = array_shift($va_tmp)) { $vs_header = $vs_tmp; } } $va_display_list[$vn_placement_id] = array('placement_id' => $vn_placement_id, 'bundle_name' => $va_display_item['bundle_name'], 'display' => $vs_header, 'settings' => $va_settings); } $this->view->setVar('placements', $va_display_list); } else { $this->postError(3100, _t("Invalid format %1", $ps_template), "DetailController->_genExport()"); return; } $va_template_info = caGetPrintTemplateDetails('summary', 'summary'); } else { $this->postError(3100, _t("Invalid format %1", $ps_template), "DetailController->_genExport()"); return; } // // PDF output // if (!is_array($va_template_info)) { $this->postError(3110, _t("Could not find view for PDF"), "DetailController->_genExport()"); return; } // // Tag substitution // // Views can contain tags in the form {{{tagname}}}. Some tags, such as "itemType" and "detailType" are defined by // the detail controller. More usefully, you can pull data from the item being detailed by using a valid "get" expression // as a tag (Eg. {{{ca_objects.idno}}}. Even more usefully for some, you can also use a valid bundle display template // (see http://docs.collectiveaccess.org/wiki/Bundle_Display_Templates) as a tag. The template will be evaluated in the // context of the item being detailed. // $va_defined_vars = array_keys($this->view->getAllVars()); // get list defined vars (we don't want to copy over them) $va_tag_list = $this->getTagListForView($va_template_info['path']); // get list of tags in view foreach ($va_tag_list as $vs_tag) { if (in_array($vs_tag, $va_defined_vars)) { continue; } if (strpos($vs_tag, "^") !== false || strpos($vs_tag, "<") !== false) { $this->view->setVar($vs_tag, $pt_subject->getWithTemplate($vs_tag, array('checkAccess' => $this->opa_access_values))); } elseif (strpos($vs_tag, ".") !== false) { $this->view->setVar($vs_tag, $pt_subject->get($vs_tag, array('checkAccess' => $this->opa_access_values))); } else { $this->view->setVar($vs_tag, "?{$vs_tag}"); } } try { $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME)); $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local")); $vs_content = $this->render($va_template_info['path']); $o_dompdf = new DOMPDF(); $o_dompdf->load_html($vs_content); $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait')); $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('summary')); $o_dompdf->render(); $o_dompdf->stream(caGetOption('filename', $va_template_info, 'export_results.pdf')); $vb_printed_properly = true; } catch (Exception $e) { $vb_printed_properly = false; $this->postError(3100, _t("Could not generate PDF"), "DetailController->_genExport()"); } return; }
$arrBloques = $oDocumento->getBloquesDoc(); $arrSPBloques = getSpBloques($oDocumento, $arrBloques); } if (!empty($arrSPBloques)) { $arrCamposBloque = $oDocumento->getCamposBloque($arrSPBloques[0]); $arrItemsBloque = $oDocumento->getCamposBloque($arrSPBloques[1]); $arrTotales = $oDocumento->getCamposBloque($arrSPBloques[2]); $TPLOrden = getCamposTPL($arrCamposBloque[0], $arrItemsBloque, $arrTotales[0]); $dompdf = new DOMPDF(); $dompdf->load_html($TPLOrden); /* ini_set("max_execution_time","2500"); ini_set("max_input_time","180"); ini_set("memory_limit","200M"); */ $dompdf->set_base_path("pdfstyles.css"); $dompdf->render(); $array_opciones = array("afichero" => 1, "compress" => 1); $dompdf->stream("orden_de_reparacion.pdf", $array_opciones); /* $tmpfile = tempnam("/tmp", "dompdf_"); file_put_contents($tmpfile, $TPLOrden); // Replace $smarty->fetch()// with your HTML string $url = "PE/PDFGEN/dompdf/dompdf.php?input_file=" . rawurlencode($tmpfile) . "&paper=letter&output_file=" . rawurlencode("My Fancy PDF.pdf"); header("Location: http://localhost/jc_zurich_dcs/$url"); */ } /** * Retorno array con stores procedures listos para ejecutar. * @param array $arrBloques */
/** * Generates display summary of record data based upon a bundle display for print (PDF) * * @param array $pa_options Array of options passed through to _initView */ public function PrintSummary($pa_options = null) { AssetLoadManager::register('tableList'); list($vn_subject_id, $t_subject) = $this->_initView($pa_options); if (!$this->_checkAccess($t_subject)) { return false; } $t_display = new ca_bundle_displays(); $va_displays = $t_display->getBundleDisplays(array('table' => $t_subject->tableNum(), 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'restrictToTypes' => array($t_subject->getTypeID()))); if (!($vn_display_id = $this->request->getParameter('display_id', pInteger)) || !isset($va_displays[$vn_display_id])) { if (!($vn_display_id = $this->request->user->getVar($t_subject->tableName() . '_summary_display_id')) || !isset($va_displays[$vn_display_id])) { $va_tmp = array_keys($va_displays); $vn_display_id = $va_tmp[0]; } } $this->view->setVar('t_display', $t_display); $this->view->setVar('bundle_displays', $va_displays); // Check validity and access of specified display if ($t_display->load($vn_display_id) && $t_display->haveAccessToDisplay($this->request->getUserID(), __CA_BUNDLE_DISPLAY_READ_ACCESS__)) { $this->view->setVar('display_id', $vn_display_id); $va_placements = $t_display->getPlacements(array('returnAllAvailableIfEmpty' => true, 'table' => $t_subject->tableNum(), 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'no_tooltips' => true, 'format' => 'simple', 'settingsOnly' => true)); $va_display_list = array(); foreach ($va_placements as $vn_placement_id => $va_display_item) { $va_settings = caUnserializeForDatabase($va_display_item['settings']); // get column header text $vs_header = $va_display_item['display']; if (isset($va_settings['label']) && is_array($va_settings['label'])) { if ($vs_tmp = array_shift(caExtractValuesByUserLocale(array($va_settings['label'])))) { $vs_header = $vs_tmp; } } $va_display_list[$vn_placement_id] = array('placement_id' => $vn_placement_id, 'bundle_name' => $va_display_item['bundle_name'], 'display' => $vs_header, 'settings' => $va_settings); } $this->view->setVar('placements', $va_display_list); $this->request->user->setVar($t_subject->tableName() . '_summary_display_id', $vn_display_id); $vs_format = $this->request->config->get("summary_print_format"); } else { $this->view->setVar('display_id', null); $this->view->setVar('placements', array()); } // // PDF output // if (!is_array($va_template_info = caGetPrintTemplateDetails('summary', "{$this->ops_table_name}_summary"))) { if (!is_array($va_template_info = caGetPrintTemplateDetails('summary', "summary"))) { $this->postError(3110, _t("Could not find view for PDF"), "BaseEditorController->PrintSummary()"); return; } } $va_barcode_files_to_delete = array(); try { $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME)); $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local")); $va_barcode_files_to_delete += caDoPrintViewTagSubstitution($this->view, $t_subject, $va_template_info['path'], array('checkAccess' => $this->opa_access_values)); $vs_content = $this->render($va_template_info['path']); $o_dompdf = new DOMPDF(); $o_dompdf->load_html($vs_content); $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait')); $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('summary')); $o_dompdf->render(); $o_dompdf->stream(caGetOption('filename', $va_template_info, 'print_summary.pdf')); $vb_printed_properly = true; foreach ($va_barcode_files_to_delete as $vs_tmp) { @unlink($vs_tmp); } } catch (Exception $e) { foreach ($va_barcode_files_to_delete as $vs_tmp) { @unlink($vs_tmp); } $vb_printed_properly = false; $this->postError(3100, _t("Could not generate PDF"), "BaseEditorController->PrintSummary()"); } }
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; } } } }
/** * Generate export file of current result */ protected function _genExport($po_result, $ps_template, $ps_output_filename, $ps_title = null) { if ($this->opo_result_context) { $this->opo_result_context->setParameter('last_export_type', $ps_output_type); $this->opo_result_context->saveContext(); } if (substr($ps_template, 0, 5) === '_pdf_') { $va_template_info = caGetPrintTemplateDetails('results', substr($ps_template, 5)); } elseif (substr($ps_template, 0, 9) === '_display_') { $vn_display_id = substr($ps_template, 9); $t_display = new ca_bundle_displays($vn_display_id); if ($vn_display_id && $t_display->haveAccessToDisplay($this->request->getUserID(), __CA_BUNDLE_DISPLAY_READ_ACCESS__)) { $this->view->setVar('display', $t_display); $va_placements = $t_display->getPlacements(array('settingsOnly' => true)); foreach ($va_placements as $vn_placement_id => $va_display_item) { $va_settings = caUnserializeForDatabase($va_display_item['settings']); // get column header text $vs_header = $va_display_item['display']; if (isset($va_settings['label']) && is_array($va_settings['label'])) { $va_tmp = caExtractValuesByUserLocale(array($va_settings['label'])); if ($vs_tmp = array_shift($va_tmp)) { $vs_header = $vs_tmp; } } $va_display_list[$vn_placement_id] = array('placement_id' => $vn_placement_id, 'bundle_name' => $va_display_item['bundle_name'], 'display' => $vs_header, 'settings' => $va_settings); } $this->view->setVar('display_list', $va_display_list); } else { $this->postError(3100, _t("Invalid format %1", $ps_template), "FindController->_genExport()"); return; } $va_template_info = caGetPrintTemplateDetails('results', 'display'); } else { $this->postError(3100, _t("Invalid format %1", $ps_template), "FindController->_genExport()"); return; } // // PDF output // if (!is_array($va_template_info)) { $this->postError(3110, _t("Could not find view for PDF"), "FindController->_genExport()"); return; } try { $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME)); $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local")); set_time_limit(600); $vs_content = $this->render($va_template_info['path']); $o_dompdf = new DOMPDF(); $o_dompdf->load_html($vs_content); $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait')); $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('results')); $o_dompdf->render(); $o_dompdf->stream(caGetOption('filename', $va_template_info, 'export_results.pdf')); $vb_printed_properly = true; } catch (Exception $e) { $vb_printed_properly = false; $this->postError(3100, _t("Could not generate PDF"), "FindController->_genExport()"); } return; }
function process_print_view() { $form_id = $_GET["fid"]; $lead_id = $_GET["lid"]; $filename = "form-{$form_id}-entry-{$lead_id}.pdf"; $entry = GetRequire(dirname(__FILE__) . "/print-view.php"); //Parse the default print view from Gravity forms so we can play with it. $entry = absolutify_html($entry); //Load the DOMPDF Engine to render the PDF require_once "dompdf/dompdf_config.inc.php"; $dompdf = new DOMPDF(); $dompdf->load_html($entry); $dompdf->set_base_path(site_url()); $dompdf->render(); return $dompdf; }
/** * return a fwe invoices as a zipped collection of PDFs * * @return null */ function OnlineStore_adminInvoicesGetAsPdf() { $ids = explode(',', $_REQUEST['ids']); $files = array(); $foundIds = array(); foreach ($ids as $id) { $id = (int) $id; $pfile = USERBASE . '/ww.cache/online-store/invoice' . $id . '.pdf'; if (!file_exists($pfile)) { $hfile = USERBASE . '/ww.cache/online-store/invoice' . $id; if (!file_exists($hfile) || !filesize($hfile)) { $i = dbOne('select invoice from online_store_orders where id=' . $id, 'invoice'); if (!$i) { continue; } file_put_contents($hfile, "" . '<html><head><meta http-equiv="Content-Type"' . ' content="text/html;' . ' charset=UTF-8" /></head><body>' . utf8_encode($i) . '</body></html>'); } require_once $_SERVER['DOCUMENT_ROOT'] . '/ww.incs/dompdf/dompdf_config.inc.php'; $html = file_get_contents($hfile); $dompdf = new DOMPDF(); $dompdf->set_base_path($_SERVER['DOCUMENT_ROOT']); $dompdf->load_html(utf8_decode(str_replace('€', '€', $html)), 'UTF-8'); $dompdf->set_paper('a4'); $dompdf->render(); file_put_contents($pfile, $dompdf->output()); } $files[] = 'invoice' . $id . '.pdf'; $foundIds[] = $id; } $zdir = USERBASE . '/ww.cache/online-store/'; $zfile = USERBASE . '/ww.cache/online-store/invoices-' . join(',', $foundIds) . '.zip'; $filesToZip = join(' ', $files); `cd {$zdir} && zip -D {$zfile} {$filesToZip}`; header('Content-type: application/zip'); header('Content-Disposition: attachment; filename="invoices.zip"'); $fp = fopen($zfile, 'r'); fpassthru($fp); fclose($fp); Core_quit(); }
</tr> <tr style="background:' . $color . '"> <td colspan="14" ><span style="color:red;">' . $detail['reason'] . '</span> <span style="color:red;">Notes: ' . $detail['note'] . '</span></td> </tr>'; } $html = $html . ' </tbody> </table> </div> </div> </div>'; } $html = $html . ' </form>'; include "dompdf/dompdf_config.inc.php"; $html = preg_replace("@id=\"aclogo\">.*?</div>@is", 'id="aclogo"><img src="css/images/main_logo.jpg" width="200" class="img-responsive" alt="Logo" id="main_logo" style="padding-left:0px;"></div>', $html); $html = preg_replace("@id=\"ad1\\s*class.*?\"\\s*style.*?\"@is", '', $html); $html = str_replace('style="padding:20px 80px 0px 30px;"', "", $html); $html = preg_replace("@repAddress\">@is", 'id="repAddress"><table style="width:100%;"><tr><td>', $html); $html = preg_replace("@</div>\\s*<div id=\"repBy\".*?>@is", '</div></td><td>', $html); $html = preg_replace("@<span id=\"repClose\"></span>@", "</td></tr></table>", $html); $html = $html; $dompdf = new DOMPDF(); $dompdf->set_base_path(realpath(APPLICATION_PATH . 'css/bootstrap.css')); $dompdf->set_base_path(realpath(APPLICATION_PATH . 'css/bootstrap-theme.css')); $dompdf->set_base_path(realpath(APPLICATION_PATH . 'css/style.css')); $dompdf->load_html($html); $dompdf->render(); $dompdf->stream("{$id}.pdf");
/** * Generate export file of current result */ protected function _genExport($po_result, $ps_output_type, $ps_output_filename, $ps_title = null) { $this->view->setVar('criteria_summary', $vs_criteria_summary = $this->getCriteriaForDisplay()); // add displayable description of current search/browse parameters $this->view->setVar('criteria_summary_truncated', mb_substr($vs_criteria_summary, 0, 60) . (mb_strlen($vs_criteria_summary) > 60 ? '...' : '')); $this->opo_result_context->setParameter('last_export_type', $ps_output_type); $this->opo_result_context->saveContext(); if (substr($ps_output_type, 0, 4) !== '_pdf') { switch ($ps_output_type) { case '_xlsx': require_once __CA_LIB_DIR__ . "/core/Parsers/PHPExcel/PHPExcel.php"; require_once __CA_LIB_DIR__ . "/core/Parsers/PHPExcel/PHPExcel/Writer/Excel2007.php"; $vs_content = $this->render('Results/xlsx_results.php'); return; case '_csv': $vs_delimiter = ","; $vs_output_file_name = mb_substr(preg_replace("/[^A-Za-z0-9\\-]+/", '_', $ps_output_filename . '_csv'), 0, 30); $vs_file_extension = 'txt'; $vs_mimetype = "text/plain"; break; case '_tab': $vs_delimiter = "\t"; $vs_output_file_name = mb_substr(preg_replace("/[^A-Za-z0-9\\-]+/", '_', $ps_output_filename . '_tab'), 0, 30); $vs_file_extension = 'txt'; $vs_mimetype = "text/plain"; default: // TODO add exporter code here break; } header("Content-Disposition: attachment; filename=export_" . $vs_output_file_name . "." . $vs_file_extension); header("Content-type: " . $vs_mimetype); // get display list self::Index(null, null); $va_display_list = $this->view->getVar('display_list'); $va_rows = array(); // output header $va_row = array(); foreach ($va_display_list as $va_display_item) { $va_row[] = $va_display_item['display']; } $va_rows[] = join($vs_delimiter, $va_row); $po_result->seek(0); $t_display = $this->view->getVar('t_display'); while ($po_result->nextHit()) { $va_row = array(); foreach ($va_display_list as $vn_placement_id => $va_display_item) { $vs_value = html_entity_decode($t_display->getDisplayValue($po_result, $vn_placement_id, array('convert_codes_to_display_text' => true, 'convertLineBreaks' => false)), ENT_QUOTES, 'UTF-8'); // quote values as required if (preg_match("![^A-Za-z0-9 .;]+!", $vs_value)) { $vs_value = '"' . str_replace('"', '""', $vs_value) . '"'; } $va_row[] = $vs_value; } $va_rows[] = join($vs_delimiter, $va_row); } $this->opo_response->addContent(join("\n", $va_rows), 'view'); } else { // // PDF output // $va_template_info = caGetPrintTemplateDetails('results', substr($ps_output_type, 5)); if (!is_array($va_template_info)) { $this->postError(3110, _t("Could not find view for PDF"), "BaseFindController->PrintSummary()"); return; } try { $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME)); $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local")); $vs_content = $this->render($va_template_info['path']); $o_dompdf = new DOMPDF(); $o_dompdf->load_html($vs_content); $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait')); $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('results')); $o_dompdf->render(); $o_dompdf->stream(caGetOption('filename', $va_template_info, 'export_results.pdf')); $vb_printed_properly = true; } catch (Exception $e) { $vb_printed_properly = false; $this->postError(3100, _t("Could not generate PDF"), "BaseFindController->PrintSummary()"); } return; } }
<?php //$tmpfile = tempnam("/home/utopic/phpninja.info/tshirts/customAPP/php/dompdf/tmp", "dompdf_"); //require '../vendor/autoload.php'; define('DOMPDF_ENABLE_AUTOLOAD', false); require_once dirname(__FILE__) . "/dompdf/dompdf_config.inc.php"; $html = '<html> <head> <base href="http://www.phpninja.info/tshirts/"></base> <link href="customAPP/css/master.css" rel="stylesheet" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style></head><body><div id="custom">'; $html .= $_GET['html']; $html .= '</div></body></html>'; $dompdf = new DOMPDF(); $dompdf->set_base_path(dirname(__FILE__) . '/../temp/'); //$dompdf->set_paper('a4'); $dompdf->load_html($html); $dompdf->render(); $dompdf->stream("sample.pdf");
#comps td{ font-size:10px; height:30px; } #ucomps{ } #ucomps td{ font-size:10px; height:30px; } .headAddress { font-size:16px; } .headAdd { font-size:14px; } #graph td{ height:5px;} </style>' . $_POST['cc']; $html = $_POST['cc']; preg_match("@downloadReport\\s*<br>(.*?)downloadReport@is", $html, $matches); $html = $matches[1]; $html = preg_replace("@src=\"http.*?\".*?>@", "src='{$id}.jpg' width='400'>", $html); /*$html = preg_replace("@style=\"padding:20px 0px 20px 30px;\"@", "", $html); $html = preg_replace("@<div id=\"repbtn\".*?<\/form>|<button type=\"button.*><\/button>@is", "", $html); $html = str_replace('<button type="button" class="btn btn-success" style="margin:3px;" onclick="convert_pdf();">Create Report</button>', "", $html); $html = preg_replace("@id=\"aclogo\">.*?</div>@is", 'id="aclogo"><img src="css/images/main_logo.jpg" width="200" class="img-responsive" alt="Logo" id="main_logo" style="padding-left:0px;"></div>',$html); $html = preg_replace("@id=\"ad1\s*class.*?\"\s*style.*?\"@is",'',$html); $html = str_replace('style="padding:20px 80px 0px 30px;"',"",$html); $html = preg_replace("@repAddress\">@is",'id="repAddress"><table style="width:100%;"><tr><td>',$html); $html = preg_replace("@</div>\s*<div id=\"repBy\".*?>@is",'</div></td><td>',$html); $html = preg_replace("@<span id=\"repClose\"></span>@","</td></tr></table>",$html);*/ /*$html = preg_replace("@<div id=\"break\"></div>@is","<div><br/><br/><br/></div>",$html);*/ include "dompdf/dompdf_config.inc.php"; $html = $css . $html; $dompdf = new DOMPDF(); $dompdf->set_base_path(realpath(APPLICATION_PATH . 'css/style.css')); $dompdf->load_html($html); $dompdf->render(); $dompdf->stream("{$id}.pdf");
/** * createPDF() * creates a PDF document for a given html file * * @param string the html file to convert to pdf * @return string returns the pdf in binary/string stream */ function createPDF($html) { global $base; // instansiate the pdf document $dompdf = new DOMPDF(); $dompdf->set_base_path("{$base}/templates/"); $dompdf->load_html($html); $dompdf->render(); $notification_pdf = $dompdf->output(); return $notification_pdf; }
/** * Generates display for specific bundle or (optionally) a specific repetition in a bundle * ** Right now only attribute bundles are supported for printing ** * * @param array $pa_options Array of options passed through to _initView */ public function PrintBundle($pa_options = null) { list($vn_subject_id, $t_subject) = $this->_initView($pa_options); if (!$this->_checkAccess($t_subject)) { return false; } // // PDF output // $vs_template = substr($this->request->getParameter('template', pString), 5); // get rid of _pdf_ prefix if (!is_array($va_template_info = caGetPrintTemplateDetails('bundles', $vs_template))) { $this->postError(3110, _t("Could not find view for PDF"), "BaseEditorController->PrintBundle()"); return; } // Element code to display $vs_element = $this->request->getParameter('element_code', pString); $vn_attribute_id = $this->request->getParameter('attribute_id', pString); // Does user have access to this element? if ($this->request->user->getBundleAccessLevel($t_subject->tableName(), $vs_element) == __CA_BUNDLE_ACCESS_NONE__) { $this->postError(2320, _t("No access to element"), "BaseEditorController->PrintBundle()"); return; } // Add raw array of values to view if ($vn_attribute_id > 0) { $o_attr = $t_subject->getAttributeByID($vn_attribute_id); if ((int) $o_attr->getRowID() !== (int) $vn_subject_id || (int) $o_attr->getTableNum() !== (int) $t_subject->tableNum()) { $this->postError(2320, _t("Element is not part of current item"), "BaseEditorController->PrintBundle()"); return; } $this->view->setVar('valuesAsAttributeInstances', $va_values = array($o_attr)); } else { $this->view->setVar('valuesAsAttributeInstances', $va_values = $t_subject->getAttributesByElement($vs_element)); } // Extract values into array for easier view processing $va_extracted_values = array(); foreach ($va_values as $o_value) { $va_extracted_values[] = $o_value->getDisplayValues(); } $this->view->setVar('valuesAsElementCodeArrays', $va_extracted_values); $va_barcode_files_to_delete = array(); try { $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME)); $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local")); $va_barcode_files_to_delete += caDoPrintViewTagSubstitution($this->view, $t_subject, $va_template_info['path'], array('checkAccess' => $this->opa_access_values)); $vs_content = $this->render($va_template_info['path']); $o_dompdf = new DOMPDF(); $o_dompdf->load_html($vs_content); $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait')); $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('summary')); $o_dompdf->render(); $o_dompdf->stream(caGetOption('filename', $va_template_info, 'print_bundles.pdf')); $vb_printed_properly = true; foreach ($va_barcode_files_to_delete as $vs_tmp) { @unlink($vs_tmp); } } catch (Exception $e) { foreach ($va_barcode_files_to_delete as $vs_tmp) { @unlink($vs_tmp); } $vb_printed_properly = false; $this->postError(3100, _t("Could not generate PDF"), "BaseEditorController->PrintBundle()"); } }
$save_file = false; # Don't save the file break; } $dompdf = new DOMPDF(); if ($file == "-") { $str = ""; while (!feof(STDIN)) { $str .= fread(STDIN, 4096); } $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) { foreach ($_dompdf_warnings as $msg) { echo $msg . "\n"; } 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); }
€ 0,0- </td> </tr> <tr> <td colspan="2"> <div class="bordertop" style="margin-bottom: 10px;"></div> </td> </tr> <tr> <td class="heading"> Totaal </td> <td class="body"> € ' . $totaal . ',- </td> </tr> </table> </div> </td> </tr> </table> </div> <div class="bluebar footer"></div> </body> </html> '; $dompdf->load_html($html); $dompdf->render(); $dompdf->set_base_path('../core/css/pdf.css'); $dompdf->stream($reserveringnr, array("Attachment" => 0));