Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you try change:</p> <pre><code>App::import('Vendor','xtcpdf'); </code></pre> <p>to</p> <pre><code>App::import('Vendor','tcpdf/xtcpdf'); </code></pre> <p>or maybe following this tutorial: <a href="http://www.pedroventura.com/cakephp/crear-archivos-pdf-con-cakephp/" rel="nofollow">http://www.pedroventura.com/cakephp/crear-archivos-pdf-con-cakephp/</a></p> <p>summary:</p> <p>file: app/vendors/tcpdf/xtcpdf.php</p> <pre><code>&lt;?php App::import('Vendor','tcpdf/tcpdf'); class XTCPDF extends TCPDF { var $xheadertext = 'PDF creado using CakePHP y TCPDF'; var $xheadercolor = array(0,0,200); var $xfootertext = 'Copyright © %d XXXXXXXXXXX. All rights reserved.'; var $xfooterfont = PDF_FONT_NAME_MAIN ; var $xfooterfontsize = 8 ; function Header() { list($r, $b, $g) = $this-&gt;xheadercolor; $this-&gt;setY(10); $this-&gt;SetFillColor($r, $b, $g); $this-&gt;SetTextColor(0 , 0, 0); $this-&gt;Cell(0,20, '', 0,1,'C', 1); $this-&gt;Text(15,26,$this-&gt;xheadertext ); } function Footer() { $year = date('Y'); $footertext = sprintf($this-&gt;xfootertext, $year); $this-&gt;SetY(-20); $this-&gt;SetTextColor(0, 0, 0); $this-&gt;SetFont($this-&gt;xfooterfont,'',$this-&gt;xfooterfontsize); $this-&gt;Cell(0,8, $footertext,'T',1,'C'); } } ?&gt; </code></pre> <p>file: app/views/layouts/pdf.ctp</p> <pre><code>&lt;?php header("Content-type: application/pdf"); echo $content_for_layout; ?&gt; </code></pre> <p>action in controller: </p> <pre><code>function descargar($id = null) { if (!$id) { $this-&gt;Session-&gt;setFlash('no has seleccionado ningun pdf.'); $this-&gt;redirect(array('action'=&gt;'index')); } Configure::write('debug',0); $resultado = $this-&gt;MiControlador-&gt;findById($id); // info from database $this-&gt;set("datos_pdf",$resultado); // info to view (pdf) $this-&gt;layout = 'pdf'; $this-&gt;render(); } </code></pre> <p>and file: app/views/mi_aplicacion/descargar.ctp</p> <pre><code>&lt;?php App::import('Vendor','tcpdf/xtcpdf'); $tcpdf = new XTCPDF(); $textfont = 'freesans'; $tcpdf-&gt;SetAuthor(""); $tcpdf-&gt;SetAutoPageBreak( false ); $tcpdf-&gt;setHeaderFont(array($textfont,'',10)); $tcpdf-&gt;xheadercolor = array(255,255,255); $tcpdf-&gt;xheadertext = 'Fecha: '. date('d-m-Y',time()); $tcpdf-&gt;xfootertext = 'www.example.cl'; $tcpdf-&gt;AddPage(); $tcpdf-&gt;SetTextColor(0, 0, 0); $tcpdf-&gt;SetFont($textfont,'B',10); $tcpdf-&gt;Cell(10,20,'Nombre:', 0, 0); // more info echo $tcpdf-&gt;Output('mi_archivo.pdf', 'D'); //D or I ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload