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

Deploying to elastic beanstalk instance breaks pdf read functionality #305

Open
ajhelsby opened this issue Aug 2, 2018 · 3 comments
Open

Comments

@ajhelsby
Copy link

ajhelsby commented Aug 2, 2018

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
Copy link
Author

ajhelsby commented Aug 2, 2018

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

@galkahana
Copy link
Owner

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
Copy link
Contributor

chunyenHuang commented Aug 20, 2018

@ajhelsby Maybe it's relevant?
chunyenHuang/hummusRecipe#51

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