function get_base_url() { return ""; } } $media = Media::predefined("A4"); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0)); $media->set_pixels(1024); $GLOBALS['g_config'] = array('cssmedia' => 'screen', 'renderimages' => true, 'renderforms' => false, 'renderlinks' => true, 'renderfields' => true, 'mode' => 'html', 'debugbox' => false, 'draw_page_border' => false); $g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels; $g_pt_scale = $g_px_scale * 1.43; $pipeline = new Pipeline(); $pipeline->configure($GLOBALS['g_config']); $pipeline->fetchers[] = new MyFetcherLocalFile(); // $pipeline->destination = new MyDestinationFile($pdf); $pipeline->destination = new MyDestinationDownload($pdf); $pipeline->data_filters[] = new DataFilterHTML2XHTML(); $pipeline->pre_tree_filters = array(); $header_html = "test"; $footer_html = "test"; $filter = new PreTreeFilterHeaderFooter($header_html, $footer_html); $pipeline->pre_tree_filters[] = $filter; $pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields(); $pipeline->parser = new ParserXHTML(); $pipeline->layout_engine = new LayoutEngineDefault(); $pipeline->output_driver = new OutputDriverFPDF($media); $pipeline->process('', $media); } convert_to_pdf("test");
$this->_content = file_get_contents($file); } function get_data($dummy1) { return new FetchedDataURL($this->_content, array(), ""); } function get_base_url() { return ""; } } $pipeline = PipelineFactory::create_default_pipeline("", ""); // Override HTML source $pipeline->fetchers[] = new MyFetcherLocalFile($path_to_html); // Override destination to local file $pipeline->destination = new MyDestinationFile($path_to_pdf); $baseurl = ""; $media = Media::predefined("A4"); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0)); $media->set_pixels(1024); global $g_config; $g_config = array('cssmedia' => 'screen', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false); global $g_px_scale; $g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels; global $g_pt_scale; $g_pt_scale = $g_px_scale * 1.43; $pipeline->process($baseurl, $media); } convert_to_pdf("./testing/forms.html", "./testing/forms.pdf");
/** * Runs the HTML->PDF conversion with default settings * * Warning: if you have any files (like CSS stylesheets and/or images referenced by this file, * use absolute links (like http://my.host/image.gif). * * @param $path_to_html String path to source html file. * @param $path_to_pdf String path to file to save generated PDF to. */ function convert_to_pdf($path_to_html, $path_to_pdf) { $pipeline = PipelineFactory::create_default_pipeline("", ""); // Override HTML source $pipeline->fetchers[] = new MyFetcherLocalFile($path_to_html); $filter = new PreTreeFilterHeaderFooter("HEADER", "FOOTER"); $pipeline->pre_tree_filters[] = $filter; // Override destination to local file $pipeline->destination = new MyDestinationFile($path_to_pdf); $baseurl = ""; $media = Media::predefined("A4"); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 10, 'bottom' => 10)); $media->set_pixels(1024); global $g_config; $g_config = array('cssmedia' => 'screen', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false); $pipeline->configure($g_config); $pipeline->add_feature('toc', array('location' => 'before')); $pipeline->process($baseurl, $media); } convert_to_pdf("../temp/test.html", "../out/test.pdf");
/** * Runs the HTML->PDF conversion with default settings * * Warning: if you have any files (like CSS stylesheets and/or images referenced by this file, * use absolute links (like http://my.host/image.gif). * * @param $path_to_html String HTML code to be converted * @param $path_to_pdf String path to file to save generated PDF to. * @param $base_path String base path to use when resolving relative links in HTML code. */ function convert_to_pdf($html, $path_to_pdf, $base_path = '') { $pipeline = PipelineFactory::create_default_pipeline('', ''); // Override HTML source // @TODO: default http fetcher will return null on incorrect images // Bug submitted by 'imatronix' (tufat.com forum). $pipeline->fetchers[] = new MyFetcherMemory($html, $base_path); // Override destination to local file $pipeline->destination = new MyDestinationFile($path_to_pdf); $baseurl = ''; $media =& Media::predefined('A4'); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0)); $media->set_pixels(1024); global $g_config; $g_config = array('cssmedia' => 'screen', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false); $pipeline->configure($g_config); $pipeline->process_batch(array($baseurl), $media); } convert_to_pdf(file_get_contents('../temp/long.html'), '../out/test.pdf');
function pdfThis($html, $file_location = "", $pdfname) { global $config; // set_include_path("../../../../library/pdf/"); require_once './library/pdf/config.inc.php'; require_once './library/pdf/pipeline.factory.class.php'; require_once './library/pdf/pipeline.class.php'; parse_config_file('./library/pdf/html2ps.config'); require_once "./include/init.php"; // for getInvoice() and getPreference() #$invoice_id = $_GET['id']; #$invoice = getInvoice($invoice_id); #$preference = getPreference($invoice['preference_id']); #$pdfname = trim($preference['pref_inv_wording']) . $invoice_id; #error_reporting(E_ALL); #ini_set("display_errors","1"); #@set_time_limit(10000); /** * Runs the HTML->PDF conversion with default settings * * Warning: if you have any files (like CSS stylesheets and/or images referenced by this file, * use absolute links (like http://my.host/image.gif). * * @param $path_to_html String path to source html file. * @param $path_to_pdf String path to file to save generated PDF to. */ if (!function_exists(convert_to_pdf)) { function convert_to_pdf($html_to_pdf, $pdfname, $file_location = "") { global $config; $destination = $file_location == "download" ? "DestinationDownload" : "DestinationFile"; /** * Handles the saving generated PDF to user-defined output file on server */ if (!class_exists(MyFetcherLocalFile)) { class MyFetcherLocalFile extends Fetcher { var $_content; function MyFetcherLocalFile($html_to_pdf) { //$this->_content = file_get_contents($file); $this->_content = $html_to_pdf; } function get_data($dummy1) { return new FetchedDataURL($this->_content, array(), ""); } function get_base_url() { return ""; } } } $pipeline = PipelineFactory::create_default_pipeline("", ""); // Attempt to auto-detect encoding // Override HTML source $pipeline->fetchers[] = new MyFetcherLocalFile($html_to_pdf); $baseurl = ""; $media = Media::predefined($config->export->pdf->papersize); $media->set_landscape(false); global $g_config; $g_config = array('cssmedia' => 'screen', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'process_mode' => 'single', 'pixels' => $config->export->pdf->screensize, 'media' => $config->export->pdf->papersize, 'margins' => array('left' => $config->export->pdf->leftmargin, 'right' => $config->export->pdf->rightmargin, 'top' => $config->export->pdf->topmargin, 'bottom' => $config->export->pdf->bottommargin), 'transparency_workaround' => 1, 'imagequality_workaround' => 1, 'draw_page_border' => false); $media->set_margins($g_config['margins']); $media->set_pixels($config->export->pdf->screensize); /* header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Location: $myloc"); */ global $g_px_scale; $g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels; global $g_pt_scale; $g_pt_scale = $g_px_scale * 1.43; $pipeline->configure($g_config); $pipeline->data_filters[] = new DataFilterUTF8(""); $pipeline->destination = new $destination($pdfname); $pipeline->process($baseurl, $media); } } //echo "location: ".$file_location; convert_to_pdf($html, $pdfname, $file_location); }
$this->_content = $file; } function get_data($dummy1) { return new FetchedDataURL($this->_content, array(), ""); } function get_base_url() { return ""; } } $pipeline = PipelineFactory::create_default_pipeline("", ""); // Override HTML source $pipeline->fetchers[] = new MyFetcherLocalFile($path_to_html); // Override destination to local file $pipeline->destination = new MyDestinationFile($path_to_pdf); $baseurl = ""; $media = Media::predefined("A4"); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0)); $media->set_pixels(1024); global $g_config; $g_config = array('cssmedia' => 'screen', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false); global $g_px_scale; $g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels; global $g_pt_scale; $g_pt_scale = $g_px_scale * 1.43; $pipeline->process($baseurl, $media); } convert_to_pdf("<html>TEST PDF</html>", "forms.pdf");
} /** * Runs the HTML->PDF conversion with default settings * * Warning: if you have any files (like CSS stylesheets and/or images referenced by this file, * use absolute links (like http://my.host/image.gif). * * @param $path_to_html String path to source html file. * @param $path_to_pdf String path to file to save generated PDF to. */ function convert_to_pdf($path_to_html, $path_to_pdf) { $pipeline = PipelineFactory::create_default_pipeline("", ""); // Override HTML source $pipeline->fetchers[] = new MyFetcherLocalFile($path_to_html); $filter = new PreTreeFilterHeaderFooter("HEADER", "FOOTER"); $pipeline->pre_tree_filters[] = $filter; // Override destination to local file $pipeline->destination = new MyDestinationFile($path_to_pdf); $baseurl = ""; $media = Media::predefined("A4"); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 10, 'bottom' => 10)); $media->set_pixels(1024); global $g_config; $g_config = array('cssmedia' => 'screen', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false); $pipeline->configure($g_config); $pipeline->process($baseurl, $media); } convert_to_pdf("../testsuite/encoding/iso-8859-2.html", "../data/testing/test.pdf");
/** * Runs the HTML->PDF conversion with default settings * * Warning: if you have any files (like CSS stylesheets and/or images referenced by this file, * use absolute links (like http://my.host/image.gif). * * @param $path_to_html String HTML code to be converted * @param $path_to_pdf String path to file to save generated PDF to. * @param $base_path String base path to use when resolving relative links in HTML code. */ function convert_to_pdf($html, $path_to_pdf, $base_path = "") { $pipeline = PipelineFactory::create_default_pipeline("", ""); // Override HTML source // @TODO: default http fetcher will return null on incorrect images // Bug submitted by 'imatronix' (tufat.com forum). $pipeline->fetchers[] = new MyFetcherMemory($html, $base_path); // Override destination to local file $pipeline->destination = new MyDestinationFile($path_to_pdf); $baseurl = ""; $media = Media::predefined("A4"); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0)); $media->set_pixels(1024); global $g_config; $g_config = array('cssmedia' => 'screen', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false); $pipeline->configure($g_config); $pipeline->process($baseurl, $media); } convert_to_pdf(file_get_contents("../testsuite/encoding/iso-8859-2.html"), "../data/testing/test.pdf");
function convert_html2pdf($html, $pdf) { // start conversion //require_once('includes/html2ps/dave.php'); $library = module_config::c('pdf_library'); if (!$library && file_exists(dirname(__FILE__) . '/mpdf/mpdf.php')) { $library = 'mpdf'; } switch ($library) { case 'mpdf': if (file_exists(dirname(__FILE__) . '/mpdf/mpdf.php')) { //require_once ( dirname( __FILE__ ) . '/mpdf/mpdf.php' ); require_once module_theme::include_ucm('includes/plugin_pdf/mpdf/mpdf.php'); $html_contents = file_get_contents($html); $mpdf = new mPDF('', module_config::c('pdf_media_size', 'A4'), 0, '', module_config::c('pdf_media_left', '10'), module_config::c('pdf_media_right', '10'), module_config::c('pdf_media_top', '10'), module_config::c('pdf_media_bottom', '10'), 8, 8); $mpdf->debug = true; $mpdf->WriteHTML($html_contents); //$mpdf->Output($pdf,'D'); // Download $mpdf->Output($pdf, 'F'); break; } default: ini_set('error_reporting', E_ERROR); ini_set("display_errors", true); require_once 'html2ps/config.inc.php'; require_once HTML2PS_DIR . 'pipeline.factory.class.php'; set_time_limit(120); parse_config_file(HTML2PS_DIR . 'html2ps.config'); global $g_font_resolver_pdf; // print_r($g_font_resolver_pdf->ttf_mappings); exit; $g_font_resolver_pdf->ttf_mappings['Arial Unicode MS'] = module_config::c('pdf_unicode_font', 'arialuni.ttf'); /** * Handles the saving generated PDF to user-defined output file on server */ if (!class_exists('MyDestinationFile', false)) { class MyDestinationFile extends Destination { /** * @var String result file name / path * @access private */ var $_dest_filename; function MyDestinationFile($dest_filename) { $this->_dest_filename = $dest_filename; } function process($tmp_filename, $content_type) { copy($tmp_filename, $this->_dest_filename); } } class MyFetcherLocalFile extends Fetcher { var $_content; function MyFetcherLocalFile($file) { $this->_content = file_get_contents($file); } function get_data($dummy1) { return new FetchedDataURL($this->_content, array(), ""); } function get_base_url() { return "http://" . $_SERVER['HTTP_HOST'] . '/'; } } /** * Runs the HTML->PDF conversion with default settings * * Warning: if you have any files (like CSS stylesheets and/or images referenced by this file, * use absolute links (like http://my.host/image.gif). * * @param $path_to_html String path to source html file. * @param $path_to_pdf String path to file to save generated PDF to. */ function convert_to_pdf($path_to_html, $path_to_pdf) { $pipeline = PipelineFactory::create_default_pipeline("", ""); // Override HTML source $pipeline->fetchers[] = new MyFetcherLocalFile($path_to_html); //$filter = new PreTreeFilterHeaderFooter("HEADER", "FOOTER"); //$pipeline->pre_tree_filters[] = $filter; // Override destination to local file $pipeline->destination = new MyDestinationFile($path_to_pdf); $baseurl = ""; $media = Media::predefined(module_config::c('pdf_media_size', 'A4')); $media->set_landscape(false); $media->set_margins(array('left' => module_config::c('pdf_media_left', '0'), 'right' => module_config::c('pdf_media_right', '0'), 'top' => module_config::c('pdf_media_top', '0'), 'bottom' => module_config::c('pdf_media_bottom', '0'))); $media->set_pixels(module_config::c('pdf_media_pixels', '1010')); global $g_config; $g_config = array('compress' => true, 'cssmedia' => 'screen', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => 'UTF-8', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false, 'media' => module_config::c('pdf_media_size', 'A4')); $pipeline->configure($g_config); //$pipeline->add_feature('toc', array('location' => 'before')); $pipeline->process($baseurl, $media); } } convert_to_pdf($html, $pdf); break; } return str_replace(_UCM_FOLDER, '', $pdf); }
function pdf_convert_and_download($html_filename, $download_filename = null, $orientation = "Portrait") { $html_to_convert = file_get_contents($html_filename); if (!$download_filename) { $download_filename = gen_id() . '.pdf'; } //generate the pdf $pdf_filename = convert_to_pdf($html_to_convert, $orientation, gen_id()); if ($pdf_filename) { include_once ROOT . "/library/browser/Browser.php"; if (Browser::instance()->getBrowser() == Browser::BROWSER_IE) { evt_add('download_tmp_file', array('file_name' => $pdf_filename, 'file_type' => 'application/pdf')); } else { download_file(ROOT . "/tmp/" . $pdf_filename, 'application/pdf', $download_filename, true); } } }