[
https://issues.apache.org/jira/browse/PDFBOX-1735?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13784952#comment-13784952
]
Tilman Hausherr commented on PDFBOX-1735:
-----------------------------------------
I was able to decode the JPEG2000 image and to render it. The problem is that
the width and height in the PDF are incorrect, that it has no colorspace
http://www.verypdf.com/document/pdf-format-reference/pg_0340.htm
So I took these from the image itself.
change 1:
in PDPixelMap.getRGBImage() add this after "if (array.length == 0)":
{code}
if (COSName.JPX_DECODE.equals(getCOSStream().getItem(COSName.FILTER)))
{
width = getWidth();
height = getHeight();
bpc = getBitsPerComponent();
}
{code}
(The "if" part here is probably not needed and just to make sure that my change
doesn't affect anything else. It is probably enough to just move the three
(same) assignments from above to here, I'll do more tests later.
change 2)
in JPXFilter.java after the ImageIO.read() call, in the "if" branch, add this:
{code}
if (options.getItem(COSName.COLORSPACE) == null)
options.setItem(COSName.COLORSPACE,
PDColorSpaceFactory.createColorSpace(null, bi.getColorModel().getColorSpace()));
options.setInt(COSName.BITS_PER_COMPONENT, bi.getColorModel().getPixelSize() /
bi.getColorModel().getNumComponents());
options.setInt(COSName.BPC, bi.getColorModel().getPixelSize() /
bi.getColorModel().getNumComponents());
options.setInt(COSName.HEIGHT, bi.getHeight());
options.setInt(COSName.WIDTH, bi.getWidth());
{code}
The intent of all this is to pass the info from the image itself to the layers
above.
Next thing I will try to find out why the image is rendered inverted.
Paulo, please add the labels JPEG2000 and JPXDecode to this jira.
> Convert page pdf to image
> -------------------------
>
> Key: PDFBOX-1735
> URL: https://issues.apache.org/jira/browse/PDFBOX-1735
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 1.8.2
> Environment: Windows 8
> JDK 1.7
> Reporter: Paulo R C Mello Junior
> Attachments: N130567_116.pdf
>
>
> I'm in the fight to perfectly convert a PDF to an image.
> But the stacktrace below breaks my application!
> ---
> Out 02, 2013 3:22:35 PM org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap
> getRGBImage
> SEVERE: Something went wrong ... the pixelmap doesn't contain any data.
> Out 02, 2013 3:22:35 PM org.apache.pdfbox.util.operator.pagedrawer.Invoke
> process
> WARNING: getRGBImage returned NULL
> Out 02, 2013 3:22:35 PM org.apache.pdfbox.util.PDFStreamEngine processOperator
> INFO: unsupported/disabled operation: i
> ---
> I really need to fix this problem in order to succeed in converting
> You know why this error occurs?
> You know how I can fix this error?
> is some dependence of my environment that i forgot? or a failure of PDFBox
> framewor ?
> Follow my code below:
> ---
> public static List<BufferedImage> getPdfPagesAsImages(String pdfPath,
> int i)
> throws FileNotFoundException, IOException {
> List<BufferedImage> bImages = new ArrayList<BufferedImage>();
>
> File f = new File(pdfPath);
> if (f.exists()) {
> int resolution = 185;
> PDDocument pdfDocument = null;
> pdfDocument = PDDocument.loadNonSeq(f, null);
> if (pdfDocument != null) {
> @SuppressWarnings("unchecked")
> List<PDPage> pages = (List<PDPage>) pdfDocument
> .getDocumentCatalog().getAllPages();
> int j = 1;
> for (PDPage p : pages) {
> System.out.println(j);
> BufferedImage convertedImage = p.convertToImage(
> BufferedImage.TYPE_INT_BGR ,
> resolution);
> saveImageToRepository(i, j, convertedImage);
>
> j++;
> if (isNegativeImage(convertedImage)) {
>
> bImages.add(invertNegativeImage(convertedImage));
> } else {
> bImages.add(convertedImage);
> }
>
> }
> System.out.println(pdfPath +" sucess");
> }
> pdfDocument.close();
> }else{
> System.out.println(pdfPath +" nao existe");
> }
> return bImages;
> }
> private static void saveImageToRepository(int i, int j,
> BufferedImage convertedImage) throws IOException {
> File outputfile = new File("C:/Desenvolvimento/bkp/convertido/"
> + i + j+ ".png");
> ImageIO.write(convertedImage, "png", outputfile);
> }
> ---
> I create a list of images
> these images are saved to be loaded in the browser later on a JSF component.
> Thank you!
--
This message was sent by Atlassian JIRA
(v6.1#6144)