implements page-numbers-plan
This commit is contained in:
1 parent
39da8dac4d
commit
b5279434b2
19 files changed
+1823
-339
No files matched your search
@@ -123,6 +123,27 @@ export const getPageContentText = (document: PDFDocument, pageIndex: number) =>
|
||||
.join('\n');
|
||||
};
|
||||
|
||||
/**
|
||||
* Decoded operands of all `Tj` operators. pdf-lib writes drawn text as hex
|
||||
* strings (`<426C2E2031> Tj`), so the raw content stream is not readable.
|
||||
*/
|
||||
export const getPageTextValues = (document: PDFDocument, pageIndex: number) => {
|
||||
const content = getPageContentText(document, pageIndex);
|
||||
const values: string[] = [];
|
||||
|
||||
for (const match of content.matchAll(/<([0-9a-fA-F]+)>\s*Tj/g)) {
|
||||
values.push(Buffer.from(match[1], 'hex').toString('latin1'));
|
||||
}
|
||||
for (const match of content.matchAll(/\(((?:\\.|[^()\\])*)\)\s*Tj/g)) {
|
||||
values.push(match[1]);
|
||||
}
|
||||
|
||||
return values;
|
||||
};
|
||||
|
||||
export const getPageText = (document: PDFDocument, pageIndex: number) =>
|
||||
getPageTextValues(document, pageIndex).join('\n');
|
||||
|
||||
export const createEncryptedPdf = async (pageCount: number, label: string, password: string) => {
|
||||
const document = await EncryptablePdfDocument.load(await createPdf(pageCount, label));
|
||||
document.encrypt({
|
||||
|
||||
Reference in new issue
Block a user