The New JPDF2HTML5 API

If you use JPDF2HTML5, hopefully we have made you aware by now that there were some upcoming changes. We’re pleased to announce that those changes are now available by default in our daily builds.

We won’t go into detail about what has changed as we have already explained that in the previous article. Instead, the aim of this article is to tell you how to API has changed.

Here’s how our code example used to look:

    HTMLConversionOptions options = new HTMLConversionOptions();
 
    options.setDisableComments(true);
    options.setViewMode(HTMLConversionOptions.ViewMode.SINGLEFILE);
 
    File pdfFile = new File("C:/MyDocument.pdf");
    File outputDir = new File("C:/MyOutputDirectory/");
 
    //Multiple constructors allow PDF as File or byte[] in first parameter - see Javadoc
    PDFtoHTML5Converter converter = new PDFtoHTML5Converter(pdfFile, outputDir, options);
 
    try {
        converter.convert();
    } catch (PdfException e) {
        e.printStackTrace();
    }

And here’s how it now looks:

    HTMLConversionOptions conversionOptions = new HTMLConversionOptions();//Set conversion options here           
    conversionOptions.setDisableComments(true);                                                                   
 
    IDRViewerOptions viewerOptions = new IDRViewerOptions();//Set viewer options here                             
 
    File pdfFile = new File("C:/MyDocument.pdf");                                                                 
    File outputDir = new File("C:/MyOutputDirectory/");                                                           
 
    //Alternative constructor exists for converting from byte array                                               
    PDFtoHTML5Converter converter = new PDFtoHTML5Converter(pdfFile, outputDir, conversionOptions, viewerOptions);
 
    try {                                                                                                         
        converter.convert();                                                                                      
    } catch (PdfException e) {                                                                                    
        e.printStackTrace();                                                                                      
    }

As you can see, the important difference is that the PDFtoHTML5Converter constructor now requires an additional parameter of type OutputModeOptions.

There are two classes that extend OutputModeOptions: IDRViewerOptions and ContentOptions. This controls whether the converted file includes our HTML5 viewer or not.

What is the difference between HTMLConversionOptions and OutputModeOptions?

HTMLConversionOptions is the object on which you set options that are applicable for all view modes. For example that includes settings such as the page range, how text should appear, whether content should be inlined or stored as separate files, etc.

OutputModeOptions is the object on which you set options that are specific to the view mode you are using. For example if you are using ContentOptions you can control whether to output thumbnails or disable the properties.json file. If you are using IDRViewerOptions, you can control view mode the viewer should default to, whether the viewer should allow downloading of the PDF file, etc.

The benefit of this separation is that you no longer see options which are not applicable to the mode you are using.

To learn more, I highly recommend reading the Javadocs, in particular PDFtoHTML5Converter now has more detailed code examples that show the new API.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the Blog RSS.

Related Posts:

The following two tabs change content below.
Leon is a developer at IDRsolutions and product manager for JPDF2HTML5. He is responsible for managing the JPDF2HTML5 product strategy and roadmap, and also spends a lot of his time writing code to build new features, improve functionality, fix bugs, and improve the testing for JPDF2HTML5.
Leon Atherton

About Leon Atherton

Leon is a developer at IDRsolutions and product manager for JPDF2HTML5. He is responsible for managing the JPDF2HTML5 product strategy and roadmap, and also spends a lot of his time writing code to build new features, improve functionality, fix bugs, and improve the testing for JPDF2HTML5.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>