Yii Framework Forum: printing out a pdf file - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

printing out a pdf file Rate Topic: -----

#1 User is offline   binkabir 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 193
  • Joined: 25-July 10
  • Location:Abuja,Nigeria

Posted 13 February 2012 - 08:53 AM

Hello,
i have created a pdf file and placed it in the view folder of the controller,
now when i tried to output it to the brower i get a popup error
"file does not begin with '%PDF-'"

in the controllers action method
i have this
        $this->renderPartial('index'); 
   


in the index view file
     $pdfFile="myPDF.pdf";

$filename = 'TIME_TABLE.pdf';

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . strlen($pdfFile));
header('Accept-Ranges: bytes');



//output the document
print($pdfFile); 
   


anyone with ideas ????
0

#2 User is offline   binkabir 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 193
  • Joined: 25-July 10
  • Location:Abuja,Nigeria

Posted 14 February 2012 - 03:39 AM

Oooooooop ! On one with ideas????
0

#3 User is offline   Artificial 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 11-December 10
  • Location:Sydney, Australia

Posted 15 February 2012 - 07:32 AM

You're not even dealing directly with the file. You're quite literally just printing out 'myPDF.pdf', which of course isn't going to render properly as a pdf file. You're going to have to open the file and output its contents.

Why don't you just link to the file, or if you want to be able to view the pdf inline utilise something like Google Docs?
0

#4 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,165
  • Joined: 05-January 12
  • Location:Morocco

Posted 06 March 2012 - 07:51 AM

I had exactly the same requirement.

How I did it:

header('Content-Type: application/pdf');
readfile($file); 

0

#5 User is offline   Abigail 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 01-August 13

Posted 12 August 2013 - 03:46 AM

How about these code:
public void PdfProcessorPrint();
{
PDFInputFile = (@"C:/1.pdf");
Printer = (@"C:/HP Color LaserJet 5550 PCL 6");
};
PDF. PdfProcessorPrint(@"C:/1.pdf", @"C:/HP Color LaserJet 5550 PCL 6");
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users