Fix split export

This commit is contained in:
Reece Browne 2025-08-25 19:05:45 +01:00
parent ec398fc9e2
commit e63572197d
2 changed files with 17 additions and 5 deletions

View File

@ -441,11 +441,16 @@ const PageEditor = ({
const filenames: string[] = [];
const sourceFiles = getSourceFiles();
const exportFilename = getExportFilename();
for (const doc of processedDocuments) {
const baseExportFilename = getExportFilename();
const baseName = baseExportFilename.replace(/\.pdf$/i, '');
for (let i = 0; i < processedDocuments.length; i++) {
const doc = processedDocuments[i];
const partFilename = `${baseName}_part_${i + 1}.pdf`;
const result = sourceFiles
? await pdfExportService.exportPDFMultiFile(doc, sourceFiles, [], { filename: exportFilename })
: await pdfExportService.exportPDF(doc, [], { filename: exportFilename });
? await pdfExportService.exportPDFMultiFile(doc, sourceFiles, [], { filename: partFilename })
: await pdfExportService.exportPDF(doc, [], { filename: partFilename });
blobs.push(result.blob);
filenames.push(result.filename);
}
@ -459,7 +464,7 @@ const PageEditor = ({
});
const zipBlob = await zip.generateAsync({ type: 'blob' });
const zipFilename = exportFilename.replace(/\.pdf$/i, '.zip');
const zipFilename = baseExportFilename.replace(/\.pdf$/i, '.zip');
pdfExportService.downloadFile(zipBlob, zipFilename);
} else {

View File

@ -61,6 +61,7 @@ export class DocumentManipulationService {
// Find split points - pages with splitAfter create split points AFTER them
document.pages.forEach((page, index) => {
if (page.splitAfter) {
console.log(`Found split marker at page ${page.pageNumber} (index ${index}), adding split point at ${index + 1}`);
splitPoints.push(index + 1);
}
});
@ -70,12 +71,18 @@ export class DocumentManipulationService {
splitPoints.push(document.pages.length);
}
console.log('Final split points:', splitPoints);
console.log('Total pages to split:', document.pages.length);
let startIndex = 0;
let partNumber = 1;
for (const endIndex of splitPoints) {
const segmentPages = document.pages.slice(startIndex, endIndex);
console.log(`Creating split document ${partNumber}: pages ${startIndex}-${endIndex-1} (${segmentPages.length} pages)`);
console.log(`Split document ${partNumber} page numbers:`, segmentPages.map(p => p.pageNumber));
if (segmentPages.length > 0) {
documents.push({
...document,