I would to change the filename of the pdf file : I use the template_webform2pdf_filename() function in my theme to include the last part of the node path in the filename, like this

 function mytheme_webform2pdf_filename($node, $submission) {
  $sid = is_object($submission) ? $submission->sid : $submission;
  $filename =end(preg_split("#/#",$node->path));
  $filename .= !empty($sid) ? '-' . $sid : '';
  $filename .=".pdf";
  return $filename;
}

All is OK with that, and the pdf has the desired filename.
The problem is when the pdf is attached in a email. If the filename is longer that 39 characters, the attached pdf is entitled "Part 1.2" and can't be read : I get an error "Adobe Reader could not open 'Part 1.2' because it is either not a supported file type of because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)".
In the source code of the email, the difference is an additional line between the content-type declaration and the name variable :

  • correct
    Content-Type: application/pdf; name="abcdefghijklmnopqrstuvwxyz-abcdefgh.pdf"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment;  
    
    filename="abcdefghijklmnopqrstuvwxyz-abcdefgh.pdf"
    
  • uncorrect
    Content-Type: application/pdf;
    
    name="abcdefghijklmnopqrstuvwxyz-abcdefghij.pdf"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment;  
    filename="abcdefghijklmnopqrstuvwxyz-abcdefghij.pdf"

Is there a solution to solve this problem ?

Comments

mr.york’s picture

Status: Active » Closed (fixed)