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

Crash when appending PDF more than 507 times #61

Closed
shaehn opened this issue Sep 26, 2018 · 3 comments
Closed

Crash when appending PDF more than 507 times #61

shaehn opened this issue Sep 26, 2018 · 3 comments
Labels

Comments

@shaehn
Copy link
Collaborator

shaehn commented Sep 26, 2018

Since I had to programatically create a template file before I could edit it, I put the creation inside a loop.

const PdfDocument  = require('hummus-recipe');

pdfDoc = new PdfDocument('new', 'junk2.pdf');
const underlay = 'PDF-document1.pdf';
for (let page = 1; page < 10001; page++) {
    console.log(page);
    pdfDoc.appendPage(underlay);
}
pdfDoc.endPDF();

when the loop was getting ready to append at the 508th iteration, the following appeared.

C:\Users\shaehn\json2pdf\node_modules\hummus-recipe\lib\appendPage.js:42
        this.writer.appendPDFPagesFromPDF(pdfSrc);
                    ^

TypeError: unable to append page, make sure it's fine
    at Recipe.appendPage (C:\Users\me\project\node_modules\hummus-recipe\lib\appendPage.js:42:21)
    at Object.<anonymous> (C:\Users\me\project\edit.js:7:16)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

Is there some kind of limit involved when appending an existing document to a new document?

@shaehn
Copy link
Collaborator Author

shaehn commented Sep 26, 2018

Not sure if this will give a hint as to what is going on, but if I do the .appendPage 500 times before I invoke the crash, the document created appears to be unhealthy in some way, because when I try to print out the structure of the newly created document, I get the following problem.

C:\Users\me\project\node_modules\hummus-recipe\lib\info.js:176
            const type = inObject.getType();
                                  ^

TypeError: Cannot read property 'getType' of undefined
    at iterateObjectTypes (C:\Users\me\project\node_modules\hummus-recipe\lib\info.js:176:35)
    at write (C:\Users\me\project\node_modules\hummus-recipe\lib\info.js:227:9)
    at structures.forEach (C:\Users\me\project\node_modules\hummus-recipe\lib\info.js:231:9)
    at Array.forEach (<anonymous>)
    at Recipe.structure (C:\Users\me\project\node_modules\hummus-recipe\lib\info.js:230:16)
    at Object.<anonymous> (C:\Users\me\project\edit.js:16:8)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)

So it would appear that the appendPage is not creating healthy PDF file.

@chunyenHuang
Copy link
Owner

I will check soon. Thanks for finding the issue.

shaehn added a commit to shaehn/hummusRecipe that referenced this issue Dec 17, 2019
The problem was that putting appendPage opens up a reader file resource that does not get released after function is complete, so when it is called within a large loop, the program runs out of file descriptors.
chunyenHuang added a commit that referenced this issue Jan 7, 2020
@shaehn
Copy link
Collaborator Author

shaehn commented Jan 8, 2020

fixed in release 1.9.1

@shaehn shaehn closed this as completed Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants