Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to append page, make sure it's fine #387

Open
coolhand79 opened this issue Jun 13, 2024 · 6 comments
Open

unable to append page, make sure it's fine #387

coolhand79 opened this issue Jun 13, 2024 · 6 comments

Comments

@coolhand79
Copy link

coolhand79 commented Jun 13, 2024

We're still seeing this issue. Attached is a sample PDF that fails when attempting to merge.
blank-bad.pdf

Our merge code looks like this:

export async function merge(
    inputPath: string,
    coversheetPath: string,
    outputPath: string
): Promise<void> {

    const outStream = new memoryStreams.WritableStream();

    const coversheetPDFBuffer = fs.readFileSync(coversheetPath);
    const reportPDFBuffer = fs.readFileSync(inputPath);

    try {
        const firstPDFStream = new muhammara.PDFRStreamForBuffer(coversheetPDFBuffer);
        const secondPDFStream = new muhammara.PDFRStreamForBuffer(reportPDFBuffer);

        const pdfWriter = muhammara.createWriterToModify(
            firstPDFStream,
            new muhammara.PDFStreamForResponse(outStream)
        );
        pdfWriter.appendPDFPagesFromPDF(secondPDFStream);
        pdfWriter.end();
        const newBuffer = outStream.toBuffer();
        outStream.end();

        fs.writeFileSync(outputPath, newBuffer);
    } catch (e: any) {
        outStream.end();
        throw new Error('Error during PDF combination: ' + e.message);
    }
}

When attempting to merge with this file
blank_coversheet.pdf
the error returned will be unable to append page, make sure it's fine

Originally posted by @coolhand79 in #309 (comment)

@coolhand79
Copy link
Author

@julianhille We're running into this consistently. Have you had any time to take a look?

@julianhille
Copy link
Owner

actually not, but i try to update the pdf writer lib and hope there are some improvements over there. currently running into electron and musl build issies.

@julianhille
Copy link
Owner

Please try current dev branch. PDF writer lib has seen updates

@julianhille
Copy link
Owner

shrinked test cases by removing all the streaming.
PDF Writer update did not fix this.

@julianhille
Copy link
Owner

tested it here: https://www.pdfforge.org/online/en/validate-pdfa
test says corrupted. coversheet is fine.
not sure i could do anything about this

@Bhoomi2105
Copy link

The same issue persists: running appendPDFPagesFromPDF causes an exception in Hummus, crashing the Node.js application, even with the latest version of "muhammara": "5.2.0".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants