ok, i try
lets start with:
I use
MODx 1.0.3
my PDF document is 441
I have chosen to put the
[!tcpd!] in blank template - the PDF document (441) is empty.
I
don’t use the "contentType" Plugin any more, because Evolution has the option to select contentType PDF on each Document.
The Snippet is:
<?php
//collect here your output in $output, use $modx->runsnippet or what else for generating your html-output.
$docid = $_REQUEST['docid'];
$table = $modx->getFullTableName("site_content");
$pagetitle = $modx->db->getValue( $modx->db->select("longtitle", $table, 'id='.$docid,"",""));
$longtitle = $modx->db->getValue( $modx->db->select("longtitle", $table, 'id='.$docid,"",""));
$introtext = $modx->db->getValue( $modx->db->select("introtext", $table, 'id='.$docid,"",""));
$content = $modx->db->getValue( $modx->db->select("content", $table, 'id='.$docid,"",""));
$output = '<h1>'.$pagetitle.'</h1><h2>'.$longtitle.'</h2>'.$content;
$basePath = $modx->config['base_path'];
$pluginpath = $basePath.'assets/classes/tcpdf/';
if ($_GET['contentType']=='pdf'){
include $pluginpath.'examples/myexample.php';
}
else{
return $output;
}
?>
myexample.php is:
<?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/ger.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
//============================================================+
?>
this do work:
- creating PDFs if $output gets plain text (changed the snippets to get this happen)
- without correct docid it creates an empty PDF
this don’t work:
- getting content, title and so on in the PDF
this would be perfect:
- don’t need an extra template and document and run the hole thing by placing an chunk in a document.
- have a snippet with individual text (should be easily made with $text=`download as PDF` or something - i think I will try this after everything works)
a plugin to auto-create new PDFs of a document after saving a document so that they will be saved in a folder and won’t be create each time someone would like ti download
thank you for help