@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.js
CHANGED
|
@@ -3236,6 +3236,26 @@ var PageAssembler = React7.forwardRef(
|
|
|
3236
3236
|
console.log(`[PageAssembler] Total extracted fields: ${allExtractedFields.length}`);
|
|
3237
3237
|
console.log(`[PageAssembler] Field names:`, allExtractedFields.map((f) => `${f.name} (page ${f.position.page})`));
|
|
3238
3238
|
const combinedDoc = await PDFDocument5.create();
|
|
3239
|
+
const copyOrderBySource = /* @__PURE__ */ new Map();
|
|
3240
|
+
for (const file of state.files) {
|
|
3241
|
+
for (const page of file.pages) {
|
|
3242
|
+
const originalFileId = page.originalFileId || file.id;
|
|
3243
|
+
const sourcePdf = fileMap.get(originalFileId)?.type === "pdf" ? loadedPdfs.get(originalFileId) : void 0;
|
|
3244
|
+
if (!sourcePdf || page.srcIndex < 0 || page.srcIndex >= sourcePdf.getPageCount()) continue;
|
|
3245
|
+
const order = copyOrderBySource.get(originalFileId) ?? [];
|
|
3246
|
+
order.push(page.srcIndex);
|
|
3247
|
+
copyOrderBySource.set(originalFileId, order);
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
const copiedPagesBySource = /* @__PURE__ */ new Map();
|
|
3251
|
+
for (const [fileId, order] of copyOrderBySource) {
|
|
3252
|
+
try {
|
|
3253
|
+
copiedPagesBySource.set(fileId, await combinedDoc.copyPages(loadedPdfs.get(fileId), order));
|
|
3254
|
+
} catch (copyError) {
|
|
3255
|
+
console.error(`Error copying pages from ${fileId}:`, copyError);
|
|
3256
|
+
throw new Error(`Failed to copy page: ${copyError instanceof Error ? copyError.message : String(copyError)}`);
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3239
3259
|
for (const file of state.files) {
|
|
3240
3260
|
if (file.pages.length === 0) continue;
|
|
3241
3261
|
for (const page of file.pages) {
|
|
@@ -3253,23 +3273,16 @@ var PageAssembler = React7.forwardRef(
|
|
|
3253
3273
|
}
|
|
3254
3274
|
const sourcePageCount = sourcePdf.getPageCount();
|
|
3255
3275
|
if (page.srcIndex >= 0 && page.srcIndex < sourcePageCount) {
|
|
3276
|
+
const copiedPage = copiedPagesBySource.get(originalFileId).shift();
|
|
3256
3277
|
try {
|
|
3257
|
-
const
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
}
|
|
3264
|
-
} catch (annotError) {
|
|
3265
|
-
console.warn("Could not remove annotations from copied page:", annotError);
|
|
3266
|
-
}
|
|
3267
|
-
combinedDoc.addPage(copiedPage);
|
|
3268
|
-
});
|
|
3269
|
-
} catch (copyError) {
|
|
3270
|
-
console.error(`Error copying page ${page.srcIndex}:`, copyError);
|
|
3271
|
-
throw new Error(`Failed to copy page: ${copyError instanceof Error ? copyError.message : String(copyError)}`);
|
|
3278
|
+
const annotsRef = copiedPage.node.get(PDFName4.of("Annots"));
|
|
3279
|
+
if (annotsRef) {
|
|
3280
|
+
copiedPage.node.delete(PDFName4.of("Annots"));
|
|
3281
|
+
}
|
|
3282
|
+
} catch (annotError) {
|
|
3283
|
+
console.warn("Could not remove annotations from copied page:", annotError);
|
|
3272
3284
|
}
|
|
3285
|
+
combinedDoc.addPage(copiedPage);
|
|
3273
3286
|
}
|
|
3274
3287
|
} else if (sourceFile.type === "image" && sourceFile.originalFile) {
|
|
3275
3288
|
try {
|