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

EditPage on loop #331

Open
xLEpEX opened this issue Sep 29, 2023 · 0 comments
Open

EditPage on loop #331

xLEpEX opened this issue Sep 29, 2023 · 0 comments

Comments

@xLEpEX
Copy link

xLEpEX commented Sep 29, 2023

Hello, i Would like to know if i'm using the Recip object correctly. I want to loop over every page of my pdf document to add a text, for exmaple the page number to the document, but when im using the loop at the following example. The saved out put buffer is still the same. Im also using the createReader since i'm not able to get the page count over the recip.

const writeTest = (pdfBuffer: Buffer) => {
        this.logger.log("write file")
        fs.writeFileSync('./pdfs/BaseWithTestText.pdf', pdfBuffer);
    }

const addPageNumber = (pdfBuffer: Buffer, skipFirstPage?: boolean) => {
        //create readStream from Buffer
        const readBuffer = new PDFRStreamForBuffer(pdfBuffer);

        //create readStream to get Page Count
        const pdfReader = createReader(readBuffer)

        //create recipe
        const recipe = new Recipe(pdfBuffer);

        //loop over pages at index 1
        for(let i = 1; i == pdfReader.getPagesCount(); i++) {
            recipe.editPage(i).text("Test funktioniert das", 42, 42).endPage();
        }
        //save updated pdf to file system
        recipe.endPDF((cb) => this.writeTest(cb));
    }

const main = () => {
        const buffer = fs.readFileSync('./pdfs/Base.pdf');
        addPageNumber(buffer);
}

main();
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

1 participant