The issue is that a PDJpeg can not be created while a ContentStream is being operated on.
Thank you Daniel, Andreas, and the entire PDFBox team. The fix is: PDDocument pdDocument = new PDDocument(); // loop BufferedImage image = myObject.toBufferedImage(); // returns the bf from above PDPage pdPage = new PDPage(new PDRectangle(image.getWidth() + border * 2, image.getHeight() + border * 2)); pdPage.setRotation(myObject.getRotation()); // getRotation() is an int and a multiple of 90 PDJpeg pdJpeg = new PDJpeg(pdDocument,image); contentStream = new PDPageContentStream(pdDocument,pdPage,false,false); contentStream.drawImage(pdJpeg,border,border); pdDocument.addPage(pdPage); // end loop pdDocument.save(outputStream = new FileOutputStream(file)); -- Grant Overby Senior Developer FloorSoft, Inc. Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something." They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves. -- Yukihiro Matsumoto ---------- Forwarded message ---------- From: Daniel Wilson <[email protected]> Date: Fri, Oct 1, 2010 at 3:54 PM Subject: Re: insufficient data for an image To: [email protected], [email protected] As begun at http://www.experts-exchange.com/Programming/Languages/Java/Q_26515004.html... Can you create an issue in JIRA with this *and include* both the image you're using and the PDF you're getting? Thanks. Daniel On Fri, Oct 1, 2010 at 2:29 PM, Grant Overby <[email protected]> wrote: > When I open a pdf generated with pdfbox with adobe, I get the following > error: insufficient data for an image . > > I'm using this code (stripped down version) to create the pdf. > > PDDocument pdDocument = new PDDocument(); > BufferedImage image = myObject.toBufferedImage(); > PDPage pdPage = new PDPage(new PDRectangle(image.getWidth() + border * 2, > image.getHeight() + border * 2)); > pdPage.setRotation(myObject.getRotation()); > contentStream = new PDPageContentStream(pdDocument,pdPage,false,false); > contentStream.drawImage(new PDJpeg(pdDocument,image),border,border); > pdDocument.addPage(pdPage); > pdDocument.save(outputStream = new FileOutputStream(file)); > > > Any ideas about what I'm doing wrong? > > -- > Grant Overby > Senior Developer > FloorSoft, Inc. > > Often people, especially computer engineers, focus on the machines. They > think, "By doing this, the machine will run faster. By doing this, the > machine will run more effectively. By doing this, the machine will > something > something something." They are focusing on machines. But in fact we need to > focus on humans, on how humans care about doing programming or operating > the > application of the machines. We are the masters. They are the slaves. -- > Yukihiro Matsumoto >

