Sie sind auf Seite 1von 5

2/23/2017 What is the best way to generate a PDF file from HTML and CSS?

- Quora

PDF Converter HTML5 Cascading Style Sheets HTML PDF (file format)

Web Development

What is the best way to generate a PDF le from


HTML and CSS?

Promoted by Rollbar

Catch code errors before your users do...


Rollbar detects and alerts you when code breaks. Get stack trace, user data and defeat
Search for questions, people, and topics Sign In
impactful errors.

Learn More at Rollbar.com


Related Questions

11 Answers What is the best way to convert HTML to a PDF on a


web server?

Daniel Nordstrom, Founder of things Web junkie Cryptonymity What's a good way of rendering HTML/CSS to PDF
cheerleader server-side?
Written Aug 15, 2014
While it may not be the kind of answer you're looking for, I'd argue that on a Mac, the easiest What is the best way I can type in a PDF file?

way is to open the HTML le in a web browser and choose to print it, then save it as PDF.
How do I convert PSD to HTML/CSS in best way?

On MacOS Yosemite: What is the best PDF to HTML converter?

What is the best way to learn HTML CSS on


MacBook?

How can I include a CSS file into a HTML?

Is it possible to convert a Kindle book to PDF format?

I know PHP, HTML, and CSS. What is the best way


to bring it all together?

What is the best way to put content into HTML file?

A very manual way, but very simple.

I've worked with PDF on a few web projects, and there's a whole bunch of open source
libraries for this purpose, in many languagessome are covered in the other answers.
However, the question could use some details, such as if we're talking about applications or
code libraries, manual or automation, bulk generation or not, and so on, as well as which
platforms and devices we're targeting.
14.8k Views View Upvotes

Promoted by X-Team
Hire motivated developers.
Scale your team with developers trusted by Twitter, FOX, Riot Games and more.

Learn More at x-team.com

https://www.quora.com/What-is-the-best-way-to-generate-a-PDF-file-from-HTML-and-CSS 1/5
2/23/2017 What is the best way to generate a PDF file from HTML and CSS? - Quora

Related Questions More Answers Below

What is the best way to convert HTML to a PDF on a web server?

What's a good way of rendering HTML/CSS to PDF server-side?

What is the best way I can type in a PDF file?

How do I convert PSD to HTML/CSS in best way?

What is the best PDF to HTML converter?

Giordon Stark, taught at Caltech


Written Aug 15, 2014

Convert HTML to PDF with CSS (the best)

HTML/CSS to PDF converter written in Python

WeasyPrint converts HTML/CSS documents to PDF


9.9k Views View Upvotes

Milenko Vlajnic, works at Plava Tvornica


Written Oct 17

Converting HTML to PDF.

When converting HTML with css to pdf people often encounter to a problems, wether is the
font rendering, css-oat, positioning elements to problems with memory on server side. Main
question is often how do i really need to write css for PDF, does it has some hidden features
that will make all things work.

Well the answer is that there is no shortcuts. Some libraries will do most job for you if you
keep html simple, but when you need to change something to more complicated you will
probably encounter dierent results with rendering, converting time, memory usage and so
on.

People often use converters on server side because it has more libraries, and you can more
easily and directly store data on a server, or pass additional headers to show content of PDF in
browser. There arent many client side converters. Since converters are expensive if you are
using simple HTML it would be better to use client side script to free up server resources. In
this example we are only going to examine server side converters.

Lets get started.

We will examine converting time, memory consuption, and visual look for couple of HTML
renderers.
We are going to use 3 templates in this example. One is fairly simple, and other two are more
complex regarding code structure, css or the amount of data that needs to be converted. We
are going to rate results from 1 to 5 scale, 1 is the poor result and 5 is the excellent results. All of
the test was done on same machine (running Linux os) couple of times, and average results
was taken for each group of data. We will only valuate free open source PDF converters

You can preview HTML templates that we used in our testings


Simple HTML
Complex HTML
Long HTML

Installation

DOMPDF :
(Os: universal, runs in php) Very easy installation (Under one minute). It uses composer to

https://www.quora.com/What-is-the-best-way-to-generate-a-PDF-file-from-HTML-and-CSS 2/5
2/23/2017 What is the best way to generate a PDF file from HTML and CSS? - Quora
download and install dependencies. It also has a zip le if you dont want to use it with
composer. Its a mostly a CSS 2.1 compliant HTML layout and rendering engine written in
PHP. Its a style-driven renderer: it will download and read external stylesheets, inline style
tags, and the style attributes of individual HTML elements. It also supports most
presentational HTML attributes.

wkhtmltopdf :
(os: windows, mac os, linux, SmartOS , OpenBSD). Easy download and installation, under
a minute. Uses Qt WebKit rendering engine. These run entirely headless and do not
require a display or display service.. In this demonstration we are going to use 64 bit version

