1

I am trying to create a pdf file from database and I am stuck at the image part, since Apache pdf box only accepts physical files and the images in my database are in blob format.

PDXObjectImage image = new PDJpeg(doc,rs.getBlob("image"));

Can anyone help me?

1
  • I would recommend storing the images on disk and instead store metadata about the images in the database (i.e. location/name etc) unless you really have to store them directly. See this thread, really puts light on the discussion stackoverflow.com/questions/3748/… Commented Dec 30, 2015 at 11:25

1 Answer 1

1

Convert your blob into an InputStream and pass this to PDJpeg:

Blob imageBlob = rs.getBlob("image");
try (InputStream imageInputStream = imageBlob.getBinaryStream()) {
    PDXObjectImage image = new PDJpeg(doc, imageInputStream);
}
Sign up to request clarification or add additional context in comments.

1 Comment

I am probably nit picking, but I would close that imageInputStream with a try with resources :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.