1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 09:38:06 +02:00

PDF names need to be escaped when saving

This commit is contained in:
Calixte Denizet 2020-09-09 18:39:14 +02:00
parent f9d56320f5
commit dc4eb71ff1
4 changed files with 56 additions and 2 deletions

View file

@ -185,7 +185,33 @@ function parseXFAPath(path) {
});
}
function escapePDFName(str) {
const buffer = [];
let start = 0;
for (let i = 0, ii = str.length; i < ii; i++) {
const char = str.charCodeAt(i);
if (char < 0x21 || char > 0x7e || char === 0x23) {
if (start < i) {
buffer.push(str.substring(start, i));
}
buffer.push(`#${char.toString(16)}`);
start = i + 1;
}
}
if (buffer.length === 0) {
return str;
}
if (start < str.length) {
buffer.push(str.substring(start, str.length));
}
return buffer.join("");
}
export {
escapePDFName,
getLookupTableFactory,
MissingDataException,
XRefEntryException,