hubdohmen Posted September 12, 2012 Share Posted September 12, 2012 (edited) Hi! I have created a new addon and I need a hand. I want to add pdf reports, but I can not get it to work with the bundled tcpdf. This is what I have: function create_pdf(){ require(ROOTDIR."/includes/tcpdf.php"); require(ROOTDIR."/includes/tcpdf_unicode.php"); $html .= "Blah blah"; $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetAuthor('John'); $pdf->AddPage(); $pdf->writeHTML($html, true, 0); $pdf->Output('somefile.pdf', 'I'); } // end Hope you can help! Hub Edited September 12, 2012 by hubdohmen 0 Quote Link to comment Share on other sites More sharing options...
doram Posted September 12, 2012 Share Posted September 12, 2012 Hi Hub. I'm trying to also get a page to generate a pdf form. On my side, code for tcpfd and fpdf that works to generate a pdf on any other test page, generates a non functioning pdf when attempted through whmcs template files. code run from a regular php page, will generate a pdf file of 11KB, when I check the PDF properties, it has a FORMAT: PDF-1.7 when running same code from a template in whmcs, the generated pdf file is 33KB and properties shoe FORMAT: PDF-0 the file generated from standalone php page, will open in adobe pdf reader, and any other pdf viewer I have, whereas the equivalent generated in whmcs, will only open through 3rd party pdf viewer. I then tried your code, it worked ... once, and since then , all future attempts give me the same results I received with my attempts. I tried emptying templates_c, still cant get a successful generation, all pdf generated will have bad format, but they do open in ubuntus document viewer, and macs pdf viewer...but not on ANY ADOBE PDF viewer. I been pulling out my hair since yesterday with this. Let me know if you getting similiar results. 0 Quote Link to comment Share on other sites More sharing options...
doram Posted September 13, 2012 Share Posted September 13, 2012 Hey Hub. It seems to be aproblem with the output parameters, it bombs out on I and D (view inline, and Download respectively) It does however function using F (save to file) , and then providing a download link for the user. Will test a little further and confirm with you once I am certain it works consistently. 0 Quote Link to comment Share on other sites More sharing options...
doram Posted September 13, 2012 Share Posted September 13, 2012 Ok, problem and cause resolved. If you download the file generated in your code, and then open the attachemnt in a text editor, you will see a whole pile of HTML code slapped into the top of the file (this would be client area header code). This is due to html output to browser prior to the pdf->output command, which is then getting populated into the file being output to the browser inline or as a download. $pdf->Output('somefile.pdf', 'I'); //fails with header html in output file $pdf->Output('somefile.pdf', 'D'); //fails with header html in output file The solution is to store the file somewhere on server, and either email through php, or provide a download link to the client referencing the stored location of pdf, ie ('/path/to/somefile.pdf', 'F'); Glad I resolved this, been pulling my hair out for days to generate a pdf, I will be mailing pdf to client with a link to upload completed pdf to. 0 Quote Link to comment Share on other sites More sharing options...
hubdohmen Posted September 13, 2012 Author Share Posted September 13, 2012 Thanks Doram, I will test it tonight. Hub 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.