[!tcpdf!]
<?php //collect here your output in $output, use $modx->runsnippet or what else for generating your html-output. $basePath = $modx->config['base_path']; $pluginpath = $basePath.'assets/classes/tcpdf/'; if ($_GET['contentType']=='pdf'){ include $pluginpath.'examples/myexample.php'; } else{ return $output; } ?>
<?php //============================================================+ // File name : example_001.php // Begin : 2008-03-04 // Last Update : 2009-03-18 // // Description : Example 001 for TCPDF class // Default Header and Footer // // Author: Nicola Asuni // // (c) Copyright: // Nicola Asuni // Tecnick.com s.r.l. // Via Della Pace, 11 // 09044 Quartucciu (CA) // ITALY // www.tecnick.com // [email protected] //============================================================+ /** * Creates an example PDF TEST document using TCPDF * @package com.tecnick.tcpdf * @abstract TCPDF - Example: Default Header and Footer * @author Nicola Asuni * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - [email protected] * @link http://tcpdf.org * @license http://www.gnu.org/copyleft/lesser.html LGPL * @since 2008-03-04 */ //(dirname( __FILE__ )."/../../rennergebnis/includes/getdatas.php"); require_once(dirname( __FILE__ ).'/../config/lang/de.php'); require_once(dirname( __FILE__ ).'/../tcpdf.php'); // create new PDF document //$pdf = new BLOCKPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example 001'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); $pdf->SetFont('helvetica', '', 9); // add a page $pdf->AddPage(); $pdf->writeHTML($output); // --------------------------------------------------------- //Close and output PDF document $pdf->Output('myexample.pdf', 'I'); if(isset($_GET['savepdf'])){ $pdf->Output($modx->config['base_path']."assets/files/pdfdownloads/".$_GET['savepdf'].".pdf", "F"); } //============================================================+ // END OF FILE //============================================================+ ?>
<?php $e = & $modx->event; switch($e->name) { case 'OnLoadWebDocument': if (isset($_GET['contentType']) && $_GET['contentType']=='pdf') { $modx->contentTypes[$modx->documentObject['id']]='application/pdf'; } break; } ?>
<a href="[~501~]&task=rennergebnis&contentType=pdf" target="_blank">PDF-Ausgabe</a> <a href="[~501~]&task=rennergebnis&contentType=pdf&savepdf=Rennergebnis_[+regatta_jahr+]" target="_blank">Als PDF-Download speichern </a>
Think you need to install and set right paths --> http://sourceforge.net/projects/tcpdf/files/
<?php //collect here your output in $output, use $modx->runsnippet or what else for generating your html-output. $basePath = $modx->config['base_path']; $pluginpath = $basePath.'assets/classes/tcpdf/'; if ($_GET['contentType']=='pdf'){ include $pluginpath.'examples/myexample.php'; } else{ return $output; } ?>
<?php //============================================================+ // File name : example_001.php // Begin : 2008-03-04 // Last Update : 2009-03-18 // // Description : Example 001 for TCPDF class // Default Header and Footer // // Author: Nicola Asuni // // (c) Copyright: // Nicola Asuni // Tecnick.com s.r.l. // Via Della Pace, 11 // 09044 Quartucciu (CA) // ITALY // www.tecnick.com // [email protected] //============================================================+ /** * Creates an example PDF TEST document using TCPDF * @package com.tecnick.tcpdf * @abstract TCPDF - Example: Default Header and Footer * @author Nicola Asuni * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - [email protected] * @link http://tcpdf.org * @license http://www.gnu.org/copyleft/lesser.html LGPL * @since 2008-03-04 */ //(dirname( __FILE__ )."/../../rennergebnis/includes/getdatas.php"); require_once(dirname( __FILE__ ).'/../config/lang/de.php'); require_once(dirname( __FILE__ ).'/../tcpdf.php'); // create new PDF document $pdf = new BLOCKPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example 001'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); $pdf->SetFont('helvetica', '', 9); // add a page $pdf->AddPage(); $pdf->writeHTML($output); // --------------------------------------------------------- //Close and output PDF document $pdf->Output('myexample.pdf', 'I'); if(isset($_GET['savepdf'])){ $pdf->Output($modx->config['base_path']."assets/files/pdfdownloads/".$_GET['savepdf'].".pdf", "F"); } //============================================================+ // END OF FILE //============================================================+ ?>
<?php $e = & $modx->event; switch($e->name) { case 'OnLoadWebDocument': if (isset($_GET['contentType']) && $_GET['contentType']=='pdf') { $modx->contentTypes[$modx->documentObject['id']]='application/pdf'; } break; } ?>
<a href="[~479~]&task=rennergebnis&contentType=pdf" target="_blank">DOWN PDF</a>
//$pdf = new BLOCKPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
i try twice - nope
1. if you have [!tcpdf!] in your content, you need [*content*] in your template, or only [!tcpdf!] in your template
2. do you have some html-content collected in $output?
3. this dosn’t matter, but you do not need &task=rennergebnis, this is only for my environment where I can have different tasks in my snippet, which collects the output.
4. try your link first without &contentType=pdf. If you get some html-content then try <a href="[~479~]&contentType=pdf" target="_blank">DOWN PDF</a>
5. did you check OnLoadWebDocument for your plugin?
OK - remove tags <?php ?> in plugin
6. Aah, and do not use <?php .............................. ?> in your plugin, only the code between!
OK, changed
7. I had a bug in myexample.php change:
//$pdf = new BLOCKPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
I have extented TCPDF to BLOCKPDF, where I can have <tcpdf method="Block" params="begin" /> in my html to stop TCPDF split blocks over two pages