HTML to PDF in Java
HTML to PDF conversion can be done using the DynamicPDF Generator product.
How to Convert HTML to PDF
The HtmlLayout class can be used to convert HTML to PDF using Generator with several custom options for page info, header and footer for the output PDF.
Steps for Creating a PDF Document using Generator
- Create
PageInfowith required page options. - Create a
URIobject to point to the HTML file. - Create a
HtmlLayoutobject by specifying the URI and PageInfo. - Create a
HeaderandFooteras required to the HtmlLayout object. - Convert the URI to Document by calling
Layoutmethod and save the Document.
Sample code - C#
PageInfo layoutPage = new PageInfo(PageSize.A4, PageOrientation.Portrait);
Uri uri = new Uri(@"http://www.google.com");
HtmlLayout html = new HtmlLayout(uri, layoutPage);
html.Header.Center.Text = "%%PR%%%%SP%% of %%ST%%";
html.Header.Center.HasPageNumbers = true;
html.Header.Center.Width = 200;
html.Footer.Center.Text = "%%PR%%%%SP(A)%% of %%ST(B)%%";
html.Footer.Center.HasPageNumbers = true;
html.Footer.Center.Width = 200;
Document document = html.Layout();
document.Draw(@"Output.pdf");
Getting Started
DynamicPDF Generator Information
More information can be found here:
Available in other platforms
DynamicPDF Generator is available for the following platforms. Refer to the respective product pages for more details.
- .NET - DynamicPDF Generator for .NET
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX