3

I'm writing a small extension to display contributions in a format that is similar to our organization's invoices. I'd like to be able to export them as a PDF.

I found CRM_Utils_PDF_Utils::html2pdf(), and I've been trying to use this to generate PDFs. However, when I download the PDF, my PDF reader tells me that the file is either not a PDF, or is corrupted.

The following is similar to the code I'm using:

CRM_Utils_PDF_Utils::html2pdf($html, $invoiceName, FALSE, NULL);

Where $html is the generated HTML string and $invoiceName is a string containing the concatenated participant name and event name.

I guess I'm not certain what the 3rd and 4th arguments do. Any insight would be appreciated.

Thanks!

  • Did you get this solved? I'm curious as I may have need to do something similar (generating a PDF "certificate" for contacts). – Laryn - CEDC.org May 29 '15 at 2:42
1

You might want to make the invoiceName end with a .pdf

so:

$invoiceName = "{$participantName}-{$eventName}.pdf";

The third parameter return the pdf if set to true, else initiates a file download via the browser

the 4th parameter is optional and is used to send additional (or override the default) parameters to the pdf code

  • My PDF name indeed ends in .pdf. My apologies for not specifying that bit.Is there any reason the above code snippet above shouldn't work, assuming $html is valid html and $invoiceName ends in .pdf? – Squishus Tyrannicus May 6 '15 at 15:02
  • can you try sending a really simple string of html, so something like: <p>Hello, World!</p> and see if that works. – Donald Lobo May 6 '15 at 15:44
  • Even the simplest HTML fails to generate a usable PDF. – Squishus Tyrannicus May 14 '15 at 12:34
1

You could also implement the CiviCRM hooks for tokens:

http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tokens

http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tokenValues

Then the user can use the standard CiviCRM "create PDF letter" feature, and click "Insert Tokens" to put in the financial data needed.

The user could use the same tokens when emailing invoices too.

1

The 3rd argument causes the output to be returned as a string rather than sending a file to the client if true (it defaults to false). The 4th param allows you to override the default pdf format.

In your use-case I think you can safely leave off both of those params.

1

If you create a custom template that is similar to your organization's invoices, you might be able to simply use code from the "Thank-you Letters for Contributions" functionality that you get in a Contributions search result to generate the PDFs:

Thank-you Letters option

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.