I am using print module to generate pdf using dompdf library. I am facing issue with file name which node title have ampersand(&) sign, this character is converting into &.

For example- If file name is hello & drupal then the file name become hello & drupal - 2019-04-23

My filename filename configuration is as attached image.

enter image description here

2 Answers 2


I am not a specialist of dompdf, but having used fpdf, I think it's something you do in your print template or custom module that converts the fields in dompdf format. You may need to set a php rule like this:

$title = mb_convert_encoding($title, 'HTML-ENTITIES', 'UTF-8');

Source: https://stackoverflow.com/questions/16384517/dompdf-character-encoding-utf-8

Or another one like this:

$titlePrintFriendly = preg_replace('#&#',chr(38),$title);

and then print $titlePrintFriendly

I used the second one in the past to trick printing some special chars.
The dompdf library should be loaded in the file you add this line.

I took the char number from https://github.com/dompdf/dompdf/blob/master/lib/fonts/Symbol.afm


A hook is available for this that is: Implements hook_print_pdf_filename_alter

* Implements hook_print_pdf_filename_alter().
function MY_MODULE_print_pdf_filename_alter(&$pdf_filename, &$path) {
  $pdf_filename = htmlspecialchars_decode($pdf_filename, ENT_NOQUOTES);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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