Leanpub Header

Skip to main content

Create PDF from HTML with pdfHTML

Generate PDF documents using HTML and CSS as template format

Use HTML and CSS to create templates for your PDF files. In this book, we'll learn how to use the iText 7 add-on pdfHTML.

IMPORTANT: vouchers to get a free copy of this book will be available on the iText web site soon!

Minimum price

$7.99

$7.99

You pay

$7.99

Author earns

$6.39
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
1,233
Readers
130
Pages
25,227Words
About

About

About the Book

IMPORTANT: vouchers to get a free copy of this book will be available on the iText web site soon!

This is a step by step guide on how to use the iText 7 add-on pdfHTML.

This tutorial consists of 7 chapters:

  • Chapter 1: Hello HTML to PDF: consists of a series "Hello World" examples that explain the different approaches to convert HTML to PDF with the pdfHTML add-on,
  • Chapter 2: Defining Styles with CSS: explains the different approaches to use CSS to define styles for HTML... and PDF,
  • Chapter 3: Generating PDF based on Media Queries: demonstrates how a single HTML file can result in different PDF documents depending on Media Queries,
  • Chapter 4: Creating reports using pdfHTML: shows how data can be rendered to PDF using HTML and CSS to define the layout, and shares some best practices for creation industry-grade, future-proof reports, invoices, catalogues,... involving standards such as PDF/A and PDF/UA.
  • Chapter 5: Custom tag workers and CSS appliers: reveals how you can change the inner workings of pdfHTML and how to adapt the way HTML tags and CSS styles to your own needs,
  • Chapter 6: Using fonts in pdfHTML: talks about fonts, fonts, and fonts, listing the different types of fonts that are supported, how to select fonts, how to use a different encoding, and how to create international documents (with content in Russian, Greek, Hebrew, Arabic, and many other languages),
  • Chapter 7: Frequently Asked Questions about pdfHTML: reuses a dozen of questions that were posted in the past about XML Worker, for which we now provide an answer using iText 7 and pdfHTML.

Share this book

Author

About the Author

iText Software

iText is one of the fastest growing technology companies in the digital document space. The company’s flagship product is an open source software library to create and manipulate PDF documents in Java and .NET (C#). There are currently millions of iText users, both open source (AGPL) and commercial. iText’s customers (software developers, technology vendors, software integrators) span the fields of technology, financial, public, government and health care sectors including many of the Fortune 500 companies. iText has dedicated international teams with offices in Belgium (Ghent), South Korea (Seoul), Singapore and in the USA (Boston). 

Contents

Table of Contents

Introduction

Chapter 1: Hello HTML to PDF

  1. Structure of the examples
  2. Converting HTML to PDF
  3. Converting HTML to iText objects
  4. Summary

Chapter 2: Defining styles with CSS

  1. Old-fashioned HTML
  2. Inline CSS
  3. What’s the difference between id and class?
  4. Internal CSS
  5. External CSS
  6. When CSS is defined in different places, which CSS takes precedence?
  7. Using absolute positioning
  8. Adding “Page X of Y” using an @page rule
  9. Adding page breaks
  10. Summary

Chapter 3: Generating PDF based on Media Queries

  1. Examining the example HTML file
  2. Creating a PDF file for Print
  3. Responsiveness in HTML
  4. Creating a PDF for the desktop
  5. What is the relationship between pt and px?
  6. Creating a PDF for a tablet
  7. Creating a PDF for a smartphone
  8. The semantic structure of a document
  9. Summary

Chapter 4: Creating reports using pdfHTML

  1. Description of a use case
  2. Converting XML to HTML using XSLT
  3. Adding a background and a custom header or footer
  4. Converting an HTML page to a single-page PDF
  5. Adding bookmarks to a report
  6. Creating PDF/A documents with pdfHTML
  7. Summary

Chapter 5: Custom tag workers and CSS appliers

  1. Changing the behavior of a tag
  2. Introducing custom tags
  3. Creating your own ITagWorker implementation
  4. Creating custom CSS appliers
  5. Implementing your own custom CSS
  6. Summary

Chapter 6: Using fonts in pdfHTML

  1. Standard Type 1 fonts
  2. Fonts shipped with iText
  3. System fonts
  4. Web Open Font Format fonts
  5. Adding selected fonts to the font provider
  6. Choosing the right order for your font selection
  7. Choosing the encoding that is right for you
  8. Internationalization
  9. Summary

Chapter 7: Frequently Asked Questions about pdfHTML

  1. How to convert an ASP or JSP page to PDF?
  2. How to parse multiple HTML files into one PDF?
  3. Can pdfHTML render Base64 images to PDF?
  4. Can I generate a PDF from a URL instead of from a file on disk?
  5. Do we need a browser engine to render HTML+CSS to PDF
  6. Does my HTML have to be valid XML?
  7. How to add metadata to a PDF using pdfHTML?
  8. How do the measurement systems in HTML relate to the measurement system in PDF?
  9. Can I convert an HTML form to a PDF?
  10. How to render certain HTML entities (such as arrows) to PDF?
  11. Why can’t I embed a font due to licensing restrictions?
  12. Which languages are supported in pdfHTML?
  13. How to convert HTML containing Arabic/Hebrew characters to PDF?
  14. Why is my PDF missing several characters?

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub