Answers.Body: <p>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.</p>
  
  <p>In your use-case I think you can safely leave off both of those params.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-07T02:25:26.390Z
Answers.LastActivityDate: 2015-05-07T02:25:26.390Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>You could also implement the CiviCRM hooks for tokens:</p>
  
  <p><a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tokens" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tokens</a></p>
  
  <p><a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tokenValues" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tokenValues</a></p>
  
  <p>Then the user can use the standard CiviCRM "create PDF letter" feature, and click "Insert Tokens" to put in the financial data needed. </p>
  
  <p>The user could use the same tokens when emailing invoices too. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T17:07:48.027Z
Answers.LastActivityDate: 2015-05-06T17:25:57.830Z
Answers.LastEditDate: 2015-05-06T17:25:57.830Z
Answers.UserDisplayName: Sarah Poger Gladstone
Answers.Body: <p>You might want to make the invoiceName end with a .pdf</p>
  
  <p>so:</p>
  
  <p>$invoiceName = "{$participantName}-{$eventName}.pdf";</p>
  
  <p>The third parameter return the pdf if set to true, else initiates a file download via the browser</p>
  
  <p>the 4th parameter is optional and is used to send additional (or override the default) parameters to the pdf code</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T15:02:59.810Z
Answers.Text: 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?
Answers.UserDisplayName: Squishus Tyrannicus
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T15:44:06.980Z
Answers.Text: can you try sending a really simple string of html, so something like: <p>Hello, World!</p> and see if that works.
Answers.UserDisplayName: Donald Lobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-14T12:34:04.430Z
Answers.Text: Even the simplest HTML fails to generate a usable PDF.
Answers.UserDisplayName: Squishus Tyrannicus
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T14:51:01.483Z
Answers.LastActivityDate: 2015-05-06T14:51:01.483Z
Answers.UserDisplayName: Donald Lobo
Answers.Body: <p>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:</p>
  
  <p><img src="https://i.sstatic.net/Y9QKs.jpg" alt="Thank-you Letters option"></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-02T16:20:47.497Z
Answers.LastActivityDate: 2015-06-02T16:50:20.723Z
Answers.LastEditDate: 2015-06-02T16:50:20.723Z
Answers.UserDisplayName: Laryn
Body: <p>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.</p>
  
  <p>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.</p>
  
  <p>The following is similar to the code I'm using:</p>
  
  <pre><code>CRM_Utils_PDF_Utils::html2pdf($html, $invoiceName, FALSE, NULL);
  </code></pre>
  
  <p>Where $html is the generated HTML string and $invoiceName is a string containing the concatenated participant name and event name.</p>
  
  <p>I guess I'm not certain what the 3rd and 4th arguments do. Any insight would be appreciated.</p>
  
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-29T02:42:49.823Z
Comments.Text: Did you get this solved? I'm curious as I may have need to do something similar (generating a PDF "certificate" for contacts).
Comments.UserDisplayName: Laryn
Tags: <extension><pdf>
Title: How can I generate a custom PDF using CiviCRM?
ThreadText: # How can I generate a custom PDF using CiviCRM?
  
  (Asked by: username_0 on 2015-05-06)
  
  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!
  
  **Tags:** extension, pdf
  
  > **Comments:**
  > **username_1**: Did you get this solved? I'm curious as I may have need to do something similar (generating a PDF "certificate" for contacts).  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_2 on 2015-05-07. Score: 2
  
  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.
  
  
  ---
  
  ### Answer by username_3 on 2015-05-06. Score: 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.
  
  
  ---
  
  ### Answer by username_4 on 2015-05-06. Score: 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
  
  > **Comments:**
  > **username_0**: 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?  
  > **username_4**: can you try sending a really simple string of html, so something like: <p>Hello, World!</p> and see if that works.  
  > **username_0**: Even the simplest HTML fails to generate a usable PDF.  
  
  ---
  
  ### Answer by username_1 on 2015-06-02. Score: 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](https://i.sstatic.net/Y9QKs.jpg)
  
  
  ---
  
  