mPDF :
(os: universal, runs in php). Easy download and installation, under a minute. It uses
composer to download and install dependencies. mPDF is a PHP class which generates PDF
les from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF, with a number of
enhancements.

TCPDF :
(os: universal, runs in php). Easy download and installation, under a minute. No dependency
required to generate simple HTML. NOTE: There is a new version of TCPDF under
development, but i was having diculties running this new development version.

Getting into details.

As seen in results if you are going to use simple html for example simple invoices for
generating PDF you will probably prefer mpdf. It provided excellent results, with 16 mb of
usage, wkhtmltopdf did a decent job too, generating in half time of mpdf but used twice as
much memory as mpdf. DOMPDF and tcpdf would require a html optimization to get to
desire results.

For a complex html we denitely recommend wkhtmltopdf. Although it uses large amount of
memory, results were excellent. Perhaps running it as separate service is good choice, but that
depends on how much often you expect to generate complex PDFs. It also took some time to
generate PDF, around 18 seconds, but if thats the cost to have a excellent result ill take it.
Mpdf was struggling to render correctly column sizes, and it lack some css details, but hey if
you dont need them you can live with mpdf too because it used only 23mb of memory in
compared to wkhtmltopdf which used 108. Other libraries are not so worth to be mentioned
here.

In long example we used pretty simple html, enough to generate around 15 pages. Peple often
need to generate large but simple PDFs. For example some database export. Once again
wkhtmltopdf and mpdf delivered good results. Wkhtmltopdf took the win in speed and
memory taking only 654ms to generate pdf and 21mb of ram, while mpdf took about 7
seconds and a bit more memory around 80mb, both delivered excellent results. It seems like
tcpdf would run forever but around 2 minutes of execution delivered good results using only
6mb of ram, but that time is simply too much for anyone to wait and seems to be funny when
we look at half second for wkhtmltopdf. Dompdf produced out of memory exception, which
is often the problem whit DOMPDF as i can see on stackoverow.

Its worth to mention that wkhtmltopdf has some other features like running Javascript
inside, and you can get page number from wkhtmltopdf where you can inject page number
to certain html element you choose. You can also provide headers and footers just like in
tcpdf library. Wkhtmltopdf gives even more variables to play with it.

Conclusion.

Although results vary in many ways, its safe to say that mpdf and wkhtmltopdf will get you
where you need quickly and with good results. For DOMPDF it will take you some time to add
for example fonts to PDF, and to satisfy html to have a good looking PDF. We used dompdf in
some simple renderings, but we quickly change it to wkhtmltopdf when it comes to more
complex solutions. Of course there are maybe some better PDF converters online but I would
say by googling these 4 5 pdf converters are mainly in conversations.

Details and test on: How to eciently transfer HTML to PDF - Plava tvornica
7.7k Views View Upvotes

Connie Yu, Everything about PDF


Written Dec 2

The best way to create PDF out from HTML is using the PDF Creator :

https://www.quora.com/What-is-the-best-way-to-generate-a-PDF-file-from-HTML-and-CSS 3/5
2/23/2017 What is the best way to generate a PDF file from HTML and CSS? - Quora
1. Open PDF Creator and drag-n-drop the webpage les to its interface.

2. Hit the "Convert" to start webpages to PDF conversion on Mac.

The best thing about PDF Creator is, it allows users to create PDF from les in a wide range of
dierent format, even merge these les into one single PDF within seconds.
1.2k Views

Related Questions

What is the best way to learn HTML CSS on MacBook?

How can I include a CSS file into a HTML?

Is it possible to convert a Kindle book to PDF format?

I know PHP, HTML, and CSS. What is the best way to bring it all together?

What is the best way to put content into HTML file?

I want to convert a PDF file to VCE file. what is the best way to do this?

What is the best way to convert HTML to a PDF on a web server (Java)?

Where can I find software to convert PDF to HTML5?

In what ways can I change a TIF file to a PDF file?

What is the best way of applying CSS in a HTML tree?

How do I convert a HTML doc and CSS to PDF using JS?

Which is the best way to unlock a PDF file?

What is the best way to send a PDF file using a tablet?

Which is the best way to convert from PDF to Flipbook?

How do I extract bold text from HTML or PDF file?

https://www.quora.com/What-is-the-best-way-to-generate-a-PDF-file-from-HTML-and-CSS 4/5
2/23/2017 What is the best way to generate a PDF file from HTML and CSS? - Quora

Top Stories

Sitemap # A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
About - Careers - Privacy - Terms - Contact

https://www.quora.com/What-is-the-best-way-to-generate-a-PDF-file-from-HTML-and-CSS 5/5

Das könnte Ihnen auch gefallen