Is there a command-line tool for converting html files to pdf? [duplicate]convert a html book to a pdf file?Modifying PDF filesHow to convert a PowerPoint ppt file into HTML files?Is there a command line tool for validating RDF files?Convert linked html files into a pdf file?Is there some html annotation tool for adding annotations to downloaded html files?Command line tool for making icon files?Overlay text in PDF via command lineConverting .odm to .odt or .pdf - command lineCommand line tool to create a pdf file with a4 sized pages from a poster pdfConvert multi pages PDF to multi images with Inkscape command line
Doesn't the speed of light limit imply the same electron can be annihilated twice?
The space of cusp forms for GL_2 over F_q(T)
What would cause a nuclear power plant to break down after 2000 years, but not sooner?
Have there ever been other TV shows or Films that told a similiar story to the new 90210 show?
Problem with GFCI at start of circuit with both lights and two receptacles
Unconventional examples of mathematical modelling
Good way to stop electrolyte tabs from turning into powder?
When does The Truman Show take place?
Expressing a chain of boolean ORs using ILP
Are there any rules on how characters go from 0th to 1st level in a class?
Output with the same length always
Weird resistor with dots around it on the schematic
"sh -c" does not expand positional parameters, if I run it from "sudo --login". Is there a way around this?
How to prevent criminal gangs from making/buying guns?
global variant of csname…endcsname
Minimum population for language survival
What if a restaurant suddenly cannot accept credit cards, and the customer has no cash?
What is the purpose/function of this power inductor in parallel?
Can I use my OWN published papers' images in my thesis without Copyright infringment
Has the speed of light ever been measured in vacuum?
Quick destruction of a helium filled airship?
What's the point of writing that I know will never be used or read?
How to render "have ideas above his station" into German
Java methods to add and authenticate users in MySQL
Is there a command-line tool for converting html files to pdf? [duplicate]
convert a html book to a pdf file?Modifying PDF filesHow to convert a PowerPoint ppt file into HTML files?Is there a command line tool for validating RDF files?Convert linked html files into a pdf file?Is there some html annotation tool for adding annotations to downloaded html files?Command line tool for making icon files?Overlay text in PDF via command lineConverting .odm to .odt or .pdf - command lineCommand line tool to create a pdf file with a4 sized pages from a poster pdfConvert multi pages PDF to multi images with Inkscape command line
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
This question already has an answer here:
convert a html book to a pdf file?
2 answers
I would like to install a command line tool within a Docker image in order to quickly convert *html files into *pdf files.
I am surprised there is not a Unix tool to do something like this.
command-line pdf software-rec conversion html
marked as duplicate by muru, Toby Speight, X Tian, mmoya, Kusalananda♦ Aug 6 at 17:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
convert a html book to a pdf file?
2 answers
I would like to install a command line tool within a Docker image in order to quickly convert *html files into *pdf files.
I am surprised there is not a Unix tool to do something like this.
command-line pdf software-rec conversion html
marked as duplicate by muru, Toby Speight, X Tian, mmoya, Kusalananda♦ Aug 6 at 17:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
@muru It's arguable a duplicate, though (A) I'm looking for a command line tool to put in a Docker image and (B) the answers below are quite useful and more helpful that the posting above from 2015. I've edited the question to clarify this somewhat, and I'm happy to edit again.
– EB2127
Aug 5 at 4:26
1
Yes, this question is focused on command line tools while the other isn't and also, the other requires a more complex solution since it's about converting multiple, linked html documents. I don't think it's a dupe.
– terdon♦
Aug 5 at 16:21
1
html2pdf
– Barmar
Aug 5 at 21:06
this should probably be on Software Recommendations
– phuclv
Aug 6 at 16:47
@phuclv This is a good point. I didn't know this existed.
– EB2127
Aug 6 at 22:20
add a comment |
This question already has an answer here:
convert a html book to a pdf file?
2 answers
I would like to install a command line tool within a Docker image in order to quickly convert *html files into *pdf files.
I am surprised there is not a Unix tool to do something like this.
command-line pdf software-rec conversion html
This question already has an answer here:
convert a html book to a pdf file?
2 answers
I would like to install a command line tool within a Docker image in order to quickly convert *html files into *pdf files.
I am surprised there is not a Unix tool to do something like this.
This question already has an answer here:
convert a html book to a pdf file?
2 answers
command-line pdf software-rec conversion html
command-line pdf software-rec conversion html
edited Aug 5 at 16:22
terdon♦
140k34 gold badges287 silver badges466 bronze badges
140k34 gold badges287 silver badges466 bronze badges
asked Aug 5 at 2:24
EB2127EB2127
2282 silver badges7 bronze badges
2282 silver badges7 bronze badges
marked as duplicate by muru, Toby Speight, X Tian, mmoya, Kusalananda♦ Aug 6 at 17:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by muru, Toby Speight, X Tian, mmoya, Kusalananda♦ Aug 6 at 17:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by muru, Toby Speight, X Tian, mmoya, Kusalananda♦ Aug 6 at 17:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
@muru It's arguable a duplicate, though (A) I'm looking for a command line tool to put in a Docker image and (B) the answers below are quite useful and more helpful that the posting above from 2015. I've edited the question to clarify this somewhat, and I'm happy to edit again.
– EB2127
Aug 5 at 4:26
1
Yes, this question is focused on command line tools while the other isn't and also, the other requires a more complex solution since it's about converting multiple, linked html documents. I don't think it's a dupe.
– terdon♦
Aug 5 at 16:21
1
html2pdf
– Barmar
Aug 5 at 21:06
this should probably be on Software Recommendations
– phuclv
Aug 6 at 16:47
@phuclv This is a good point. I didn't know this existed.
– EB2127
Aug 6 at 22:20
add a comment |
@muru It's arguable a duplicate, though (A) I'm looking for a command line tool to put in a Docker image and (B) the answers below are quite useful and more helpful that the posting above from 2015. I've edited the question to clarify this somewhat, and I'm happy to edit again.
– EB2127
Aug 5 at 4:26
1
Yes, this question is focused on command line tools while the other isn't and also, the other requires a more complex solution since it's about converting multiple, linked html documents. I don't think it's a dupe.
– terdon♦
Aug 5 at 16:21
1
html2pdf
– Barmar
Aug 5 at 21:06
this should probably be on Software Recommendations
– phuclv
Aug 6 at 16:47
@phuclv This is a good point. I didn't know this existed.
– EB2127
Aug 6 at 22:20
@muru It's arguable a duplicate, though (A) I'm looking for a command line tool to put in a Docker image and (B) the answers below are quite useful and more helpful that the posting above from 2015. I've edited the question to clarify this somewhat, and I'm happy to edit again.
– EB2127
Aug 5 at 4:26
@muru It's arguable a duplicate, though (A) I'm looking for a command line tool to put in a Docker image and (B) the answers below are quite useful and more helpful that the posting above from 2015. I've edited the question to clarify this somewhat, and I'm happy to edit again.
– EB2127
Aug 5 at 4:26
1
1
Yes, this question is focused on command line tools while the other isn't and also, the other requires a more complex solution since it's about converting multiple, linked html documents. I don't think it's a dupe.
– terdon♦
Aug 5 at 16:21
Yes, this question is focused on command line tools while the other isn't and also, the other requires a more complex solution since it's about converting multiple, linked html documents. I don't think it's a dupe.
– terdon♦
Aug 5 at 16:21
1
1
html2pdf
– Barmar
Aug 5 at 21:06
html2pdf
– Barmar
Aug 5 at 21:06
this should probably be on Software Recommendations
– phuclv
Aug 6 at 16:47
this should probably be on Software Recommendations
– phuclv
Aug 6 at 16:47
@phuclv This is a good point. I didn't know this existed.
– EB2127
Aug 6 at 22:20
@phuclv This is a good point. I didn't know this existed.
– EB2127
Aug 6 at 22:20
add a comment |
6 Answers
6
active
oldest
votes
pandoc is a great command-line tool for file format conversion.
The disadvantage is for PDF output, you’ll need LaTeX.
The usage is
pandoc test.html -t latex -o test.pdf
If you don't have LaTeX installed, then I recommend htmldoc.
Cited from Creating a PDF
By default, pandoc will use LaTeX to create the PDF, which requires that a LaTeX engine be installed.
Alternatively, pandoc can use ConTeXt, pdfroff, or any of the following HTML/CSS-to-PDF-engines, to create a PDF: wkhtmltopdf, weasyprint or prince. To do this, specify an output file with a .pdf extension, as before, but add the --pdf-engine option or -t context, -t html, or -t ms to the command line (-t html defaults to --pdf-engine=wkhtmltopdf).
6
+1. pandoc can also usewkhtmltopdf
to directly convert from html to pdf, without needing latex. seeman pandoc
and search forwkhtmltopdf
or--pdf-engine
– cas
Aug 5 at 4:15
1
@cas This is really useful. Could you answer the question with that command? I would like to keep this answer
– EB2127
Aug 5 at 4:28
@EB2127 Stack Exchange answers can easily contain more than one solution to a problem; collaborative editing can/should make any answer better.
– Jeff Schaller♦
Aug 6 at 11:05
add a comment |
You can also try wkhtmltopdf, usage and installation is pretty straightforward.
add a comment |
weasyprint is an opion. A possible drawback is that you'll need python on your machine.
Install:
pip install weasyprint
Convert:
weasyprint in.html out.pdf
1
All distributions are shipped with Python .
– Paradox
Aug 6 at 3:57
Sure, but there are custom linux systems, on embedded devices for example, that might not have python.
– shiftas
Aug 7 at 6:42
add a comment |
I've been successfully using the 1.8 branch of HTMLDOC for years. I put it in a commercial system that has since generated hundreds of thousands of reports since 2003.
It's not super-versatile, but it is very efficient and reliable. It's limited to a basic set of postscript fonts.
It does not support CSS, but instead uses a special HTML comment directive set to control PDF specific aspects.
The source code is not too difficult to read and edit if you need to add custom facilities, if you're comfortable with C. It is compiled with GCC or Visual Studio, depending on your target platform.
Note that the HTML does not need to be in a file. You can generate it dynamically from a URL, php or aspx etc. You can also hook it up in your web server for generate a PDF file dynamically.
In my use case it generates a PDF file from an asp page which then gets attached to an email, instead of sending the HTML to the printer and the letter stuffing machine; it's a kind of print spooler.
add a comment |
There is also an html2ps program, and you could then easily convert the PostScript file to pdf. I used this several years ago, and IIRC it did a pretty good job on a large manual.
add a comment |
PhantomJS can do the job for you. It has command line functionality and works out of the box. You'll be required to write a simple Javascript function to tell it what to do. The site has a quick start guide and there are plenty of articles online to assist you. Usage is generally as follows:
phantomjs configFile.js htmlFile.html output.pdf
Here is a sample script to generate an A4 portrait PDF taken from here, save as your configFile.js
var page = require('webpage').create(),
system = require('system'),
fs = require('fs');
page.paperSize =
format: 'A4',
orientation: 'portrait',
margin:
top: "1.5cm",
bottom: "1cm"
,
footer:
height: "1cm",
contents: phantom.callback(function (pageNum, numPages)
return '' +
'<div style="margin: 0 1cm 0 1cm; font-size: 0.65em">' +
' <div style="color: #888; padding:20px 20px 0 10px; border-top: 1px solid #ccc;">' +
' <span>REPORT FOOTER</span> ' +
' <span style="float:right">' + pageNum + ' / ' + numPages + '</span>' +
' </div>' +
'</div>';
)
;
page.settings.dpi = "96";
page.content = fs.read(system.args[1]);
var output = system.args[2];
window.setTimeout(function ()
page.render(output, format: 'pdf');
phantom.exit(0);
, 2000);
add a comment |
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
pandoc is a great command-line tool for file format conversion.
The disadvantage is for PDF output, you’ll need LaTeX.
The usage is
pandoc test.html -t latex -o test.pdf
If you don't have LaTeX installed, then I recommend htmldoc.
Cited from Creating a PDF
By default, pandoc will use LaTeX to create the PDF, which requires that a LaTeX engine be installed.
Alternatively, pandoc can use ConTeXt, pdfroff, or any of the following HTML/CSS-to-PDF-engines, to create a PDF: wkhtmltopdf, weasyprint or prince. To do this, specify an output file with a .pdf extension, as before, but add the --pdf-engine option or -t context, -t html, or -t ms to the command line (-t html defaults to --pdf-engine=wkhtmltopdf).
6
+1. pandoc can also usewkhtmltopdf
to directly convert from html to pdf, without needing latex. seeman pandoc
and search forwkhtmltopdf
or--pdf-engine
– cas
Aug 5 at 4:15
1
@cas This is really useful. Could you answer the question with that command? I would like to keep this answer
– EB2127
Aug 5 at 4:28
@EB2127 Stack Exchange answers can easily contain more than one solution to a problem; collaborative editing can/should make any answer better.
– Jeff Schaller♦
Aug 6 at 11:05
add a comment |
pandoc is a great command-line tool for file format conversion.
The disadvantage is for PDF output, you’ll need LaTeX.
The usage is
pandoc test.html -t latex -o test.pdf
If you don't have LaTeX installed, then I recommend htmldoc.
Cited from Creating a PDF
By default, pandoc will use LaTeX to create the PDF, which requires that a LaTeX engine be installed.
Alternatively, pandoc can use ConTeXt, pdfroff, or any of the following HTML/CSS-to-PDF-engines, to create a PDF: wkhtmltopdf, weasyprint or prince. To do this, specify an output file with a .pdf extension, as before, but add the --pdf-engine option or -t context, -t html, or -t ms to the command line (-t html defaults to --pdf-engine=wkhtmltopdf).
6
+1. pandoc can also usewkhtmltopdf
to directly convert from html to pdf, without needing latex. seeman pandoc
and search forwkhtmltopdf
or--pdf-engine
– cas
Aug 5 at 4:15
1
@cas This is really useful. Could you answer the question with that command? I would like to keep this answer
– EB2127
Aug 5 at 4:28
@EB2127 Stack Exchange answers can easily contain more than one solution to a problem; collaborative editing can/should make any answer better.
– Jeff Schaller♦
Aug 6 at 11:05
add a comment |
pandoc is a great command-line tool for file format conversion.
The disadvantage is for PDF output, you’ll need LaTeX.
The usage is
pandoc test.html -t latex -o test.pdf
If you don't have LaTeX installed, then I recommend htmldoc.
Cited from Creating a PDF
By default, pandoc will use LaTeX to create the PDF, which requires that a LaTeX engine be installed.
Alternatively, pandoc can use ConTeXt, pdfroff, or any of the following HTML/CSS-to-PDF-engines, to create a PDF: wkhtmltopdf, weasyprint or prince. To do this, specify an output file with a .pdf extension, as before, but add the --pdf-engine option or -t context, -t html, or -t ms to the command line (-t html defaults to --pdf-engine=wkhtmltopdf).
pandoc is a great command-line tool for file format conversion.
The disadvantage is for PDF output, you’ll need LaTeX.
The usage is
pandoc test.html -t latex -o test.pdf
If you don't have LaTeX installed, then I recommend htmldoc.
Cited from Creating a PDF
By default, pandoc will use LaTeX to create the PDF, which requires that a LaTeX engine be installed.
Alternatively, pandoc can use ConTeXt, pdfroff, or any of the following HTML/CSS-to-PDF-engines, to create a PDF: wkhtmltopdf, weasyprint or prince. To do this, specify an output file with a .pdf extension, as before, but add the --pdf-engine option or -t context, -t html, or -t ms to the command line (-t html defaults to --pdf-engine=wkhtmltopdf).
edited Aug 5 at 4:54
answered Aug 5 at 3:02
ComplicatedPhenomenonComplicatedPhenomenon
3431 silver badge5 bronze badges
3431 silver badge5 bronze badges
6
+1. pandoc can also usewkhtmltopdf
to directly convert from html to pdf, without needing latex. seeman pandoc
and search forwkhtmltopdf
or--pdf-engine
– cas
Aug 5 at 4:15
1
@cas This is really useful. Could you answer the question with that command? I would like to keep this answer
– EB2127
Aug 5 at 4:28
@EB2127 Stack Exchange answers can easily contain more than one solution to a problem; collaborative editing can/should make any answer better.
– Jeff Schaller♦
Aug 6 at 11:05
add a comment |
6
+1. pandoc can also usewkhtmltopdf
to directly convert from html to pdf, without needing latex. seeman pandoc
and search forwkhtmltopdf
or--pdf-engine
– cas
Aug 5 at 4:15
1
@cas This is really useful. Could you answer the question with that command? I would like to keep this answer
– EB2127
Aug 5 at 4:28
@EB2127 Stack Exchange answers can easily contain more than one solution to a problem; collaborative editing can/should make any answer better.
– Jeff Schaller♦
Aug 6 at 11:05
6
6
+1. pandoc can also use
wkhtmltopdf
to directly convert from html to pdf, without needing latex. see man pandoc
and search for wkhtmltopdf
or --pdf-engine
– cas
Aug 5 at 4:15
+1. pandoc can also use
wkhtmltopdf
to directly convert from html to pdf, without needing latex. see man pandoc
and search for wkhtmltopdf
or --pdf-engine
– cas
Aug 5 at 4:15
1
1
@cas This is really useful. Could you answer the question with that command? I would like to keep this answer
– EB2127
Aug 5 at 4:28
@cas This is really useful. Could you answer the question with that command? I would like to keep this answer
– EB2127
Aug 5 at 4:28
@EB2127 Stack Exchange answers can easily contain more than one solution to a problem; collaborative editing can/should make any answer better.
– Jeff Schaller♦
Aug 6 at 11:05
@EB2127 Stack Exchange answers can easily contain more than one solution to a problem; collaborative editing can/should make any answer better.
– Jeff Schaller♦
Aug 6 at 11:05
add a comment |
You can also try wkhtmltopdf, usage and installation is pretty straightforward.
add a comment |
You can also try wkhtmltopdf, usage and installation is pretty straightforward.
add a comment |
You can also try wkhtmltopdf, usage and installation is pretty straightforward.
You can also try wkhtmltopdf, usage and installation is pretty straightforward.
answered Aug 5 at 12:01
guitarmanguitarman
2391 silver badge2 bronze badges
2391 silver badge2 bronze badges
add a comment |
add a comment |
weasyprint is an opion. A possible drawback is that you'll need python on your machine.
Install:
pip install weasyprint
Convert:
weasyprint in.html out.pdf
1
All distributions are shipped with Python .
– Paradox
Aug 6 at 3:57
Sure, but there are custom linux systems, on embedded devices for example, that might not have python.
– shiftas
Aug 7 at 6:42
add a comment |
weasyprint is an opion. A possible drawback is that you'll need python on your machine.
Install:
pip install weasyprint
Convert:
weasyprint in.html out.pdf
1
All distributions are shipped with Python .
– Paradox
Aug 6 at 3:57
Sure, but there are custom linux systems, on embedded devices for example, that might not have python.
– shiftas
Aug 7 at 6:42
add a comment |
weasyprint is an opion. A possible drawback is that you'll need python on your machine.
Install:
pip install weasyprint
Convert:
weasyprint in.html out.pdf
weasyprint is an opion. A possible drawback is that you'll need python on your machine.
Install:
pip install weasyprint
Convert:
weasyprint in.html out.pdf
answered Aug 5 at 6:47
shiftasshiftas
514 bronze badges
514 bronze badges
1
All distributions are shipped with Python .
– Paradox
Aug 6 at 3:57
Sure, but there are custom linux systems, on embedded devices for example, that might not have python.
– shiftas
Aug 7 at 6:42
add a comment |
1
All distributions are shipped with Python .
– Paradox
Aug 6 at 3:57
Sure, but there are custom linux systems, on embedded devices for example, that might not have python.
– shiftas
Aug 7 at 6:42
1
1
All distributions are shipped with Python .
– Paradox
Aug 6 at 3:57
All distributions are shipped with Python .
– Paradox
Aug 6 at 3:57
Sure, but there are custom linux systems, on embedded devices for example, that might not have python.
– shiftas
Aug 7 at 6:42
Sure, but there are custom linux systems, on embedded devices for example, that might not have python.
– shiftas
Aug 7 at 6:42
add a comment |
I've been successfully using the 1.8 branch of HTMLDOC for years. I put it in a commercial system that has since generated hundreds of thousands of reports since 2003.
It's not super-versatile, but it is very efficient and reliable. It's limited to a basic set of postscript fonts.
It does not support CSS, but instead uses a special HTML comment directive set to control PDF specific aspects.
The source code is not too difficult to read and edit if you need to add custom facilities, if you're comfortable with C. It is compiled with GCC or Visual Studio, depending on your target platform.
Note that the HTML does not need to be in a file. You can generate it dynamically from a URL, php or aspx etc. You can also hook it up in your web server for generate a PDF file dynamically.
In my use case it generates a PDF file from an asp page which then gets attached to an email, instead of sending the HTML to the printer and the letter stuffing machine; it's a kind of print spooler.
add a comment |
I've been successfully using the 1.8 branch of HTMLDOC for years. I put it in a commercial system that has since generated hundreds of thousands of reports since 2003.
It's not super-versatile, but it is very efficient and reliable. It's limited to a basic set of postscript fonts.
It does not support CSS, but instead uses a special HTML comment directive set to control PDF specific aspects.
The source code is not too difficult to read and edit if you need to add custom facilities, if you're comfortable with C. It is compiled with GCC or Visual Studio, depending on your target platform.
Note that the HTML does not need to be in a file. You can generate it dynamically from a URL, php or aspx etc. You can also hook it up in your web server for generate a PDF file dynamically.
In my use case it generates a PDF file from an asp page which then gets attached to an email, instead of sending the HTML to the printer and the letter stuffing machine; it's a kind of print spooler.
add a comment |
I've been successfully using the 1.8 branch of HTMLDOC for years. I put it in a commercial system that has since generated hundreds of thousands of reports since 2003.
It's not super-versatile, but it is very efficient and reliable. It's limited to a basic set of postscript fonts.
It does not support CSS, but instead uses a special HTML comment directive set to control PDF specific aspects.
The source code is not too difficult to read and edit if you need to add custom facilities, if you're comfortable with C. It is compiled with GCC or Visual Studio, depending on your target platform.
Note that the HTML does not need to be in a file. You can generate it dynamically from a URL, php or aspx etc. You can also hook it up in your web server for generate a PDF file dynamically.
In my use case it generates a PDF file from an asp page which then gets attached to an email, instead of sending the HTML to the printer and the letter stuffing machine; it's a kind of print spooler.
I've been successfully using the 1.8 branch of HTMLDOC for years. I put it in a commercial system that has since generated hundreds of thousands of reports since 2003.
It's not super-versatile, but it is very efficient and reliable. It's limited to a basic set of postscript fonts.
It does not support CSS, but instead uses a special HTML comment directive set to control PDF specific aspects.
The source code is not too difficult to read and edit if you need to add custom facilities, if you're comfortable with C. It is compiled with GCC or Visual Studio, depending on your target platform.
Note that the HTML does not need to be in a file. You can generate it dynamically from a URL, php or aspx etc. You can also hook it up in your web server for generate a PDF file dynamically.
In my use case it generates a PDF file from an asp page which then gets attached to an email, instead of sending the HTML to the printer and the letter stuffing machine; it's a kind of print spooler.
edited Aug 5 at 23:19
answered Aug 5 at 23:03
birdwesbirdwes
113 bronze badges
113 bronze badges
add a comment |
add a comment |
There is also an html2ps program, and you could then easily convert the PostScript file to pdf. I used this several years ago, and IIRC it did a pretty good job on a large manual.
add a comment |
There is also an html2ps program, and you could then easily convert the PostScript file to pdf. I used this several years ago, and IIRC it did a pretty good job on a large manual.
add a comment |
There is also an html2ps program, and you could then easily convert the PostScript file to pdf. I used this several years ago, and IIRC it did a pretty good job on a large manual.
There is also an html2ps program, and you could then easily convert the PostScript file to pdf. I used this several years ago, and IIRC it did a pretty good job on a large manual.
edited Aug 6 at 15:26
Jeff Schaller♦
49k11 gold badges72 silver badges162 bronze badges
49k11 gold badges72 silver badges162 bronze badges
answered Aug 6 at 3:46
jamesqfjamesqf
1415 bronze badges
1415 bronze badges
add a comment |
add a comment |
PhantomJS can do the job for you. It has command line functionality and works out of the box. You'll be required to write a simple Javascript function to tell it what to do. The site has a quick start guide and there are plenty of articles online to assist you. Usage is generally as follows:
phantomjs configFile.js htmlFile.html output.pdf
Here is a sample script to generate an A4 portrait PDF taken from here, save as your configFile.js
var page = require('webpage').create(),
system = require('system'),
fs = require('fs');
page.paperSize =
format: 'A4',
orientation: 'portrait',
margin:
top: "1.5cm",
bottom: "1cm"
,
footer:
height: "1cm",
contents: phantom.callback(function (pageNum, numPages)
return '' +
'<div style="margin: 0 1cm 0 1cm; font-size: 0.65em">' +
' <div style="color: #888; padding:20px 20px 0 10px; border-top: 1px solid #ccc;">' +
' <span>REPORT FOOTER</span> ' +
' <span style="float:right">' + pageNum + ' / ' + numPages + '</span>' +
' </div>' +
'</div>';
)
;
page.settings.dpi = "96";
page.content = fs.read(system.args[1]);
var output = system.args[2];
window.setTimeout(function ()
page.render(output, format: 'pdf');
phantom.exit(0);
, 2000);
add a comment |
PhantomJS can do the job for you. It has command line functionality and works out of the box. You'll be required to write a simple Javascript function to tell it what to do. The site has a quick start guide and there are plenty of articles online to assist you. Usage is generally as follows:
phantomjs configFile.js htmlFile.html output.pdf
Here is a sample script to generate an A4 portrait PDF taken from here, save as your configFile.js
var page = require('webpage').create(),
system = require('system'),
fs = require('fs');
page.paperSize =
format: 'A4',
orientation: 'portrait',
margin:
top: "1.5cm",
bottom: "1cm"
,
footer:
height: "1cm",
contents: phantom.callback(function (pageNum, numPages)
return '' +
'<div style="margin: 0 1cm 0 1cm; font-size: 0.65em">' +
' <div style="color: #888; padding:20px 20px 0 10px; border-top: 1px solid #ccc;">' +
' <span>REPORT FOOTER</span> ' +
' <span style="float:right">' + pageNum + ' / ' + numPages + '</span>' +
' </div>' +
'</div>';
)
;
page.settings.dpi = "96";
page.content = fs.read(system.args[1]);
var output = system.args[2];
window.setTimeout(function ()
page.render(output, format: 'pdf');
phantom.exit(0);
, 2000);
add a comment |
PhantomJS can do the job for you. It has command line functionality and works out of the box. You'll be required to write a simple Javascript function to tell it what to do. The site has a quick start guide and there are plenty of articles online to assist you. Usage is generally as follows:
phantomjs configFile.js htmlFile.html output.pdf
Here is a sample script to generate an A4 portrait PDF taken from here, save as your configFile.js
var page = require('webpage').create(),
system = require('system'),
fs = require('fs');
page.paperSize =
format: 'A4',
orientation: 'portrait',
margin:
top: "1.5cm",
bottom: "1cm"
,
footer:
height: "1cm",
contents: phantom.callback(function (pageNum, numPages)
return '' +
'<div style="margin: 0 1cm 0 1cm; font-size: 0.65em">' +
' <div style="color: #888; padding:20px 20px 0 10px; border-top: 1px solid #ccc;">' +
' <span>REPORT FOOTER</span> ' +
' <span style="float:right">' + pageNum + ' / ' + numPages + '</span>' +
' </div>' +
'</div>';
)
;
page.settings.dpi = "96";
page.content = fs.read(system.args[1]);
var output = system.args[2];
window.setTimeout(function ()
page.render(output, format: 'pdf');
phantom.exit(0);
, 2000);
PhantomJS can do the job for you. It has command line functionality and works out of the box. You'll be required to write a simple Javascript function to tell it what to do. The site has a quick start guide and there are plenty of articles online to assist you. Usage is generally as follows:
phantomjs configFile.js htmlFile.html output.pdf
Here is a sample script to generate an A4 portrait PDF taken from here, save as your configFile.js
var page = require('webpage').create(),
system = require('system'),
fs = require('fs');
page.paperSize =
format: 'A4',
orientation: 'portrait',
margin:
top: "1.5cm",
bottom: "1cm"
,
footer:
height: "1cm",
contents: phantom.callback(function (pageNum, numPages)
return '' +
'<div style="margin: 0 1cm 0 1cm; font-size: 0.65em">' +
' <div style="color: #888; padding:20px 20px 0 10px; border-top: 1px solid #ccc;">' +
' <span>REPORT FOOTER</span> ' +
' <span style="float:right">' + pageNum + ' / ' + numPages + '</span>' +
' </div>' +
'</div>';
)
;
page.settings.dpi = "96";
page.content = fs.read(system.args[1]);
var output = system.args[2];
window.setTimeout(function ()
page.render(output, format: 'pdf');
phantom.exit(0);
, 2000);
edited Aug 7 at 10:56
Kusalananda♦
160k18 gold badges316 silver badges502 bronze badges
160k18 gold badges316 silver badges502 bronze badges
answered Aug 6 at 15:21
The BetpetThe Betpet
12 bronze badges
12 bronze badges
add a comment |
add a comment |
@muru It's arguable a duplicate, though (A) I'm looking for a command line tool to put in a Docker image and (B) the answers below are quite useful and more helpful that the posting above from 2015. I've edited the question to clarify this somewhat, and I'm happy to edit again.
– EB2127
Aug 5 at 4:26
1
Yes, this question is focused on command line tools while the other isn't and also, the other requires a more complex solution since it's about converting multiple, linked html documents. I don't think it's a dupe.
– terdon♦
Aug 5 at 16:21
1
html2pdf
– Barmar
Aug 5 at 21:06
this should probably be on Software Recommendations
– phuclv
Aug 6 at 16:47
@phuclv This is a good point. I didn't know this existed.
– EB2127
Aug 6 at 22:20