3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 use Civi\Report\OutputHandlerInterface
;
13 use Civi\Report\OutputHandlerBase
;
16 * PDF Report Output Handler
18 class CRM_Report_OutputHandler_Pdf
extends OutputHandlerBase
implements OutputHandlerInterface
{
21 * Are we a suitable output handler based on the given form?
23 * The class member $form isn't set yet at this point since we don't
24 * even know if we're in play yet, so the form is a parameter.
26 * @param CRM_Report_Form $form
30 public function isOutputHandlerFor(CRM_Report_Form
$form):bool {
31 return ($form->getOutputMode() === 'pdf');
35 * Return the download filename. This should be the "clean" name, not
36 * a munged temporary filename.
40 public function getFileName():string {
41 return 'CiviReport.pdf';
45 * Return the html body of the email.
49 public function getMailBody():string {
50 // @todo It would be nice if this was more end-user configurable, but
51 // keeping it the same as it was before for now.
52 $url = CRM_Utils_System
::url('civicrm/report/instance/' . $this->getForm()->getID(), 'reset=1', TRUE);
53 return $this->getForm()->getReportHeader() . '<p>' . ts('Report URL') .
54 ": {$url}</p>" . '<p>' .
55 ts('The report is attached as a PDF file.') . '</p>' .
56 $this->getForm()->getReportFooter();
60 * Return the report contents as a string, in this case the pdf file.
64 public function getOutputString():string {
65 return CRM_Utils_PDF_Utils
::html2pdf(
66 $this->getForm()->compileContent(),
69 ['orientation' => 'landscape']
74 * Set headers as appropriate and send the output to the browser.
76 public function download() {
77 // Nb. Once upon a time we used a package called Open Flash Charts to
78 // draw charts, and we had a feature whereby a browser could send the
79 // server a PNG version of the chart, which could then be included in a
80 // PDF by including <img> tags in the HTML for the conversion below.
82 // This feature stopped working when browsers stopped supporting Flash,
83 // and although we have a different client-side charting library in
84 // place, we decided not to reimplement the (rather convoluted)
85 // browser-sending-rendered-chart-to-server process.
87 // If this feature is required in future we should find a better way to
88 // render charts on the server side, e.g. server-created SVG.
90 CRM_Utils_PDF_Utils
::html2pdf(
91 $this->getForm()->compileContent(),
94 ['orientation' => 'landscape']
99 * Mime type of the attachment.
103 public function getMimeType():string {
104 return 'application/pdf';