You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Maruan Sahyoun (JIRA)" <ji...@apache.org> on 2013/05/17 08:29:15 UTC

[jira] [Commented] (PDFBOX-1601) java.lang.IllegalArgumentException: Width (4032) and height (-2880) cannot be <= 0

    [ https://issues.apache.org/jira/browse/PDFBOX-1601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13660394#comment-13660394 ] 

Maruan Sahyoun commented on PDFBOX-1601:
----------------------------------------

Analysis:

For the dimensions of the to be created image the pages CropBox is used. As the pdf doesn't define a CropBox the values are taken from the MediaBox. In case of the test document provided (failingtoload.pdf) the PDRectangle is [0.0,2160.0,3024.0,0.0].

According to the PDF spec 7.9.5:

Although rectangles are conventionally specified by their lower-left and upper-right corners, it is acceptable to specify any two diagonally opposite corners. Applications that process PDF should be prepared to normalize such rectangles in situations where specific corners are required.


PDRectangle getWidth()/getHeight() always expect the upper value to be higher than the lower value which is not true in this case and not in line with the spec thus returning a negative value for height in this case.
                
> java.lang.IllegalArgumentException: Width (4032) and height (-2880) cannot be <= 0
> ----------------------------------------------------------------------------------
>
>                 Key: PDFBOX-1601
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1601
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.8.1
>         Environment: Centos 6
>            Reporter: Asmita Joshi
>         Attachments: failingtoload.pdf
>
>
> We're using pdfbox-1.8.1.jar to convert PDF to JPGs.
> Below is part of a stacktrace we see when converting a PDF of size 500Kb
> java.lang.IllegalArgumentException: Width (4032) and height (-2880) cannot be <= 0
>         at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
>         at java.awt.image.BufferedImage.<init>(Unknown Source)
>         at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:752)
>         at org.apache.pdfbox.util.PDFImageWriter.writeImage(PDFImageWriter.java:115)
> We use PDDocument.load(File). As suggested, we tried with loadNonSeq and also the non sequential form of load as below. Also tried it with a FileInputStream and File. All these forms of load gave us the same error.
> ---
>           raf = new RandomAccessFile(new File("/tmp/nonSeqPdfFile"), "rw");
>           document = PDDocument.load(new FileInputStream(inputFile), raf);
>             PDFImageWriter imageWriter = new PDFImageWriter();
>             success = imageWriter.writeImage(document, imageFormat, password, startPage, endPage, pdfWorkFilePrefix, imageType, resolution);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira