galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.15k stars 170 forks source link

Deploying to elastic beanstalk instance breaks pdf read functionality #305

Open ajhelsby opened 6 years ago

ajhelsby commented 6 years ago

I'm trying to deploy my express node application that contains hummus and hummus-recipe to an elastic beanstalk instance but it seems to be stopping the read functionality. Running the application locally works absolutely fine and I have no issues whatsoever. When I try an run my PDF editing function I get

Error: TypeError: Unable to start parsing PDF file
    at Recipe.read (/var/app/current/node_modules/hummus-recipe/lib/Recipe.js:165:19)
    at Recipe._createWriter (/var/app/current/node_modules/hummus-recipe/lib/Recipe.js:61:18)
    at new Recipe (/var/app/current/node_modules/hummus-recipe/lib/Recipe.js:49:14)
    at /var/app/current/functions/pdf-functions.js:10:20
    at new Promise (<anonymous>)
    at Object.annotateDoc (/var/app/current/functions/pdf-functions.js:8:10)
    at /var/app/current/index.js:112:18
    at Layer.handle [as handle_request] (/var/app/current/node_modules/express/lib/router/layer.js:95:5)
    at next (/var/app/current/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/var/app/current/node_modules/express/lib/router/route.js:112:3)

I have tried a few possible fixes including:

Verifying that the pdf is indeed in the location I am trying to read from Using a preprocessed version of hummus-recipe from another EC2 box with the same setup as my elastic beanstalk The code below is the snippet that I am trying to get working:

const HummusRecipe = require("hummus-recipe");

var annotateDoc = (fileVersion, ip, emailAddress, country) => {
    console.log("Using " + fileVersion + " to create new pdf called " +
        "public/documents/whitepaper_" + ip + "_" + country + ".pdf");

  return new Promise(function(resolve, reject) {

    const pdfDoc = new HummusRecipe(
        fileVersion,
        "public/documents/whitepaper_" + ip + "_" + country + ".pdf"
    );
    var text =
      "This document was produced for viewing by " +
      (ip || "") +
      " " +
      emailAddress +
      " in " +
      (country || "") +
      " region";

    pdfDoc
      // edit 1st page
      .editPage(1)
      .text(text, 30, 10, {
        color: "#000000",
        size: 12
      })
      .endPage()
      // end and save
      .endPDF(function(e) {
        console.log(e)
        resolve("documents/whitepaper_" + ip + "_" + country + ".pdf");
      });
  });
};

module.exports = {
  annotateDoc
};

I may be missing something very basic but any help on this would be great

ajhelsby commented 6 years ago

Finding the same is true on a standard EC2 instance as well

galkahana commented 6 years ago

good chances are that the file is not there or don't have read permissions. so how about try to log the file content. this should bring you closer toe the true cause of problem. not sure what the path ""public/documents/whitepaper" + ip + "" + country + ".pdf"" means, so it might be that you want a little ./ as prefix for relative, or ~/ for absolutes.

chunyenHuang commented 6 years ago

@ajhelsby Maybe it's relevant? https://github.com/chunyenHuang/hummusRecipe/issues/51