Skip to content

Commit

Permalink
Multi-byte character support for filename during output (#561). (#562)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
  • Loading branch information
paulholden and nicolaasuni authored Dec 6, 2022
1 parent e8a76e1 commit 80dbfa8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tcpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7616,7 +7616,7 @@ public function setAbsXY($x, $y) {
* Send the document to a given destination: string, local file or browser.
* In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
* The method first calls Close() if necessary to terminate the document.
* @param string $name The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
* @param string $name The name of the file when saved
* @param string $dest Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local server file with the name given by name.</li><li>S: return the document as a string (name is ignored).</li><li>FI: equivalent to F + I option</li><li>FD: equivalent to F + D option</li><li>E: return the document as base64 mime multi-part email attachment (RFC 2045)</li></ul>
* @return string
* @public
Expand All @@ -7634,10 +7634,7 @@ public function Output($name='doc.pdf', $dest='I') {
$dest = $dest ? 'D' : 'F';
}
$dest = strtoupper($dest);
if ($dest[0] != 'F' && $name !== null) {
$name = preg_replace('/[\s]+/', '_', $name);
$name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
}

if ($this->sign) {
// *** apply digital signature to the document ***
// get the document content
Expand Down Expand Up @@ -7708,7 +7705,8 @@ public function Output($name='doc.pdf', $dest='I') {
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Disposition: inline; filename="'.basename($name).'"');
header('Content-Disposition: inline; filename="' . rawurlencode(basename($name)) . '"; ' .
'filename*=UTF-8\'\'' . rawurlencode(basename($name)));
TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
} else {
echo $this->getBuffer();
Expand Down Expand Up @@ -7739,7 +7737,8 @@ public function Output($name='doc.pdf', $dest='I') {
header('Content-Type: application/pdf');
}
// use the Content-Disposition header to supply a recommended filename
header('Content-Disposition: attachment; filename="'.basename($name).'"');
header('Content-Disposition: attachment; filename="' . rawurlencode(basename($name)) . '"; ' .
'filename*=UTF-8\'\'' . rawurlencode(basename($name)));
header('Content-Transfer-Encoding: binary');
TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
break;
Expand Down

0 comments on commit 80dbfa8

Please sign in to comment.