Hi All,
By using html-pdf we are able to install and generate PDF file in local setup (environment : CentOS Linux release 7.0.1406 ,Node v5.0.0 ,npm 3.5.0) here every thing is fine . When we try to install on AWS we got some errors to resolve that we installed this ( bzip2 -d file.tar.bz2 ,yum install fontconfig). then installation succes but while generating PDF file , file generated with empty data (environment : CentOS Linux release 7.1.1503 ,Node v5.0.0 ,npm 3.5.0) PFA for the same
test.pdf
+1
@somaranaresh did you use a custom font? It looks like the font isn't loaded at all.
Sorry, I've never seen this problem.
@somaranaresh @fabiusss , it generated an empty pdf because your application is defaulting to an incompatible font in the font bundle you installed. You will need to install proper custom font(s) to resolve the issue. Do a 'yum search fonts’. In my case, I noticed the liberation-mono-fonts, liberation-narrow-fonts, liberation-serif-fonts, liberation-sans-fonts all offered Sans-Serif fonts to replace Times New Roman, Microsoft Arial etc. Next I did a 'yum install' on those and it did it for me.
@blaiseche @somaranaresh thanks, in my server (Linux CentOS release 7.1) I have not found any fonts. I solved including
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet">
and
body{
font-family: 'Source Sans Pro', sans-serif;
}
in my project.
@marcbachmann @blaiseche thanks for reply. we tried even example file provide in this module path is test/example.html still it is generated empty pdf . same file worked on our local setup configuration as i mentioned above.
Do you use javascript that's asynchronous? That's not yet supported.
@marcbachmann In README.md first example we tried
Hi
I'm trying to generate PDF from generated html on the fly but get empty documents when I use:
pdf.create(someHtml, someOptions).toBuffer(
(err, buffer) => {
response.setHeader('Content-Type', 'application/pdf')
response.end(buffer.toString('utf-8'))
}
)
The page title in the browser is garbled random characters so I think it may be an encoding issue. (I've also tried 'utf8'). The results are the same for the test HTML file as my generated html.
.toFile works as expected with both test cases.
Wooohooo! So the solution is to rather use a stream:
pdf.create(someHtml, someOptions).toStream(
(err, stream) => {
response.setHeader('Content-Type', 'application/pdf')
stream.pipe(response)
}
)
Most helpful comment
@blaiseche @somaranaresh thanks, in my server (Linux CentOS release 7.1) I have not found any fonts. I solved including
and
in my project.