Quantcast

Cakephp + TCPDF

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Cakephp + TCPDF

gloop
Hello,

i would like to create a pdf. Now i found this:

http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf

So i try this example:

Step: 1, 2, 3 the same as the example

Step 4:

  function viewPdf() {
        $this->layout = 'pdf'; //this will use the pdf.ctp layout
        $this->render();
    }

Step 5:

<?php
App
::import('Vendor','xtcpdf'); 
$tcpdf = new XTCPDF();
$textfont 'freesans'// looks better, finer, and more condensed than 'dejavusans'
$tcpdf->Cell(0,14"Hello World"0,1,'L');
echo $tcpdf->Output('filename.pdf''D');
?>


When i open function in a browser i get a download popup and i have to choose how i would open the document. The standard software is "firefox".

I try

echo 
$tcpdf->Output('filename.pdf''D');

and i see many text (like i open the pdf with firefox. I check the http header and see the document is opend with Content-Type: text/html; charset=UTF-8


I try:

In
the controller $this->header(
'Content-type: application/pdf'); and header('Content-type: application/pdf');

But i get always the wrong content-type.

How i can change the content type?

Thanks for help.
gloop

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cakephp + TCPDF

Syed Muhammad Amin
try to use dompdf

On Thu, Jul 26, 2012 at 6:04 AM, gloop <[hidden email]> wrote:
Hello,

i would like to create a pdf. Now i found this:

http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf

So i try this example:

Step: 1, 2, 3 the same as the example

Step 4:

  function viewPdf() {
        $this->layout = 'pdf'; //this will use the pdf.ctp layout
        $this->render();
    }

Step 5:

<?php
App
::import('Vendor','xtcpdf'); 
$tcpdf = new XTCPDF();
$textfont 'freesans'// looks better, finer, and more condensed than 'dejavusans'
$tcpdf->Cell(0,14"Hello World"0,1,'L');
echo $tcpdf->Output('filename.pdf''D');
?>


When i open function in a browser i get a download popup and i have to choose how i would open the document. The standard software is "firefox".

I try

echo 
$tcpdf->Output('filename.pdf''D');

and i see many text (like i open the pdf with firefox. I check the http header and see the document is opend with Content-Type: text/html; charset=UTF-8


I try:

In
the controller $this->header(
'Content-type: application/pdf'); and header('Content-type: application/pdf');

But i get always the wrong content-type.

How i can change the content type?

Thanks for help.
gloop

--
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
[hidden email] 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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cakephp + TCPDF

gloop
Its not the pdf application. The question is why cake output a text/html header.

On Thursday, July 26, 2012 7:07:54 AM UTC+2, gua syed wrote:
try to use dompdf

On Thu, Jul 26, 2012 at 6:04 AM, gloop <[hidden email]> wrote:
Hello,

i would like to create a pdf. Now i found this:

http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf

So i try this example:

Step: 1, 2, 3 the same as the example

Step 4:

  function viewPdf() {
        $this->layout = 'pdf'; //this will use the pdf.ctp layout
        $this->render();
    }

Step 5:

<?php
App
::import('Vendor','xtcpdf')
$tcpdf = new XTCPDF();
$textfont 'freesans'// looks better, finer, and more condensed than 'dejavusans'
$tcpdf->Cell(0,14"Hello World"0,1,'L');
echo $tcpdf->Output('filename.pdf''D');
?>


When i open function in a browser i get a download popup and i have to choose how i would open the document. The standard software is "firefox".

I try

echo 
$tcpdf->Output('filename.pdf''D');

and i see many text (like i open the pdf with firefox. I check the http header and see the document is opend with Content-Type: text/html; charset=UTF-8


I try:

In
the controller $this->header(
'Content-type: application/pdf'); and header('Content-type: application/pdf');

But i get always the wrong content-type.

How i can change the content type?

Thanks for help.
gloop

--
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
[hidden email] 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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cakephp + TCPDF

Carlos Lavin-2
Maybe adding the header data in the pdf layout's ctp?

2012/7/26 gloop <[hidden email]>:

> Its not the pdf application. The question is why cake output a text/html
> header.
>
>
> On Thursday, July 26, 2012 7:07:54 AM UTC+2, gua syed wrote:
>>
>> try to use dompdf
>>
>> On Thu, Jul 26, 2012 at 6:04 AM, gloop <[hidden email]> wrote:
>>>
>>> Hello,
>>>
>>> i would like to create a pdf. Now i found this:
>>>
>>>
>>> http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf
>>>
>>> So i try this example:
>>>
>>> Step: 1, 2, 3 the same as the example
>>>
>>> Step 4:
>>>
>>>   function viewPdf() {
>>>         $this->layout = 'pdf'; //this will use the pdf.ctp layout
>>>         $this->render();
>>>     }
>>>
>>> Step 5:
>>>
>>> <?php
>>> App::import('Vendor','xtcpdf');
>>> $tcpdf = new XTCPDF();
>>> $textfont = 'freesans'; // looks better, finer, and more condensed than
>>> 'dejavusans'
>>> $tcpdf->Cell(0,14, "Hello World", 0,1,'L');
>>> echo $tcpdf->Output('filename.pdf', 'D');
>>> ?>
>>>
>>> When i open function in a browser i get a download popup and i have to
>>> choose how i would open the document. The standard software is "firefox".
>>>
>>> I try
>>>
>>> echo $tcpdf->Output('filename.pdf', 'D');
>>>
>>> and i see many text (like i open the pdf with firefox. I check the http
>>> header and see the document is opend with Content-Type: text/html;
>>> charset=UTF-8
>>>
>>>
>>> I try:
>>>
>>> In the controller $this->header('Content-type: application/pdf'); and
>>> header('Content-type: application/pdf');
>>>
>>> But i get always the wrong content-type.
>>>
>>> How i can change the content type?
>>>
>>> Thanks for help.
>>> gloop
>>>
>>> --
>>> 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
>>> [hidden email] 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
> [hidden email] For more options, visit this group at
> http://groups.google.com/group/cake-php



--
-Carlos

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cakephp + TCPDF

gloop
I try header(); in the view, controller and try $this->header() in the controller.

On Thursday, July 26, 2012 9:42:36 PM UTC+2, lavin wrote:
Maybe adding the header data in the pdf layout's ctp?

2012/7/26 gloop <[hidden email]>:

> Its not the pdf application. The question is why cake output a text/html
> header.
>
>
> On Thursday, July 26, 2012 7:07:54 AM UTC+2, gua syed wrote:
>>
>> try to use dompdf
>>
>> On Thu, Jul 26, 2012 at 6:04 AM, gloop <[hidden email]> wrote:
>>>
>>> Hello,
>>>
>>> i would like to create a pdf. Now i found this:
>>>
>>>
>>> http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf
>>>
>>> So i try this example:
>>>
>>> Step: 1, 2, 3 the same as the example
>>>
>>> Step 4:
>>>
>>>   function viewPdf() {
>>>         $this->layout = 'pdf'; //this will use the pdf.ctp layout
>>>         $this->render();
>>>     }
>>>
>>> Step 5:
>>>
>>> <?php
>>> App::import('Vendor','xtcpdf');
>>> $tcpdf = new XTCPDF();
>>> $textfont = 'freesans'; // looks better, finer, and more condensed than
>>> 'dejavusans'
>>> $tcpdf->Cell(0,14, "Hello World", 0,1,'L');
>>> echo $tcpdf->Output('filename.pdf', 'D');
>>> ?>
>>>
>>> When i open function in a browser i get a download popup and i have to
>>> choose how i would open the document. The standard software is "firefox".
>>>
>>> I try
>>>
>>> echo $tcpdf->Output('filename.pdf', 'D');
>>>
>>> and i see many text (like i open the pdf with firefox. I check the http
>>> header and see the document is opend with Content-Type: text/html;
>>> charset=UTF-8
>>>
>>>
>>> I try:
>>>
>>> In the controller $this->header('Content-type: application/pdf'); and
>>> header('Content-type: application/pdf');
>>>
>>> But i get always the wrong content-type.
>>>
>>> How i can change the content type?
>>>
>>> Thanks for help.
>>> gloop
>>>
>>> --
>>> 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
>>> [hidden email] 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
> [hidden email] For more options, visit this group at
> http://groups.google.com/group/cake-php



--
-Carlos

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Cakephp + TCPDF

Dakota
In reply to this post by gloop
Tcpdf has plenty of known issues. Rather use wkhtmltopdf. Also, use the CakePDF plugin, it handles all PDF creation stuff for you, including ensuring correct headers. https://github.com/ceeram/CakePdf

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cakephp + TCPDF

Daniel Baird
I'm not familiar with PDF generation, but surprising HTML headers are sometimes an "early output" problem.

So check for stray spaces and newlines in your php files.  Depending on config, if your app emits any output, even whitespace, PHP sends the headers as it knows them at the time -- if your whitespace appears early, that might be some default html headers.

d
--
Daniel Baird
I've tried going to the XHTML <bar /> a few times, but it's always closed.

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cakephp + TCPDF

Elisio Leonardo
In reply to this post by gloop
You should really try to use Cakepdf Plugin.

https://github.com/ceeram/CakePdf

On Thursday, July 26, 2012 12:04:32 AM UTC+2, gloop wrote:
Hello,

i would like to create a pdf. Now i found this:

http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf

So i try this example:

Step: 1, 2, 3 the same as the example

Step 4:

  function viewPdf() {
        $this->layout = 'pdf'; //this will use the pdf.ctp layout
        $this->render();
    }

Step 5:

<?php
App
::import('Vendor','xtcpdf')
$tcpdf = new XTCPDF();
$textfont 'freesans'// looks better, finer, and more condensed than 'dejavusans'
$tcpdf->Cell(0,14"Hello World"0,1,'L');
echo $tcpdf->Output('filename.pdf''D');
?>


When i open function in a browser i get a download popup and i have to choose how i would open the document. The standard software is "firefox".

I try

echo 
$tcpdf->Output('filename.pdf''D');

and i see many text (like i open the pdf with firefox. I check the http header and see the document is opend with Content-Type: text/html; charset=UTF-8


I try:

In
the controller $this->header(
'Content-type: application/pdf'); and header('Content-type: application/pdf');

But i get always the wrong content-type.

How i can change the content type?

Thanks for help.
gloop

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cakephp + TCPDF

schaenk
In reply to this post by gloop
Got the same problem. But the solution is easy. Delete the header("Content-Type: application/pdf"); line in your layout file.

Just put this line into your controller action instead:
$this->RequestHandler->respondAs("pdf");

Works fine with CakePHP 2.x

Cheers

On Thursday, July 26, 2012 12:04:32 AM UTC+2, gloop wrote:
Hello,

i would like to create a pdf. Now i found this:

http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf

So i try this example:

Step: 1, 2, 3 the same as the example

Step 4:

  function viewPdf() {
        $this->layout = 'pdf'; //this will use the pdf.ctp layout
        $this->render();
    }

Step 5:

<?php
App
::import('Vendor','xtcpdf')
$tcpdf = new XTCPDF();
$textfont 'freesans'// looks better, finer, and more condensed than 'dejavusans'
$tcpdf->Cell(0,14"Hello World"0,1,'L');
echo $tcpdf->Output('filename.pdf''D');
?>


When i open function in a browser i get a download popup and i have to choose how i would open the document. The standard software is "firefox".

I try

echo 
$tcpdf->Output('filename.pdf''D');

and i see many text (like i open the pdf with firefox. I check the http header and see the document is opend with Content-Type: text/html; charset=UTF-8


I try:

In
the controller $this->header(
'Content-type: application/pdf'); and header('Content-type: application/pdf');

But i get always the wrong content-type.

How i can change the content type?

Thanks for help.
gloop

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cakephp + TCPDF

niroz
This post was updated on .
In reply to this post by gloop
I have this running (CakePhp 2.2.1)

In controller add:

    $this->response->header(array('Content-type: application/pdf'));
    $this->response->type('pdf');



 
 function view_pdf() {

    $this->response->header(array('Content-type: application/pdf'));
    $this->response->type('pdf');

    $provincias = $this->Distribuidore->Provincia->find('list');
    $this->set(compact('provincias'));

    Configure::write('debug',0); // Otherwise we cannot use this method while developing

    $this->layout = 'pdf'; //this will use the pdf.ctp layout
    $this->render();
  } 
Loading...