Print/Merge document filename does not include .pdf when using wkhtmltopdf
Overview
Using wkhtmltopd for pdf generation Print/Merge Document for selected contact The downloaded pdf file has no extension (i.e. its just CiviLetter not CiviLetter.pdf)
Reproduction steps
- Click on Contact -> Print/Merge Document
- Select Document Typ: Portable Document Format (.pdf)
- Select Download Document
Document downloaded is a valid pdf, but the file has no extension
Current behaviour
As above.
Expected behaviour
Filename includes ".pdf"
Receipts, Mailing labels etc do not have the same issue.
Environment information
- __CiviCRM: 5.46.2
- __wkhtmltox: 0.12.6-1.buster amd64
Comments
Likely problem and fix
CRM_Contact_Form_Task PDFTrait.php calls https://lab.civicrm.org/dev/core/-/blob/5.48/CRM/Contact/Form/Task/PDFTrait.php#L266
if ($type === 'pdf') {
CRM_Utils_PDF_Utils::html2pdf($html, $fileName, FALSE, $formValues);
}
At this point $fileName does not have .pdf file type
The extension is stripped in CRM_Utils_PDF_Utils _html2pdf_dompdf
// CRM-19183 remove .pdf extension from filename
$fileName = basename($fileName, ".pdf");
So a fix in PDFTrait.pdf, without impacting dompdf operation: https://lab.civicrm.org/dev/core/-/blob/5.48/CRM/Contact/Form/Task/PDFTrait.php#L266
if ($type === 'pdf') {
CRM_Utils_PDF_Utils::html2pdf($html, $fileName . '.' . $type, FALSE, $formValues);
}
The above has been tested with dompdf and wkhtmltopdf