Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

PDF to HTML5 conversion – image manipulation

47 sec read

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?

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Leave a Reply

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

IDRsolutions Ltd 2019. All rights reserved.