don't remember so well, but here are the notes I took to get something
to work:
*******************************************************
1) Download the TCPDF files from TCPDF.org (php5 is OK)
2) Extract to app/vendors/tcpdf (to not get dir in dir, extract to app/
vendors)
3) Create a new layout called pdf.ctp
=============
<?php
header("Content-type: application/pdf");
echo $content_for_layout;
?>
=============
4) Do a function like this in the controller:
=============
function viewPdf($id = null)
{
Configure::write('debug',0); // Otherwise we cannot use this
method while developing
$this->layout = 'pdf'; //this will use the pdf.ctp layout
$this->render();
}
=============
5) Create a view view_pdf.ctp:
=============
<?php
App::import('Vendor','tcpdf');
(...paste tcpdf example code here starting from line
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
true);
...)
=============
examples usually end with:
//Close and output PDF document
$pdf->Output("example_001.pdf", "I");
running the view should now launch the pdf save or open dialog
*******************************************************
This did work for me, so perhaps it can help you. You're probably best
off starting from scratch, but some things I see in your code:
- I think you need to uncomment Configure::write('debug',0);
- change
echo $tcpdf->Output('filename.pdf', 'D');
to
$tcpdf->Output('filename.pdf', 'D');
- use TCPDF object and vendor, not XTCPDF which doesn't work.
But again, follow my step by step to get a working skeleton you can
build upon.
Good luck!
On Dec 1, 6:34 am, Fernando Mendonça <fernand...@gmail.com> wrote:
> Hi everybody,
>
> I'm trying to generate some pdfs files with Cake PHP and TCPDF with
> Bakery Tutorial of this address:http://bakery.cakephp.org/articles/view/creating-pdf-files-with-cakep...
>
> I did everything like this tutorial and I wrote in one of my
> controller (teacher_controller.php) the follow code:
>
> function __view($id = null) {
> if (!$id) {
> $this->Session->setFlash(__('Invalid Teacher.', true));
> $this->redirect(array('action'=>'index'));
> }
>
> $this->set('teacher', $this->Teacher->read(null, $id));
>
> }
>
> function viewPdf($id = null)
> {
> if (!$id)
> {
> $this->Session->setFlash('Sorry, there was no property ID
> submitted.');
> $this->redirect(array('action'=>'index'), null, true);
> }
> //Configure::write('debug',0); // Otherwise we cannot use this
> method while developing
>
> $id = intval($id);
>
> $property = $this->__view($id); // here the data is pulled
> from the database and set for the view
>
> if (empty($property))
> {
> $this->Session->setFlash('Sorry, there is no property with
> the submitted ID.');
> $this->redirect(array('action'=>'index'), null, true);
> }
>
> $this->layout = 'pdf'; //this will use the pdf.ctp layout
> $this->render();
> }
>
> I created the view (viewPdf.ctp) too:
>
> <?php
> App::import('Vendor','xtcpdf');
> $tcpdf = new XTCPDF();
> $textfont = 'freesans'; // looks better, finer, and more condensed
> than 'dejavusans'
>
> $tcpdf->SetAuthor("KBS Homes & Properties athttp://kbs-properties.com");
> $tcpdf->SetAutoPageBreak( false );
> $tcpdf->setHeaderFont(array($textfont,'',40));
> $tcpdf->xheadercolor = array(150,0,0);
> $tcpdf->xheadertext = 'KBS Homes & Properties';
> $tcpdf->xfootertext = 'Copyright © %d KBS Homes & Properties. All
> rights reserved.';
>
> // Now you position and print your page content
> // example:
> $tcpdf->SetTextColor(0, 0, 0);
> $tcpdf->SetFont($textfont,'B',20);
> $tcpdf->Cell(0,14, "Hello World", 0,1,'L');
> // ...
> // etc.
> // see the TCPDF examples
>
> echo $tcpdf->Output('filename.pdf', 'D');
>
> ?>
>
> But when I try to acess: 127.0.0.1/cake/myapp/teacher/1 the message
> "Sorry, there is no property with the submitted ID." appears. I know
> this message has to appears when nothing is set to $property, but I
> thing I'm doing this.
>
> Anybody Can help me?
>
> Thanksuse
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment