Premature EOF while reading jpg using itext

When I try to include some jpeg files in PDF using iText, I get the error message: Premature EOF while reading JPG

Images are downloaded from Android phones, and most of them can be embedded in a pdf file, but some cannot.

PushbuttonField ad = pdfForm.getNewPushbuttonFromField(fieldName); if(ad != null) { ad.setLayout(PushbuttonField.LAYOUT_ICON_ONLY); ad.setProportionalIcon(true); try { ad.setImage(Image.getInstance(basePath + "/" + r.value)); } catch (Exception e) { log.log(Level.SEVERE, "Image error detail", e); } pdfForm.replacePushbuttonField(fieldName, ad.getField()); } 

The error occurs during setImage at the address: com.itextpdf.text.Jpeg.processParameters (Jpeg.java:219) iText version: 5.5.5

I put an image that causes an error in the Dropbox public folder: https://dl.dropboxusercontent.com/u/46349359/image.jpg The image is 1.6 MB and is displayed without problems in html or using other image display tools.

0
source share
1 answer

As Amedi stated, this question was a duplicate. The specific solution that worked for me is this:

  • install imageMagick
  • Before adding the image.jpg image file to PDF using iText, do: "convert image.jpg image.jpg"
  • Then add jpeg
0
source

Source: https://habr.com/ru/post/1269088/


All Articles