Jump to content

Help with pdf


hubdohmen

Recommended Posts

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 by hubdohmen
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated