Fix #37322 set IPP document-format from file extension in PrintIPP (#38706)

PrintIPP just calls $ipp->setData($fileprint) and never tells CUPS what
the file actually is, so the job arrives as application/octet-stream
and CUPS treats ODT/PDF/PS as raw bytes - the ASCII garbage symptom
the reporter sees.

Map the file extension to a MIME and call $ipp->setMimeMediaType()
when the extension is recognised. Unknown extensions fall through to
the existing default, so the change is non-breaking.

Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
This commit is contained in:
w3houde 2026-06-12 00:05:03 +02:00 committed by GitHub
parent 163b18eac7
commit f282afcd62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -169,6 +169,23 @@ class printing_printipp extends PrintingDriver
}
$fileprint .= '/'.$file;
$ipp->setData($fileprint);
// Tell CUPS what we are sending so it picks the right filter chain (otherwise ODT/PDF arrive as raw and print as ASCII garbage).
$extension = strtolower(pathinfo($fileprint, PATHINFO_EXTENSION));
$mimebyext = array(
'pdf' => 'application/pdf',
'odt' => 'application/vnd.oasis.opendocument.text',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'ps' => 'application/postscript',
'eps' => 'application/postscript',
'txt' => 'text/plain',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
);
if (isset($mimebyext[$extension])) {
$ipp->setMimeMediaType($mimebyext[$extension]);
}
try {
$ipp->printJob();
} catch (Exception $e) {