This Java sample below shows how to use Qoppa’s jPDFImages (or jPDFProcess) to load a PDF and export it to an image in PNG format with overprint simulation on. First, the image is rendered in CMYK profile, then converted to RGB using ColorConvertOp and finally saved as PNG (or JPEG). The resolution is set at 200 DPI.
// Load the document PDFImages pdfDoc = new PDFImages ("C:\\test\\myDoc.pdf", null); // Turn off Java anti-aliasing needed when doing overprint simulation PDFRenderHints.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); // Loop through pages for (int count = 0; count < pdfDoc.getPageCount(); ++count) { // Get an image of the page in the expected resolution in the CMYK color space with overprint simulation ICC_Profile cmykprofile = ICC_Profile.getInstance("./CMYK Profiles/USWebCoatedSWOP.icc"); ICC_ColorSpace cmykColorSpace = new ICC_ColorSpace(cmykprofile); BufferedImage pageImage = pdfDoc.getPageImageCS(count, 200, new ICC_ColorSpace(cmykprofile), true); // Convert image from CMYK to RGB BufferedImage bi = new BufferedImage (pageImage.getWidth(), pageImage.getHeight(), BufferedImage.TYPE_INT_RGB); ColorConvertOp colorOp = new ColorConvertOp (cmykColorSpace, ColorSpace.getInstance(ColorSpace.CS_sRGB), null); colorOp.filter(pageImage, bi); // Save the image as a PNG File outputFile = new File ("C:/test/output_" + count + ".png"); ImageIO.write(bi, "PNG", outputFile); System.out.println("Outptut File "+ count + " " + outputFile.getAbsolutePath()); } // Turn Java anti-aliasing back on PDFRenderHints.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |