lonely_1 2016-12-28 01:43 采纳率: 0%
浏览 2263

java tif转pdf出现异常,求助大神。在线急等。

求助大神,下面是我在网上找到的tif转pdf代码和异常,这个错误我会崩溃了。

代码:
public static void tifOrPdf(String tif, String pdf) {

    //pdf = tif.substring(0, tif.lastIndexOf('.') + 1) + "pdf";
    Document document = new Document(PageSize.LETTER, 0, 0, 0, 0);
    int pages = 0, comps = 0;
    try {
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(pdf));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        RandomAccessFileOrArray ra = null;
        try {
            ra = new RandomAccessFileOrArray(tif);
            comps = TiffImage.getNumberOfPages(ra);
        } catch (Throwable e) {
            System.out
                    .println("Exception in " + tif + " " + e.getMessage());
        }

        System.out.println("Processing: " + tif);
        for (int c = 0; c < comps; ++c) {
            try {
                Image img = TiffImage.getTiffImage(ra, c + 1);
                if (img != null) {
                    System.out.println("page " + (c + 1));
                    img.scalePercent(7200f / img.getDpiX(),
                            7200f / img.getDpiY());
                    document.setPageSize(new Rectangle(
                            img.getScaledWidth(), img.getHeight()));
                    img.setAbsolutePosition(0, 0);
                    cb.addImage(img);
                    document.newPage();
                    ++pages;
                }
            } catch (Throwable e) {
                System.out.println("Exception " + tif + " page " + (c + 1)
                        + " " + e.getMessage());
            }
        }
        ra.close();
        document.close();
    } catch (Throwable e) {
        e.printStackTrace();
    }

    System.out.println("done...");

}


异常:
Exception D:\imgtif\1.tif page 1 All fill bits preceding EOL code must be 0.

Exception D:\imgtif\1.tif page 2 All fill bits preceding EOL code must be 0.
Exception D:\imgtif\1.tif page 3 All fill bits preceding EOL code must be 0.
ExceptionConverter: java.io.IOException: The document has no pages.
at com.fr.third.com.lowagie.text.pdf.PdfPages.writePageTree(PdfPages.java:118)
at com.fr.third.com.lowagie.text.pdf.PdfWriter.close(PdfWriter.java:1174)
at com.fr.third.com.lowagie.text.pdf.PdfDocument.close(PdfDocument.java:829)
at com.fr.third.com.lowagie.text.Document.close(Document.java:496)
at com.szewec.ecs.api.xxbs.web.controller.impl.FormatConverSion.tifOrPdf(FormatConverSion.java:290)
at com.szewec.ecs.api.xxbs.web.controller.impl.FormatConverSion.main(FormatConverSion.java:370)
done...

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2016-12-31 10:14
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现