private static BufferedImage toBufferedImage(Document document, int pageNumber,float scale,boolean transparent) {
System.getProperties().put("org.icepdf.core.screen.background", "VALUE_DRAW_NO_BACKGROUND");
Catalog cat = document.getCatalog();
Page page = cat.getPageTree().getPage(pageNumber-1, document);
PDimension sz = page.getSize(Page.BOUNDARY_CROPBOX, 0f, scale);
int pageWidth = (int) sz.getWidth();
int pageHeight = (int) sz.getHeight();
BufferedImage image = new BufferedImage(pageWidth,
pageHeight,
transparent?BufferedImage.TYPE_INT_ARGB:BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();