By default, a we convert a PDF file into an HTML file with the same size. So a 200×100 pixel PDF file becomes a 200×100 pixel HTML file. You can easily scale in/out on most mobile devices but sometimes it is just too big or small as a sensible default.
So we have added a scaling setting into the latest release (so that you can have 400×200 pixels or 50×25 pixels). Note that the scaling has to be the same on both sized (if you turn a 200×100 pixel image into a 150x150pixel image, it will becomes ‘squashed’. It is important to maintain the aspect ratio and treat both sides the same.
Sometimes, however, we might want to scale the image up so that it makes the best fit into a different sized hole in our case, we would need to scale the image to 150x75pixels. This is very easy to do. All we need to do is calculate the scaling needed for height and width to fit the maximum gap and choose the smaller of the two values. Here is the sample code (which is also in our updated example). Happy scaling!
DynamicVectorRenderer HTMLoutput=new HTMLDisplay(page, midPoint, cropBox ,false, 100, new ObjectStore()); //have a scaling factor so we can alter the page size float scaling=1.0f; /** * if you want to fit it to a certain size, use this code * work out max possible scaling for both width and height * and use smaller to get max possible size but retain aspect ratio * - will not always be exact match as preserves aspect ratio **/float preferredWidth=1000,preferredHeight=1000; // scaling we need to scale w up to our value float scalingX=preferredWidth/cropW; // scaling we need to scale w up to our value float scalingY=preferredHeight/cropH; if(scalingX>scalingY) scaling=scalingY; else scaling=scalingX; //set page scaling (default is 100%) HTMLoutput.setValue(HTMLDisplay.PercentageScaling, (int) (scaling*100));
Click here to see all the articles in the PDF to HTML5 conversion series.
Latest posts by Mark Stephens (see all)
- 3 ways that the European Union is changing the way Companies write software in 2018 - January 31, 2018
- IDRsolutions product range update for 2018 - January 22, 2018
- 4 ways Companies can make remote working successful - December 21, 2017
- My experience of a Turkish bath (visiting Istanbul for DevFest) - November 24, 2017
- My 5 key takeaways from JavaOne 2017 - October 6, 2017