http://bakery.cakephp.org/articles/sdevore_myopenid_com/2007/01/27/pdf-helper-using-fpdf
but it is prepared to Cake's version 1.2 and it gives me some errors.
I have to read about Helpers
What i did till know:
Helper views/helpers/pdf.php
<?php
//vendor('fpdf/fpdf');
App::import('Vendor', 'FPDF', array('file' => 'fpdf/fpdf.php'));
if (!defined('PARAGRAPH_STRING')) define('PARAGRAPH_STRING', '~~~');
class PdfHelper extends FPDF {
/**
* Allows you to change the defaults set in the FPDF constructor
*
* @param string $orientation page orientation values: P, Portrait,
L, or Landscape (default is P)
* @param string $unit values: pt (point 1/72 of an inch), mm, cm,
in. Default is mm
* @param string $format values: A3, A4, A5, Letter, Legal or a two
element array with the width and height in unit given in $unit
*/
function setup ($orientation='P',$unit='mm',$format='A4') {
$this->FPDF($orientation, $unit, $format);
}
/**
* Allows you to control how the pdf is returned to the user, most
of the time in CakePHP you probably want the string
*
* @param string $name name of the file.
* @param string $destination where to send the document values: I, D, F, S
* @return string if the $destination is S
*/
function fpdfOutput ($name = 'page.pdf', $destination = 's') {
// I: send the file inline to the browser. The plug-in is used
if available.
// The name given by name is used when one selects the
"Save as" option on the link generating the PDF.
// D: send to the browser and force a file download with the
name given by name.
// F: save to a local file with the name given by name.
// S: return the document as a string. name is ignored.
return $this->Output($name, $destination);
}
}
?>
Layout views/layouts/pdf.ctp
<?php
header("Content-type: application/pdf");
echo $content_for_layout;
?>
Controller contollers/test_controller.php
<?php
class TestsController extends AppController
{
var $name = 'Tests';
var $helpers = array('pdf'); // this will use the pdf.php class
function indexPdf()
{
$this->layout = 'pdf'; //this will use the pdf.thtml layout
$this->set('data','hello world!');
$this->render();
}
}
?>
Tests View views/tests/index_pdf.ctp
<?php
$fpdf->AddPage();
$fpdf->SetFont('Arial','B',16);
$fpdf->Cell(40,10,$data);
echo $fpdf->fpdfOutput();
?>
And connection with cake is working but i'm getting error from FPDF
FPDF error: Incorrect orientation:
2011/6/29 Sam Sherlock <sam.sherlock@gmail.com>:
> What is giving you issues currently?
>
> Back when 1.2 was beta I made a link that allowed users to get a off version
> of a page.
>
> Check that the vendor is found correctly
>
> Then made a simple static view out to off and build from there.
>
> Core debug will need to be 0 to display the pdf that can be frustrating.
>
> - S
>
> On 29 Jun 2011 19:47, "Dominik Gajewski" <dominikgajewski1@gmail.com> wrote:
>> I want to create reports that take data from database and/ or form
>>
>> 2011/6/29 Sam Sherlock <sam.sherlock@gmail.com>:
>>> the bakery does have a few articles on pdf generation within cake
>>>
>>> app import the vendor.
>>> App::import('Vendor', 'FPDF', array('file' => 'fpdf/fpdf.php'));
>>>
>>>
>>> or do you want to create a visualization of model relations in pdf
>>> format?
>>>
>>> - S
>>>
>>>
>>>
>>>
>>> On 29 June 2011 18:54, Dominik Gajewski <dominikgajewski1@gmail.com>
>>> wrote:
>>>>
>>>> Hi
>>>>
>>>> I would like to use FPDF or PDFlib with Cake, and I wonder how to do
>>>> it correctly according to cake's schema
>>>>
>>>> Has anyone had any experience in this matter??
>>>>
>>>> --
>>>> Dominik Gajewski
>>>>
>>>> --
>>>> Our newest site for the community: CakePHP Video Tutorials
>>>> http://tv.cakephp.org
>>>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>>>> others with their CakePHP related questions.
>>>>
>>>>
>>>> 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
>>>
>>> --
>>> Our newest site for the community: CakePHP Video Tutorials
>>> http://tv.cakephp.org
>>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>>> others with their CakePHP related questions.
>>>
>>>
>>> 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
>>>
>>
>>
>>
>> --
>> Pozdrawiam
>> Dominik Gajewski
>>
>> --
>> Our newest site for the community: CakePHP Video Tutorials
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>> others with their CakePHP related questions.
>>
>>
>> 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
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> 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
>
--
Pozdrawiam
Dominik Gajewski
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
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
No comments:
Post a Comment