@signiphi/page-assembly 0.2.0-beta.19 → 0.2.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +28 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3209,6 +3209,26 @@ var PageAssembler = forwardRef(
|
|
|
3209
3209
|
console.log(`[PageAssembler] Total extracted fields: ${allExtractedFields.length}`);
|
|
3210
3210
|
console.log(`[PageAssembler] Field names:`, allExtractedFields.map((f) => `${f.name} (page ${f.position.page})`));
|
|
3211
3211
|
const combinedDoc = await PDFDocument5.create();
|
|
3212
|
+
const copyOrderBySource = /* @__PURE__ */ new Map();
|
|
3213
|
+
for (const file of state.files) {
|
|
3214
|
+
for (const page of file.pages) {
|
|
3215
|
+
const originalFileId = page.originalFileId || file.id;
|
|
3216
|
+
const sourcePdf = fileMap.get(originalFileId)?.type === "pdf" ? loadedPdfs.get(originalFileId) : void 0;
|
|
3217
|
+
if (!sourcePdf || page.srcIndex < 0 || page.srcIndex >= sourcePdf.getPageCount()) continue;
|
|
3218
|
+
const order = copyOrderBySource.get(originalFileId) ?? [];
|
|
3219
|
+
order.push(page.srcIndex);
|
|
3220
|
+
copyOrderBySource.set(originalFileId, order);
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
const copiedPagesBySource = /* @__PURE__ */ new Map();
|
|
3224
|
+
for (const [fileId, order] of copyOrderBySource) {
|
|
3225
|
+
try {
|
|
3226
|
+
copiedPagesBySource.set(fileId, await combinedDoc.copyPages(loadedPdfs.get(fileId), order));
|
|
3227
|
+
} catch (copyError) {
|
|
3228
|
+
console.error(`Error copying pages from ${fileId}:`, copyError);
|
|
3229
|
+
throw new Error(`Failed to copy page: ${copyError instanceof Error ? copyError.message : String(copyError)}`);
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3212
3232
|
for (const file of state.files) {
|
|
3213
3233
|
if (file.pages.length === 0) continue;
|
|
3214
3234
|
for (const page of file.pages) {
|
|
@@ -3226,23 +3246,16 @@ var PageAssembler = forwardRef(
|
|
|
3226
3246
|
}
|
|
3227
3247
|
const sourcePageCount = sourcePdf.getPageCount();
|
|
3228
3248
|
if (page.srcIndex >= 0 && page.srcIndex < sourcePageCount) {
|
|
3249
|
+
const copiedPage = copiedPagesBySource.get(originalFileId).shift();
|
|
3229
3250
|
try {
|
|
3230
|
-
const
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
}
|
|
3237
|
-
} catch (annotError) {
|
|
3238
|
-
console.warn("Could not remove annotations from copied page:", annotError);
|
|
3239
|
-
}
|
|
3240
|
-
combinedDoc.addPage(copiedPage);
|
|
3241
|
-
});
|
|
3242
|
-
} catch (copyError) {
|
|
3243
|
-
console.error(`Error copying page ${page.srcIndex}:`, copyError);
|
|
3244
|
-
throw new Error(`Failed to copy page: ${copyError instanceof Error ? copyError.message : String(copyError)}`);
|
|
3251
|
+
const annotsRef = copiedPage.node.get(PDFName4.of("Annots"));
|
|
3252
|
+
if (annotsRef) {
|
|
3253
|
+
copiedPage.node.delete(PDFName4.of("Annots"));
|
|
3254
|
+
}
|
|
3255
|
+
} catch (annotError) {
|
|
3256
|
+
console.warn("Could not remove annotations from copied page:", annotError);
|
|
3245
3257
|
}
|
|
3258
|
+
combinedDoc.addPage(copiedPage);
|
|
3246
3259
|
}
|
|
3247
3260
|
} else if (sourceFile.type === "image" && sourceFile.originalFile) {
|
|
3248
3261
|
try {
|