Details
-
Type: Improvement
-
Status: Done/Fixed
-
Priority: Trivial
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.6.10, 4.7
-
Fix Version/s: None
-
Component/s: CiviReport
-
Documentation Required?:Developer Doc
-
Funding Source:Contributed Code
Description
There is currently no good way to alter the way PDF reports' headers appear. The specific use case is to add a custom CSS file to the header, but there could be a bunch of other uses. Basically, CRM_Utils_PDF_Utils::html2pdf() hard-codes the header] and removes anything in the header that might be added in the report settings:
https://github.com/civicrm/civicrm-core/blob/383b23e336bb25b193dd56acdeeb191bb72ebedc/CRM/Utils/PDF/Utils.php#L89
The header happens to be the default header for a report, plus some page formatting.
Meanwhile, hook_civicrm_alterContent() is never invoked on PDF or print outputs of a report, so you can't add anything that way either.
Finally, adding resources doesn't work because the page never gets rendered the usual way.
I can think of three possible alternatives:
- Have CRM_Utils_PDF_Utils::html2pdf() accept the header and footer as parameters, taking those (and adding the page style) if they're provided.
- Invoke hook_civicrm_alterContent() after the PDF content has been adjusted. The difficulty here is that the page/form object and the template name aren't passed to CRM_Utils_PDF_Utils::html2pdf(). (An alternative to this would be to have a separate hook_civicrm_alterPdfContent() with fewer parameters.)
- Add a new hook_civicrm_alterPrintHeader() that would allow you to add CSS if you like.
I was initially leaning toward the first option, though it will still leave no way to alter PDF letters. My only concern is that it makes it a little too easy for end user staff to mangle the HTML by editing the header and/or footer. Already, printed reports rely on opening tags in the header and closing them in the footer.
The last option would probably be the most straightforward. The hook could provide an array of CSS and Javascript files (to start with, just print.css) that an extension could modify. It would be invoked every time print.css gets included.
Re: funding, I can handle several hours as part of our work with the client who wants altered CSS in their PDFs, so a modest change could be contributed.
Attachments
Issue Links
- is duplicated by
-
CRM-13671 Add possibility to customize css for pdf
- Done/Fixed