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

Tilman Hausherr commented on PDFBOX-2654:
-----------------------------------------

I'm handling this as if this was an ARGB image. In PDF, the RGB part is 
separated from the alpha part. The only difference with your GIF, is that the 
alpha part is created like a newbie would do as there is no alpha raster, 
because the image isn't an ARGB image, but the highest byte of getRGB still 
delivers al alpha value (0 or 255). And no, I didn't create a background. If 
you download the source code with svn, you'll find a test where two transparent 
GIF images are superimposed on each other.

(Sorry for the late response, either I didn't get the JIRA mail or I missed it. 
)

> NullPointerException when reading a GIF file with a transparent color
> ---------------------------------------------------------------------
>
>                 Key: PDFBOX-2654
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2654
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.8.8, 1.8.9, 2.0.0
>         Environment: JDK 1.8.0_25 Running on Mac OsX 10.10.2
>            Reporter: Shiva Sathiraju
>            Assignee: Tilman Hausherr
>             Fix For: 1.8.9, 2.0.0
>
>         Attachments: PDFBOX-2654-target.pdf, report.pdf, test1.gif
>
>
> NullPointerException while reading a gif file before writing it to a pdf 
> file. I am able to write jpg's successfully to the pdf. The code snippet that 
> I use to write to a pdf. Can you please help ?
> {code}
> public void generatePDF() throws 
> IOException,COSVisitorException,FileNotFoundException
>       {
>               PDDocument report_pdf = new PDDocument();
>               PDPage pdfpage1 = new PDPage(PDPage.PAGE_SIZE_LETTER);
>               PDRectangle text_dimensions = pdfpage1.getMediaBox();
>               PDXObjectImage pdfImage = null;
>               PDPageContentStream stream = new 
> PDPageContentStream(report_pdf, pdfpage1);
>               stream.setFont(PDType1Font.HELVETICA, 30);
>               stream.beginText();
>               
> stream.moveTextPositionByAmount(130,text_dimensions.getHeight()-50);
>               stream.drawString("Hello");
>               stream.endText();
>               BufferedImage awtImage = ImageIO.read(new 
> File("/var/tmp/test1.gif"));
>                //pdfImage = new PDJpeg(report_pdf,awtImage);
>               pdfImage = new PDPixelMap(report_pdf, awtImage);
>               stream.drawImage(pdfImage, 60, 120 );
>         //stream.drawXObject(pdfImage, 150, 400, pdfImage.getWidth()*10, 
> pdfImage.getHeight()*20);
>               stream.close();
>               report_pdf.addPage(pdfpage1);
>               report_pdf.save(new File("/var/tmp/report.pdf"));
>       }
> {code}
> Throws an error 
> {code}
> Exception in thread "main" java.lang.NullPointerException
>       at 
> org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage.extractAlphaImage(PDXObjectImage.java:499)
>       at 
> org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.createImageStream(PDPixelMap.java:122)
>       at 
> org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.<init>(PDPixelMap.java:86)
>       at 
> org.reports.ReportGenerator.ReportGenerator.generatePDF(ReportGenerator.java:122)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to