I am new to web development and remember from past that a friend of mine once had an implementation in which Server response stream of HTML was stored in a variable and then output as PDF, this was JSP some ages ago. I don’t know how to achieve this in Yii rather bit skeptical if I even remember it right. I have explored TCPDF and can produce the PDF by coding the HTML tags, however, I am looking into the option to stream the output of a URL response in a variable and then use that to generate the PDF. I did the following but it is not working. I receive error at filesize($filename):
I’m not directly answering your post question, but is the page by any chance Yii-controlled? I mean, is it a controller that generates it?
In that case, you should find easier ways. I know that pdf extension has a WriteHTML() method, which you can pass a view rendered by Yii, so maybe TCPDF does the same?
Yes, I am planning to make it Yii based. I am thinking of creating an action in controller which would be called from a button, the action would take the HTML of an other view(HTML input streaming comes here) and pass it to the TCPDF->pdf object and I will save the PDF on the server. Once the PDF is successfully generated and saved, I will open a view to user which would let him see that PDF. User can then save it to local machine or close it. This is all how I am planning to implement, please correct me if I am wrong all the way and suggest an approach which would do the same.
I am on to what you suggested, it seems promising, will get back with my results.
Need a little push on one thing. I have generated the PDF and can open it with 100% results but i am unable to present the generated PDF to user after it has been created. I am trying to open it soon after it created and tried the following in my controller action but in vain:
$html2pdf->Output($pdfFilename,EYiiPdf::OUTPUT_TO_FILE);//This is where I get the PDF successfully.
$filecontent=file_get_contents($pdfFilename);
header("Content-Type: text/plain");
header("Content-disposition: attachment; filename=$pdfFilename");
header("Pragma: no-cache");
echo $filecontent;
exit;
Oh never mind…! a small mistake and now it working. I was rendering the view along with PDF generation because of which the Open/Save Dialog box was not coming. After I commented out the view code, it worked fine. Thanks in advance.