You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Andreas Lehmkühler <an...@lehmi.de> on 2013/09/04 12:24:16 UTC

Re: Image problems with PNG

Hi,

> Clifford Dann <cl...@paprika-software.com> hat am 27. August 2013 um 15:06
> geschrieben:
>
>
> When adding a image to a PDF document using
> org.apache.pdfbox.pdmodel.edit.PDPageContentStream.drawXObject(PDXObject
> xobject, float x, float y, float width, float height), the image has a
> spotty black line at the top of the image, and this goes over several
> lines of the image, and then 2 thirds of a line.
>
>
> I am using org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap to
> create the PDXObject.
>
> if I do java.awt.image.BufferedImage bi = new
> java.awt.image.BufferedImage(100, 100,
> java.awt.image.BufferedImage.TYPE_INT_RGB);
> and place the image in the PDF using PDPixelMap, I do not get a solid
> black box, I get the same effect, as putting in a normal PNG at the top
> , and then the rest of the image is solid black.
> using .drawXObject(xobject, 0, 0, 100, 100)
>
> The version of PDFBox I am using is 1.8.2, but this happens with earlier
> version.
> and the version of Java is 1.7.0_17-b02 64-Bit, I am running PDFBox in a
> servelet using tomcat, but this should not have an effect.
>
> I am adding to a existing PDF (using it as a template), and also adding
> lots of text lines ect, it also happens if I do not start from a
> template PDF.
Can you provide us with a sample pdf? Please upload it to a share hoster or
something similar as (most) binary attachments are blocked on our mailing list.

Maybe the source code is important as well. Please post the relevant piece of
code which creates the XObject and adds it to the pdf.

BR
Andreas Lehmkühler

Re: Image problems with PNG

Posted by Clifford Dann <cl...@paprika-software.com>.
package pdfpngtest;

import static java.awt.image.BufferedImage.TYPE_INT_RGB;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap;
import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;

/**
  *
  * @author clifford
  */
public class PdfPngTest {

     /**
      * @param args the command line arguments
      */
     public static void main(String[] args) {

         PDDocument    doc;

         try {
             doc = new PDDocument();

             PDPage page = new PDPage();

             doc.addPage(page);

             PDPageContentStream cs = new PDPageContentStream(doc, page, 
false, true);

             java.awt.image.BufferedImage bi = new 
java.awt.image.BufferedImage(10,10,TYPE_INT_RGB);
             PDXObjectImage ximage = new PDPixelMap(doc, bi);
             cs.drawXObject(ximage, 0, 0, 100, 100);

             cs.close();


             java.io.File lvFile = new java.io.File("test.pdf");
             FileOutputStream out = new FileOutputStream(lvFile);
             doc.save(out);

             doc.close();

         } catch (    IOException | COSVisitorException ex) {
Logger.getLogger(PdfPngTest.class.getName()).log(Level.SEVERE, null, ex);
         }


     }
}


On 04/09/2013 11:24, Andreas Lehmkühler wrote:
> Hi,
>
>> Clifford Dann <cl...@paprika-software.com> hat am 27. August 2013 um 15:06
>> geschrieben:
>>
>>
>> When adding a image to a PDF document using
>> org.apache.pdfbox.pdmodel.edit.PDPageContentStream.drawXObject(PDXObject
>> xobject, float x, float y, float width, float height), the image has a
>> spotty black line at the top of the image, and this goes over several
>> lines of the image, and then 2 thirds of a line.
>>
>>
>> I am using org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap to
>> create the PDXObject.
>>
>> if I do java.awt.image.BufferedImage bi = new
>> java.awt.image.BufferedImage(100, 100,
>> java.awt.image.BufferedImage.TYPE_INT_RGB);
>> and place the image in the PDF using PDPixelMap, I do not get a solid
>> black box, I get the same effect, as putting in a normal PNG at the top
>> , and then the rest of the image is solid black.
>> using .drawXObject(xobject, 0, 0, 100, 100)
>>
>> The version of PDFBox I am using is 1.8.2, but this happens with earlier
>> version.
>> and the version of Java is 1.7.0_17-b02 64-Bit, I am running PDFBox in a
>> servelet using tomcat, but this should not have an effect.
>>
>> I am adding to a existing PDF (using it as a template), and also adding
>> lots of text lines ect, it also happens if I do not start from a
>> template PDF.
> Can you provide us with a sample pdf? Please upload it to a share hoster or
> something similar as (most) binary attachments are blocked on our mailing list.
>
> Maybe the source code is important as well. Please post the relevant piece of
> code which creates the XObject and adds it to the pdf.
>
> BR
> Andreas Lehmkühler

-- 
Agency Software Worldwide Ltd
Latters House, High Street
Hadlow, Tonbridge
Kent TN11 0EF
United Kingdom

t:+44 (0) 1732 811603
w:www.paprika-software.com <http://www.paprika-software.com>

Registered in England and Wales 1665695
VAT reg 367 5667 05