Comments (53)
sudo apt-get install libfontconfig
from node-html-pdf.
I was getting the EPIPE error as well with an app running in docker containers on ec2s. In my case, it turned out not to be the fontconfig lib, but rather needing to npm rebuild phantomjs-prebuilt
in my Dockerfile.
from node-html-pdf.
sudo apt-get install libfontconfig
fixed it for me, thanks @sovanna!
from node-html-pdf.
for the record, yum install fontconfig
if you are using centOS
from node-html-pdf.
Not sure if this helps but I started encountering this exact same EPIPE issue while attempting to troubleshoot my rendering issue.
It was recommended elsewhere to add the following lines to the options but doing so is what causes the EPIPE issue for me. Removing these lines resolves the EPIPE issue.
"phantomPath": "./node_modules/phantomjs/bin/phantomjs",
"phantomArgs": [],
from node-html-pdf.
How can i fix this error on lambda functions ?
Below is error i see in CloudWatch logs for my function
Error: write EPIPE at exports._errnoException (util.js:1018:11) at WriteWrap.afterWrite (net.js:800:14)
Error: write EPIPE
at exports._errnoException (util.js:1018:11)
at WriteWrap.afterWrite (net.js:800:14)
My code for pdf creation is below
const templatePath = __dirname+'/templaate.hbs';
fs.readFile(templatePath, {encoding: 'utf-8'}, function (error, html) {
if(!error){
pdf.create(html, options).toBuffer(function(err, buffer){
//Upload to s3 bucket from received buffer
});
}
});
Can anyone help with this?
from node-html-pdf.
Started getting this error after upgrading lambda environment from node 8 to node 10.x. Anyone know how to fix this on AWS lambda?
Went back to node 8
from node-html-pdf.
Same, getting it for node 10 as well on AWS Lambda
from node-html-pdf.
I assume this was a syntax error. So I'm closing this for now.
from node-html-pdf.
I had the same error
Error: write EPIPE
at errnoException (net.js:905:11)
at Object.afterWrite (net.js:721:19)
followed by this one
Error creating pdf [Error: /opt/app_name/app/programs/server/npm/npm-container/node_modules/html-pdf/node_modules/phantomjs/lib/phantom/bin/phantomjs: 4: /opt/app_name/app/programs/server/npm/npm-container/node_modules/html-pdf/node_modules/phantomjs/lib/phantom/bin/phantomjs: Syntax error: Unterminated quoted string
It is caused by phantomjs's executable being of a wrong architecture.
If you have this error you can use this to check if the binary matches your system.
$ file /path/phantomjs
Running npm install on html-pdf should fix this.
from node-html-pdf.
Provide my solution:
Hope to help more people
The problem is on Linux OS
You can use fc-list first to check if there is a font library installed
If the instruction is invalid, you can install the font according to the version
Ubuntu / Debian
sudo apt-get install libfontconfig
Centos / Redhat
sudo yum install fontconfig
from node-html-pdf.
Anyone coming here for AWS lambda node 10 environment,
After some investigation, I found that in case of AWS lambda, the issue is the environment and not node itself.
Many OS shared libraries and fonts available in Lambda Node 8 environment are not present in Lambda Node 10 environment. (libXrender, libpng, libjpeg etc).. This is the cause of error.
There is a way to add these shared libraries into the lambda layer which would fix the problem
The first comment in this article explains how to do it. https://tech.mybuilder.com/compiling-wkhtmltopdf-aws-lambda-with-bref-easier-than-you-think/
from node-html-pdf.
UPDATE: solved my issue after a reboot. Yep, you read that right. 🔫
I don't know if the error is the same, but it surely looks very related to how the interaction with phantomjs is made: I am spawning my Node process (that uses node-html-pdf
) from a C# application, and it looks like child.stdin.write
fails with EPIPE
.
Error: write EPIPE
at exports._errnoException (util.js:746:11)
at Socket._writeGeneric (net.js:690:26)
at Socket._write (net.js:709:8)
at doWrite (_stream_writable.js:301:12)
at writeOrBuffer (_stream_writable.js:288:5)
at Socket.Writable.write (_stream_writable.js:217:11)
at Socket.write (net.js:634:40)
at PDF.module.exports.PDF.exec (C:\Users\fpontillo\AppData\Roaming\npm\node_modules\my-module\node_modules\html-pdf\lib\pdf.js:136:26)
at PDF.module.exports.PDF.toStream (C:\Users\fpontillo\AppData\Roaming\npm\node_modules\my-module\node_modules\html-pdf\lib\pdf.js:66:19)
at Promise.post (C:\Users\fpontillo\AppData\Roaming\npm\node_modules\my-module\node_modules\q\q.js:1161:36)
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn phantomjs ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
The child
process is of course phantomjs
, and it crashes here (I am using version 2.0.0):
return child.stdin.write(JSON.stringify({
html: this.html,
options: this.options
}) + '\n', 'utf8');
My setup is Windows 8.1 x64, Node 0.12.7 and phantomjs 2.0.0 (manually installed, not via npm
).
For reference, here's my C# code I am using to launch the PDF generation:
var process = new Process {
StartInfo = new ProcessStartInfo {
FileName = "myapp",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true
}
};
try {
process.Start();
// write the JSON report to the standard input
process.StandardInput.WriteLine(jsonReport);
process.StandardInput.Close();
// wait for exit
process.WaitForExit();
if (process.ExitCode != 0) {
// THIS IS WHERE IT ERRORS
Console.WriteLine(@"{0}", process.StandardError.ReadToEnd());
}
Console.WriteLine(@"stdout: {0}", process.StandardOutput.ReadToEnd());
} catch (Exception ex) {
Console.WriteLine(ex.StackTrace);
}
Do you have any idea of what could cause the issue?
from node-html-pdf.
I had this problem in Docker as well, I was binding the source code into the container as a volume (for easy development). The problem was that I had built the original npm packages on the host and mapped them into the container (it seems that even npm didn't rebuild the needed packages for the container).
The solution was similar to @kevinbror except I had to rebuild everything from inside the container with $ npm rebuild
from node-html-pdf.
from node-html-pdf.
One more solution:
Update selinux policy by changing phantomjs file to bin_t type
semanage fcontext -a -t bin_t '/opt/phantomjs/bin/phantomjs
After adding new type to selinux policy you need to update the file permissions
sudo /sbin/restorecon -v /opt/phantomjs/bin/phantomjs
Now you need to allow httpd daemon to change its resource limits by setting the boolean
sudo setsebool -P httpd_setrlimit 1
Hope it helps ( :
from node-html-pdf.
This will work 100 % -- follow this it worked for me ...
https://www.vultr.com/docs/how-to-install-phantomjs-on-ubuntu-16-04
from node-html-pdf.
I have the same problem on Windows and cant get html-pdf to work after packing to asar. Anyone found a workaround on this issue?
same here windows -- though this happened after updating to gulp4. it worked in gulp3.
events.js:183
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at Socket._writeGeneric (net.js:768:25)
at Socket._write (net.js:787:8)
at doWrite (_stream_writable.js:396:12)
at writeOrBuffer (_stream_writable.js:382:5)
at Socket.Writable.write (_stream_writable.js:290:11)
at Socket.write (net.js:711:40)
at PDF.PdfExec [as exec] (C:\Users\gsdajs1\Repos\dri-dtm-config\node_modules\html-pdf\lib\pdf.js:141:15)
at PDF.PdfToBuffer [as toBuffer] (C:\Users\gsdajs1\Repos\dri-dtm-config\node_modules\html-pdf\lib\pdf.js:44:8)
at DestroyableTransform._transform (C:\Users\gsdajs1\Repos\dri-dtm-config\node_modules\gulp-html-pdf\index.js:19:8)
at DestroyableTransform.Transform._read (C:\Users\gsdajs1\Repos\dri-dtm-config\node_modules\readable-stream\lib\_stream_transform.js:182:10)
installing phantomjs-prebuilt globally did not resolve this, hoped it would. still stuck.
update! (windows)
removing phantomPath from pdf(options) worked!
(after a global install pf phantom, not sure if related)
from node-html-pdf.
Indeed, PhantomJS is by default compiled for the platform where npm install
is ran. This causes issues when npm install
is ran on a different platform than where it is being used (e.g. when you build node_modules locally on your Windows/MacOS environment and then push it to an Linux environment).
PhantomJS addresses this issue on the GitHub README.md here.
For me setting the environment variables to:
PHANTOMJS_PLATFORM="linux"
PHANTOMJS_ARCH="x64"
before running npm install
fixed the issue as I was running the code on AWS Lambda (linux x64) but compiling it on MacOS.
from node-html-pdf.
I got this issue running in Docker.
Solution: I had to update my Dockerfile to:
FROM ubuntu:16.04
RUN apt-get update -qq && \
apt-get upgrade -yqq && \
apt-get install curl -yqq && \
curl -sL https://deb.nodesource.com/setup_lts.x | bash - && \
apt-get install nodejs -yqq && \
apt-get install bzip2 -yqq && \
apt-get install build-essential chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 -yqq
WORKDIR /app
COPY . .
# RUN npm install
RUN npm install --only=prod
CMD ["node", "keystone.js"]
from node-html-pdf.
libfontconfig
Any idea what exactly libfontconfig is used for?
from node-html-pdf.
i am facing same issue but still not able to get the answer
Error: write EPIPE
0|hb Api | at afterWrite
Dispatched (internal/stream_base_commons.js:156:25)
0|hb Api | at writeGeneric (internal/stream_base_commons.js:147:3)
0|hb Api | at Socket._writeGeneric (net.js:787:11)
0|hb Api | at Socket._write (net.js:799:8)
0|hb Api | at writeOrBuffer (internal/streams/writable.js:358:12)
0|hb Api | at Socket.Writable.write (internal/streams/writable.js:303:10)
0|hb Api | at PDF.PdfExec [as exec] (/var/www/html/hbv2Api/node_modules/html-pdf/lib/pdf.js:141:15)
0|hb Api | at PDF.PdfToFile [as toFile] (/var/www/html/hbv2Api/node_modules/html-pdf/lib/pdf.js:83:8)
0|hb Api | at /var/www/html/hbv2Api/app/helper/pdfHelper.js:6:39
0|hb Api | at new Promise ()
0|hb Api | at generatePdf (/var/www/html/hbv2Api/app/helper/pdfHelper.js:5:16)
0|hb Api | at exports.getInvoice (/var/www/html/hbv2Api/app/modules/controllers/orders.controller.js:1465:13)
0|hb Api | at processTicksAndRejections (internal/process/task_queues.js:95:5) {
0|hb Api | errno: -32,
0|hb Api | code: 'EPIPE',
0|hb Api | syscall: 'write'
0|hb Api | }
from node-html-pdf.
I didn't have a look at your html yet, but there are some errors that don't get catched in your code.
You're always using next like this.
function(err, html) {
if (err) {
next(err);
}
//...
}
In a case of an error, your code continues with the execution. To prevent this, you have to return the error like here:
function(err, html) {
if (err) {
return next(err);
}
//...
}
from node-html-pdf.
Have same issue.
html=Twig.twig({data: html}).render({
bodys: config.list.map(function(item){
return input.row[item.id].body;
})
});
var options = { filename: dest, format: 'Letter'};
console.log('Create pdf..');//Last console log before error
pdf.create(html, options).toFile(function(err, res){
if(err){
console.error(err);
callback(err);
}
console.log('Pdf file:',res.filename);
callback(err, dest_file);
});
This code working on my local machine (Win8), but on server (Debian) I got this error and server fault..
events.js:85
throw er; // Unhandled 'error' event
Error: write EPIPE
at exports._errnoException (util.js:746:11)
at WriteWrap.afterWrite (net.js:775:14)
I check path to file, its like this:
local: c:...path_to_project..\engine../public/reports/..filename.pdf
server: /var/...path_to_project../engine/../public/reports/..filename.pdf
Paths like this works correctly in another places (generate images)
What i can do with this problem? Have no idea..
from node-html-pdf.
same problem and running npm instal on html-pdf doesn't fix it.. anyone have found how to solve this ?
from node-html-pdf.
Hi marc
I am facing the EPIPE error once i have deployed my app to Amazon EC2 (Ubuntu 14.04.3 LTS). This works totally fine on my dev box, which is running Windows 10.
My app is a meteor app and it is deployed to EC2 using mupx.
I used to get the EOENT error and following the instructions here and other places, i did execute sudo apt-get install libfontconfig
and after that the error changed to EPIPE
Here are my config options
pdfConfigOptions
= {"directory": "/opt/<appname>/tmp",
"format":
"A4",
"orientation":
"portrait",
"border":
"0",
"type":
"pdf",
"quality":
"75"
"timeout":
30000}
Here is my code invoking the pdf creation. (I removed the code that deals with the returned buffer as part of debugging)
var
pdfCreator = Meteor.npmRequire('html-pdf');
let
pdf = pdfCreator.create(html, this.pdfConfigOptions);
pdf.toBuffer(function
(err, buffer) {
//This line fails with the following error
});
events.js:72
throw er; // Unhandled 'error'
event
^
Error:
write EPIPE
at errnoException
(net.js:905:11)
at Object.afterWrite (net.js:721:19)
FYI: My code had Meteor.bindEnvironment around the callback function, but i removed that while testing to figure out what is causing these errors. This clearly is happening while html-pdf is trying to create the pdf using phantom,
phantom is installed on the image, See below
ubuntu@ip-<0.0.0.0>/opt/$ sudo find . -name "phantom"
./last/bundle/programs/server/npm/npm-container/node_modules/html-pdf/node_modules/phantomjs-prebuilt/lib/phantom
./current/bundle/programs/server/npm/npm-container/node_modules/html-pdf/node_modules/phantomjs-prebuilt/lib/phantom
Any help in pointing me to the right direction to either fix this or identify the issue is greatly appreciated.
Thanks a lot in advance for your time
S
from node-html-pdf.
I was facing same EPIPE issue while generating pdf
@sovanna's "sudo apt-get install libfontconfig" worked for me
Thanks Buddy
from node-html-pdf.
I was getting following error while exporting pdf on my centOS system.
Error: write EPIPE
at errnoException (net.js:905:11)
at Object.afterWrite (net.js:721:19)
After running yum install fontconfig , now pdf is generating but its content is not visible. It is a simple html table.
Same case is working on my ubuntu system.
from node-html-pdf.
Try adding the following via yum
freetype*
fontconfig
urw-fonts
I have the above 3 in my Dockerfile that I'm using with this module. These seemed to resolve my issues with fonts or styling.
from node-html-pdf.
I had the same thing as @kevinbror and got it working by rebuilding phantomjs. (Everything worked fine in my macbook, but when I cloned the my git to Ubuntu, running my node server there was resulting the EPIPE error.)
from node-html-pdf.
are you pushing your node_modules
to git?
Don't do that. All the platform specific modules won't work unless you run npm rebuild
.
from node-html-pdf.
I am not that novice :-) My 'base project' is templated by swagger-node-express and it's default .gitignore keeps node modules out of git among other artefact files. However, I might have had a really old phantom version on my ubuntu machine from some other project I have been doing previously with angular app's test automation. But I have seen people's repos with node_modules as well as other library stuff so that is a valid concern you raised 👍
from node-html-pdf.
I am having the same issue on macOS
uncaughtException: { Error: write EPIPE
at exports._errnoException (util.js:1022:11)
at WriteWrap.afterWrite [as oncomplete] (net.js:804:14) code: 'EPIPE', errno: 'EPIPE', syscall: 'write' }
tried every possible solution suggested on web. doesn't got any luck.
any suggestions ?
And when i try to convert the HTML from terminal it works fine. :(
from node-html-pdf.
You just have to install libfontconfig1
package.
For debian users: sudo apt-get install libfontconfig1
from node-html-pdf.
Hi, I am using html-pdf npm package for my electron app. It was working perfect in both development and production environment. But now after using ASAR to pack my code, it stopped working in production. Gives Error
Uncaught Error: write EPIPE
at exports._errnoException (util.js:1022)
at Socket._writeGeneric (net.js:715)
at Socket._write (net.js:734)
at doWrite (_stream_writable.js:332)
at writeOrBuffer (_stream_writable.js:318)
at Socket.Writable.write (_stream_writable.js:245)
at Socket.write (net.js:661)
at PDF.PdfExec [as exec] (C:\Project\Project-win32-ia32\resources\app.asar\node_modules\html-pdf\lib\pdf.js:136)
at PDF.PdfToFile [as toFile] (C:\Project\Project-win32-ia32\resources\app.asar\node_modules\html-pdf\lib\pdf.js:83)
at generatePdf (:1155:43)
The solution mentioned by others i.e. to install libfontconfig is not applicable here since there is not libfontconfig package in npm.
Being a nube I expect to be clarified if i failed to understand things from the error msg or from the above discussions.
P.S: I am well aware that ASAR pack are read only. So the path for pdf is outside it. But still the same problem. Does html-pdf perform any write operation other then the final write to the file path specified?
from node-html-pdf.
@ishwarrimal any chance you figured out a solution to this issue with electron? Dealing with this now...
from node-html-pdf.
hi @danmckeon, since html-pdf
package was doing some write operation internally, the only solution for me was moving out this package from node-modules and keeping it one level outside the current directory and giving the absolute path. But with that included, the installer size was getting huge.
Hence later i found out that electron on itself has provide a tool for printing pdf. So using that it was very easy for me.
I would prefer the second approach (using inbuilt tool) but if you want to know more about the first approach please let me know.
Hope this helps.
from node-html-pdf.
@ishwarrimal I noticed that tool, but every PDF I create with Chromium (including with the Electron tool) is huge. Did you find a workaround for that?
from node-html-pdf.
@sovanna you are the boss! save my day Thanks!
from node-html-pdf.
I have the same problem on Windows and cant get html-pdf to work after packing to asar. Anyone found a workaround on this issue?
from node-html-pdf.
from node-html-pdf.
@sovanna Thanks man that worked. 👍
from node-html-pdf.
@Keksike what lambda node js version you are at?
from node-html-pdf.
This answer on explains what to do on aws lambda with node 10 or 12: https://stackoverflow.com/a/56843029/3556874
from node-html-pdf.
Do this In case you are running the app inside docker alpine image, because phantomjs-prebuilt doesn't work on alpine
from node-html-pdf.
use electron build (windows)
*Error: write EPIPE
{ phantomPath: path.join(process.cwd(), 'resources/app.asar.unpacked/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs.exe'), script: path.join(process.cwd(), 'resources/pdf_a4_portrait.js') }
from node-html-pdf.
https://www.electronjs.org/docs/tutorial/application-packaging
from node-html-pdf.
npm rebuild phantomjs-prebuilt
This solution works for me, i ran it on my local then sync files to server. Thanks @kevinbror !
from node-html-pdf.
i have the same issue when using react-pdf
library, and just happening on CI.
Node: 14.17.0
Webpack: 4.46.0
react-pdf: 4.2.0
from node-html-pdf.
Anyone able to figure out the fix?
@marcbachmann
When i add phantomPath in options i see error
But when i remove it file get generated in local machine. But fails on server saying phantomJS path not found
from node-html-pdf.
Found a solution!
If you use docker, avoid using the alphine versions.
I switched from node:14-alphine to node:14
And it was all fine
from node-html-pdf.
Found a solution! If you use docker, avoid using the alphine versions. I switched from node:14-alphine to node:14 And it was all fine
Unfortunately it didn't help me.
I found a solution here
from node-html-pdf.
I used Docker to replicate the error that was not possible to replicate on localhost, and I could fix it by adding the following command on my Dockerfile:
RUN apk add --no-cache --virtual .build-deps ca-certificates openssl \
&& wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1/dockerized-phantomjs.tar.gz" | tar xz -C / \
&& apk del .build-deps
I got it from here.
from node-html-pdf.
Related Issues (20)
- How can I make sure table header section should have at least one row.
- Background color not applying those area where no html
- Image not showing when uploaded on vps server
- QR code not visible over generated pdf post ami upgrade HOT 2
- Fonts don't work properly on server HOT 4
- stream (.toStream) not generated after deploying to k8s HOT 2
- The download pdf always have an empty page at last HOT 1
- html-pdf: Unknown Error throw new ERR_INVALID_ARG_TYPE(name, 'string', value); Docker HOT 1
- Pdf saved in TMP directory HOT 1
- Is watermark possible in pdf? HOT 3
- Not able to resize the chebox size while generating the pdf
- Syntax for forcing a page break HOT 2
- Potential injection vulnerability in node-html-pdf
- Page overflow with white line
- PDF Creation Error: spawn /root/pando-app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs ENOENT HOT 1
- The answer to how to resolve Windows error of phantomjs ENOENT issue
- Error: spawn E2BIG
- error HOT 2
- Error: spawn C:\home\site\wwwroot\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs ENOENTat
- This package has been deprecated HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-html-pdf.