Convert HTM to PDF in Java

HTM to PDF conversion with a few lines of Java code


Download Free Trial

About GroupDocs.Conversion for Java API

GroupDocs.Conversion for Java is an advanced file format conversion API for converting between popular image and document formats such as Microsoft Office, OpenDocument, PDF, HTML, email, CAD. and much more with just a few lines of code. The native API automatically detects the formats of the original documents and offers many options for customizing the converted documents. Along with the function of extracting information from a document, it also supports caching of the conversion results to the local disk by default. However, any type of cache storage can be supported by implementing the appropriate interfaces - Amazon S3, Dropbox, Google Drive, Windows Azure, Reddis, or any others.

Convert your HTM files to PDF files in Java. It only takes a couple of lines of Java code on any platform of your choice, such as Windows, Linux, macOS. You can try converting HTM to PDF for free and evaluate the quality of the conversion results. Along with simple file conversion scripts, you can try more sophisticated options for loading the HTM source file and storing the PDF output.

For example, for the source file HTM, you can use the following upload options:

  • automatic detection of the file format;
  • specify a password for protected files (if the file format supports it);
  • replace missing fonts to preserve the appearance of the document.

There are also advanced conversion options for the PDF file:

  • convert a specific page of a document or a range of pages;
  • add a watermark to the converted PDF.

Once the conversion is complete, you can save the PDF file to your local file path or to any third party storage such as FTP, Amazon S3, Google Drive, Dropbox etc. Please note - to convert HTM to PDF, you do not need to install any additional software, such as MS Office, Open Office, Adobe Acrobat Reader etc.

Steps to Convert HTM to PDF in Java

GroupDocs.Conversion allows developers to easily convert a HTM file to PDF with a few lines of code.

  • Create a new instance of the Converter class and upload the file HTM with the full path
  • Set ConvertOptions for document type to PDF.
  • Call the convert() method and pass the document name (full path) and format (PDF) as a parameter

System Requirements

Basic conversion using GroupDocs.Conversion for the Java API can be done with just a few lines of code. Our APIs are supported on all major platforms and operating systems. Before executing the code below, make sure you have the following prerequisites installed on your system.

  • Operating systems: Microsoft Windows, Linux, MacOS
  • Development environment: NetBeans, Intellij IDEA, Eclipse, etc.
  • Java runtime: J2SE 6.0 and above
  • Get the latest GroupDocs.Conversion for Java from Maven

// Load source file HTM for conversion
Converter converter = new Converter("input.htm");
// Prepare conversion options for target format PDF
ConvertOptions convertOptions = new FileType().fromExtension("pdf").getConvertOptions();
// Convert to PDF format
converter.convert("output.pdf", convertOptions);

HTM to PDF Live Demo

Convert HTM to PDF now by visiting the GroupDocs.Conversion App website. The free demo has the following benefits

No need to download API

No need to write any code

Just upload the source file

Get download link to save the file

Other supported HTM conversions in Java

You can also convert HTM to many other file formats. Please see the list below.

Convert HTM to BMP

(Bitmap image file)

Convert HTM to DOC

(Microsoft word binary format)

Convert HTM to DOCM

(Microsoft word 2007 marco file)

Convert HTM to DOCX

(Office 2007 word document)

Convert HTM to DOT

(Microsoft word template files)

Convert HTM to DOTM

(Microsoft word 2007 template file)

Convert HTM to DOTX

(Microsoft word template file)

Convert HTM to EPUB

(Open e book file)

Convert HTM to GIF

(Graphical interchange format)

Convert HTM to JPEG

(Joint photographic expert group image)

Convert HTM to MD

(Markdown language)

Convert HTM to ODT

(Open document text file format)

Convert HTM to OTT

(Open document standard format)

Convert HTM to PDF

(Portable document format)

Convert HTM to PNG

(Portable network graphic)

Convert HTM to PSD

(Photoshop document)

Convert HTM to RTF

(Rich text format)

Convert HTM to TEX

(La te x source document)

Convert HTM to TIFF

(Tagged image file format)

Convert HTM to TXT

(Text document)

Convert HTM to XPS

(Xml paper specifications)

Back to top
 English