使用itext读取JPG时过早的EOF [英] Premature EOF while reading JPG using itext

查看:716
本文介绍了使用itext读取JPG时过早的EOF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用iText将一些jpeg文件包含到PDF中时,我收到一个错误:
读取JPG时过早EOF

When attempting to include some jpeg files into a PDF using iText I get an error: Premature EOF while reading JPG

图像是从Android手机加载的,大多数都可以嵌入到pdf文件中,但有些不能。

The images are loaded from android phones and most can be embedded into the pdf file, however some can not.

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());
} 

在setImage期间发生错误:com.itextpdf.text.Jpeg.processParameters (Jpeg.java:219)
iText版本是:5.5.5

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

我已将导致错误的图像放到公共Dropbox文件夹中: https://dl.dropboxusercontent.com/u/46349359/image.jpg
图像为1.6 MB,在html中显示没有问题或使用其他图像显示工具。

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

推荐答案

如上所述Amedee这个问题是重复的。对我有用的具体解决方案是:

As stated by Amedee this question was a duplicate. The specific resolution that has worked for me is to:


  1. 安装imageMagick

  2. 在添加图片之前使用iText运行文件image.jpg到PDF:
    convert image.jpg image.jpg

  3. 然后添加jpeg

这篇关于使用itext读取JPG时过早的EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