ExceptionConverter:java.io.IOException:文档没有页面。我正在使用iText [英] ExceptionConverter: java.io.IOException: The document has no pages. am using iText

查看:1229
本文介绍了ExceptionConverter:java.io.IOException:文档没有页面。我正在使用iText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行以下代码时

File f = new File("c:/sample.pdf");
PdfWriter.getInstance(document, new FileOutputStream(f));
document.open();
System.out.println("opening the document..");
PdfPTable headerTable=new PdfPTable(9);
PdfPCell cellValue = new PdfPCell(new Paragraph("Header 1"));
cellValue.setColspan(1);
headerTable.addCell(cellValue);
cellValue = new PdfPCell(new Paragraph("Header 2"));
headerTable.addCell(cellValue);
cellValue = new PdfPCell(new Paragraph("Header 3"));
headerTable.addCell(cellValue);
cellValue = new PdfPCell(new Paragraph("Header 4"));
headerTable.addCell(cellValue);

PdfPTable subHeaderTable = new PdfPTable(3);
PdfPCell subHeadingCell = new PdfPCell(new Paragraph("Header 5"));
subHeadingCell.setColspan(3);
subHeaderTable.addCell(subHeadingCell);
subHeaderTable.addCell("Sub heading 1");
subHeaderTable.addCell("Sub heading 2"); 
subHeaderTable.addCell("Sub heading 3");

headerTable.addCell(subHeaderTable);

document.add(headerTable);
document.close();

我得到以下异常。请帮助

I get below exception. please help

ExceptionConverter: java.io.IOException: The document has no pages.
    at com.lowagie.text.pdf.PdfPages.writePageTree(Unknown Source)
    at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
    at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
    at com.lowagie.text.Document.close(Unknown Source)

请帮助朋友。感谢提前

推荐答案

好的,所以我试试了你。我之前的回答是不正确的,声明该文件也可以正常工作。我认为你的表声明是错误的。您将其设置为9列,但只填充其中的5列。如果你将headerTable的columnssize更改为5应该修复它。

Okay so I tried it out for you. My previous answer was incorrect, declaring the file first works as well. I think that your table declaration is wrong. You set it to 9 columns, but you only fill 5 of them. If you would change your columnssize of the headerTable to 5 that should fix it.

这篇关于ExceptionConverter:java.io.IOException:文档没有页面。我正在使用iText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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