Class HTMLToPDFJob


  • public class HTMLToPDFJob
    extends PDFServicesJob
    A job that converts a HTML file to a PDF file. Some source formats may have associated conversion parameters which can be set in the setParams(HTMLToPDFParams) method.

    An HTML input can be provided either as a local zip archive or as a static HTML file with inline CSS. Alternatively, an HTML can also be specified via URL.
    While creating the corresponding Asset instance, the media type must be:

    • "application/zip", if the input is a local zip archive.
    • "text/html", if the input is a static HTML file with inline CSS

    In case the input is a local zip archive, it must have the following structure:
    • The main HTML file must be named "index.html".
    • "index.html" must exist at the top level of zip archive, not in a folder.

    Sample layout:

     html_files.zip
     |__index.html
     |__referenced_file_1.css
     |__referenced_file_2.jpeg
     |__subfolder_1
     |_____referenced_file_3.jpeg
     

    Sample Usage:

    
                 InputStream inputStream = new FileInputStream(new File("SOURCE_PATH"));
    
                 Credentials credentials = new ServicePrincipalCredentials(
                         System.getenv("PDF_SERVICES_CLIENT_ID"),
                         System.getenv("PDF_SERVICES_CLIENT_SECRET"));
    
                 PDFServices pdfServices = new PDFServices(credentials);
    
                 HTMLToPDFJob htmLtoPDFJob = new HTMLToPDFJob("URL");
    
                 String location = pdfServices.submit(htmLtoPDFJob);
                 PDFServicesResponse<HTMLtoPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, HTMLtoPDFResult.class);
    
                 Asset resultAsset = pdfServicesResponse.getResult().getAsset();
                 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
     
    • Constructor Detail

      • HTMLToPDFJob

        public HTMLToPDFJob​(Asset asset)
        Constructs a new HTMLToPDFJob instance.
        Parameters:
        asset - Asset object containing the input file; can not be null.
      • HTMLToPDFJob

        public HTMLToPDFJob​(String inputURL)
        Constructs a new HTMLToPDFJob instance.
        Parameters:
        inputURL - string representing the input URL; can not be null.
    • Method Detail

      • setParams

        public HTMLToPDFJob setParams​(HTMLToPDFParams htmLtoPDFParams)
        Sets the HTML to PDF conversion parameters.
        Parameters:
        htmLtoPDFParams - HTMLToPDFParams; can not be null.
        Returns:
        HTMLToPDFJob instance
      • setOutput

        public HTMLToPDFJob setOutput​(Asset asset)
        Sets the output asset for the job. @note External assets can be set as output only when input is external asset as well
        Parameters:
        asset - Asset object representing the output asset; can not be null.
        Returns:
        HTMLToPDFJob instance