Class HtmlConverter

java.lang.Object
com.itextpdf.html2pdf.HtmlConverter

public class HtmlConverter extends Object
The HtmlConverter is the class you will use most when converting HTML to PDF. It contains a series of static methods that accept HTML as a String, File, or InputStream, and convert it to PDF in the form of an OutputStream, File, or a series of iText elements. It's also possible to write to a PdfWriter or PdfDocument instance.
  • Method Details

    • convertToPdf

      public static void convertToPdf (String html, OutputStream pdfStream)
      Converts a String containing HTML to an OutputStream containing PDF.
      Parameters:
      html - the html in the form of a String
      pdfStream - the PDF as an OutputStream
    • convertToPdf

      public static void convertToPdf (String html, OutputStream pdfStream, ConverterProperties converterProperties)
      Converts a String containing HTML to an OutputStream containing PDF, using specific ConverterProperties.
      Parameters:
      html - the html in the form of a String
      pdfStream - the PDF as an OutputStream
      converterProperties - a ConverterProperties instance
    • convertToPdf

      public static void convertToPdf (String html, com.itextpdf.kernel.pdf.PdfWriter pdfWriter)
      Converts a String containing HTML to PDF by writing PDF content to a PdfWriter instance.
      Parameters:
      html - the html in the form of a String
      pdfWriter - the PdfWriter instance
    • convertToPdf

      public static void convertToPdf (String html, com.itextpdf.kernel.pdf.PdfWriter pdfWriter, ConverterProperties converterProperties)
      Converts a String containing HTML to PDF by writing PDF content to a PdfWriter instance, using specific ConverterProperties.
      Parameters:
      html - the html in the form of a String
      pdfWriter - the PdfWriter instance
      converterProperties - a ConverterProperties instance
    • convertToPdf

      public static void convertToPdf (String html, com.itextpdf.kernel.pdf.PdfDocument pdfDocument, ConverterProperties converterProperties)
      Converts a String containing HTML to objects that will be added to a PdfDocument, using specific ConverterProperties.
      Parameters:
      html - the html in the form of a String
      pdfDocument - the PdfDocument instance
      converterProperties - a ConverterProperties instance
    • convertToPdf

      public static void convertToPdf (File htmlFile, File pdfFile) throws IOException
      Converts HTML stored in a File to a PDF File.
      Parameters:
      htmlFile - the File containing the source HTML
      pdfFile - the File containing the resulting PDF
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToPdf

      public static void convertToPdf (File htmlFile, File pdfFile, ConverterProperties converterProperties) throws IOException
      Converts HTML stored in a File to a PDF File, using specific ConverterProperties.
      Parameters:
      htmlFile - the File containing the source HTML
      pdfFile - the File containing the resulting PDF
      converterProperties - a ConverterProperties instance
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToPdf

      public static void convertToPdf (InputStream htmlStream, OutputStream pdfStream) throws IOException
      Converts HTML obtained from an InputStream to a PDF written to an OutputStream.
      Parameters:
      htmlStream - the InputStream with the source HTML
      pdfStream - the OutputStream for the resulting PDF
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToPdf

      public static void convertToPdf (InputStream htmlStream, OutputStream pdfStream, ConverterProperties converterProperties) throws IOException
      Converts HTML obtained from an InputStream to a PDF written to an OutputStream.
      Parameters:
      htmlStream - the InputStream with the source HTML
      pdfStream - the OutputStream for the resulting PDF
      converterProperties - a ConverterProperties instance
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToPdf

      public static void convertToPdf (InputStream htmlStream, com.itextpdf.kernel.pdf.PdfDocument pdfDocument) throws IOException
      Converts HTML obtained from an InputStream to objects that will be added to a PdfDocument.
      Parameters:
      htmlStream - the InputStream with the source HTML
      pdfDocument - the PdfDocument instance
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToPdf

      public static void convertToPdf (InputStream htmlStream, com.itextpdf.kernel.pdf.PdfWriter pdfWriter) throws IOException
      Converts HTML obtained from an InputStream to content that will be written to a PdfWriter.
      Parameters:
      htmlStream - the InputStream with the source HTML
      pdfWriter - the PdfWriter containing the resulting PDF
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToPdf

      public static void convertToPdf (InputStream htmlStream, com.itextpdf.kernel.pdf.PdfWriter pdfWriter, ConverterProperties converterProperties) throws IOException
      Converts HTML obtained from an InputStream to content that will be written to a PdfWriter, using specific ConverterProperties.
      Parameters:
      htmlStream - the InputStream with the source HTML
      pdfWriter - the PdfWriter containing the resulting PDF
      converterProperties - a ConverterProperties instance
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToPdf

      public static void convertToPdf (InputStream htmlStream, com.itextpdf.kernel.pdf.PdfDocument pdfDocument, ConverterProperties converterProperties) throws IOException
      Converts HTML obtained from an InputStream to objects that will be added to a PdfDocument, using specific ConverterProperties.
      Parameters:
      htmlStream - the InputStream with the source HTML
      pdfDocument - the PdfDocument instance
      converterProperties - a ConverterProperties instance
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToDocument

      public static com.itextpdf.layout.Document convertToDocument (String html, com.itextpdf.kernel.pdf.PdfWriter pdfWriter)
      Converts a String containing HTML to content that will be written to a PdfWriter, returning a Document instance.
      Parameters:
      html - the html in the form of a String
      pdfWriter - the PdfWriter containing the resulting PDF
      Returns:
      a Document instance
    • convertToDocument

      public static com.itextpdf.layout.Document convertToDocument (InputStream htmlStream, com.itextpdf.kernel.pdf.PdfWriter pdfWriter) throws IOException
      Converts HTML obtained from an InputStream to content that will be written to a PdfWriter, returning a Document instance.
      Parameters:
      htmlStream - the InputStream with the source HTML
      pdfWriter - the PdfWriter containing the resulting PDF
      Returns:
      a Document instance
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToDocument

      public static com.itextpdf.layout.Document convertToDocument (String html, com.itextpdf.kernel.pdf.PdfWriter pdfWriter, ConverterProperties converterProperties)
      Converts a String containing HTML to content that will be written to a PdfWriter, using specific ConverterProperties, returning a Document instance.
      Parameters:
      html - the html in the form of a String
      pdfWriter - the pdf writer
      converterProperties - a ConverterProperties instance
      Returns:
      a Document instance
    • convertToDocument

      public static com.itextpdf.layout.Document convertToDocument (InputStream htmlStream, com.itextpdf.kernel.pdf.PdfWriter pdfWriter, ConverterProperties converterProperties) throws IOException
      Converts HTML obtained from an InputStream to content that will be written to a PdfWriter, using specific ConverterProperties, returning a Document instance.
      Parameters:
      htmlStream - the html stream
      pdfWriter - the pdf writer
      converterProperties - a ConverterProperties instance
      Returns:
      a Document instance
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToDocument

      public static com.itextpdf.layout.Document convertToDocument (String html, com.itextpdf.kernel.pdf.PdfDocument pdfDocument, ConverterProperties converterProperties)
      Converts a String containing HTML to objects that will be added to a PdfDocument, using specific ConverterProperties, returning a Document instance.
      Parameters:
      html - the html in the form of a String
      pdfDocument - the PdfDocument instance
      converterProperties - a ConverterProperties instance
      Returns:
      a Document instance
    • convertToDocument

      public static com.itextpdf.layout.Document convertToDocument (InputStream htmlStream, com.itextpdf.kernel.pdf.PdfDocument pdfDocument, ConverterProperties converterProperties) throws IOException
      Converts HTML obtained from an InputStream to objects that will be added to a PdfDocument, using specific ConverterProperties, returning a Document instance.
      Parameters:
      htmlStream - the InputStream with the source HTML
      pdfDocument - the PdfDocument instance
      converterProperties - a ConverterProperties instance
      Returns:
      a Document instance
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToElements

      public static List convertToElements (String html)
      Converts a String containing HTML to a List of iText objects (IElement instances).
      Parameters:
      html - the html in the form of a String
      Returns:
      a list of iText building blocks
    • convertToElements

      public static List convertToElements (InputStream htmlStream) throws IOException
      Converts HTML obtained from an InputStream to a List of iText objects (IElement instances).
      Parameters:
      htmlStream - the InputStream with the source HTML
      Returns:
      a list of iText building blocks
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • convertToElements

      public static List convertToElements (String html, ConverterProperties converterProperties)
      Converts a String containing HTML to a List of iText objects (IElement instances), using specific ConverterProperties.
      Parameters:
      html - the html in the form of a String
      converterProperties - a ConverterProperties instance
      Returns:
      a list of iText building blocks
    • convertToElements

      public static List convertToElements (InputStream htmlStream, ConverterProperties converterProperties) throws IOException
      Converts HTML obtained from an InputStream to a List of iText objects (IElement instances), using specific ConverterProperties.
      Parameters:
      htmlStream - the InputStream with the source HTML
      converterProperties - a ConverterProperties instance
      Returns:
      a list of iText building blocks
      Throws:
      IOException - Signals that an I/O exception has occurred.