PDF to HTML5 conversion – image manipulation

By default when we convert a PDF to HTML5 page, we down-sample the images to reduce the size. This setting does not suit everyone – some people want them smaller while others want then larger or want to do their own image down-sampling. So we we have added a custom interface so that you can alter the images yourself. If an instance of this is setup, we will leave the image control to you. Here is how it works…

You can create an instance of our interface and pass it into our PDF2HTML convertor. At the moment it only has 1 method (we may add more to gives users even more functionality).

/**
 * allow user to control image
 */OutputImageController imageController=new SampleHTMLImageController();
HTMLoutput.writeCustom(HTMLDisplay.IMAGE_CONTROLLER,imageController);

The actual interface is very simple. It takes the image and the GraphicsState (which tells you how big the final image will be) and you return the image. Our sample here just returns the exact image (so it will not be scaled down). You could do anything you need here (add a watermark, down-sample with bicubic algorithm, convert it to grayscale, etc).

/**
 * example code for image handler
 */private class SampleHTMLImageController 
       implements OutputImageController {
    public BufferedImage processImage(BufferedImage image, 
                          GraphicsState gs, String name) {

        return image; //just return full image in example
    }
}

What would you use it for?

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

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>