* Decode PDF string escapes: \n, \r, \t, \\, \(, \), octal
(s)
| 126 | * Decode PDF string escapes: \n, \r, \t, \\, \(, \), octal |
| 127 | */ |
| 128 | function decodePdfString(s) { |
| 129 | return s.replace(/\\([nrtbf()\\]|\d{1,3})/g, (_, c) => { |
| 130 | if (c === 'n') return '\n'; |
| 131 | if (c === 'r') return '\r'; |
| 132 | if (c === 't') return '\t'; |
| 133 | if (c === 'b') return '\b'; |
| 134 | if (c === 'f') return '\f'; |
| 135 | if (c === '(' || c === ')' || c === '\\') return c; |
| 136 | return String.fromCharCode(parseInt(c, 8)); |
| 137 | }); |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Try to extract text from base64-encoded PDF. |