Prerequisites
API/app/plugin version
6.0.3
Node.js version
16.18.1
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Amazon Linux 2
Description
I moved my server from Heroku to AWS EC2 instance. On heroku everything worked fine, but on the AWS instance I get this error:
Error: Error opening output file fd://0.png
at ChildProcess.<anonymous> (/home/ec2-user/repo/node_modules/node-poppler/src/index.js:774:14)
at ChildProcess.emit (node:events:513:28)
at ChildProcess.emit (node:domain:489:12)
at maybeClose (node:internal/child_process:1100:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
To install poppler dependencies on heroku
instance I added a buildpack in heroku settings: https://github.com/amitree/heroku-buildpack-poppler
To install poppler dependencies on AWS EC2
instance I installed them with:
sudo yum install poppler-data
sudo yum install poppler-utils
Related issue
I found this StackOverflow issue. Which says that this is a bug in pdfToCairo. But the same code worked in Heroku.
Do you think this is an issue of different linux os. Or is there something I am missing and maybe I just need to install some kind of dependencies for this to work?
Differences between heroku and aws linux.
On Heroku, this is called the "stack"βan operating system image curated and maintained by Heroku. The stack is based on Ubuntu, the open source Linux distribution.
AWS's Amazon Linux will be based on Red Hat's Fedora community Linux.
Steps to Reproduce
I just created a AWS EC2 instance with default settings, installed node, installed poppler dependencies and tried running the code below.
I need to generate a png file from pdf which has a single page.
First I generate the pdf buffer:
const PdfOptions = {
base: `file:///${base}/`,
format: 'letter',
height: 2551,
localUrlAccess: true,
orientation: 'landscape',
timeout: '100000',
width: 3295,
};
const html = this.getHtml();
const fileName = await PdfService.GenerateFileName(FileExtension.Pdf);
return new Promise((resolve, reject) => {
pdf.create(html, PdfOptions).toBuffer(function (err, buffer) {
if (err) {
reject(err);
return logger.error(err);
}
resolve({ buffer, fileName });
});
});
Then I try to generate the png from the pdf buffer:
const pdfToCairoOptions = {
pngFile: true,
singleFile: true,
resolutionXYAxis: 72,
};
const pngBuffer = await poppler.pdfToCairo(pdfPath, undefined, pdfToCairoOptions); // Crashes here
const binaryBuffer = Buffer.from(pngBuffer, 'binary');
return { pngBuffer: binaryBuffer };
Expected Behaviour
Expected behaviour should be that the png file is generated. On my development machine(macOS) and heroku it works. But on AWS EC2 instance it doesn't work.