hummusRecipe icon indicating copy to clipboard operation
hummusRecipe copied to clipboard

Could not add new page to existing pdf

Open l1nknyto opened this issue 6 years ago • 1 comments

Hi,

I want to add a new page to the existing pdf, but an error message appears "this.page.startContext is not a function".

Here's my code:

pdfDoc = new HummusRecipe(pdfFile, outputFile);
pdfDoc.createPage('A4')
pdfDoc.image(image, 'center', 'center')

I am also try to add simple text, but same error still exists.

Here's the error

  "err": {
    "message": "this.page.startContext is not a function",
    "name": "TypeError",
    "stack": "TypeError: this.page.startContext is not a function\n    at Recipe.resumeContext (node_modules/hummus-recipe/lib/page.js:189:38)\n    at write (node_modules/hummus-recipe/lib/vector.helper.js:102:14)\n    at Recipe._createExtGStates (node_modules/hummus-recipe/lib/vector.helper.js:106:17)\n    at Recipe._getPathOptions (node_modules/hummus-recipe/lib/vector.helper.js:35:29)\n    at Recipe.image (node_modules/hummus-recipe/lib/image.js:31:23)\n ..."
  }

How can i create new page to existing pdf?

Thanks

l1nknyto avatar Nov 13 '18 05:11 l1nknyto

A working workaround for me right now is create a pdf (that contain text/image/others) then append it to targeted pdf.

const newRecipe = new HummusRecipe('new', otherPdfFile);
newRecipe
  .createPage('A4')
  .image(image, 'center', 'center')
  .endPage()
  .endPDF(function() {
    const recipe = new HummusRecipe(pdfFile, outputFile);
    pdfDoc.appendPage(otherPdfFile)
    // clean up otherPdfFile, etc
  });

l1nknyto avatar Nov 14 '18 04:11 l1nknyto