gpt4 book ai didi

java - ExceptionConverter : java. io.IOException : The document has no pages. 我正在使用 iText

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:45:03 25 4
gpt4 key购买 nike

当我执行下面的代码时

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

我得到以下异常。请帮忙

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)

请帮助 friend 。提前致谢

最佳答案

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

关于java - ExceptionConverter : java. io.IOException : The document has no pages. 我正在使用 iText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6816195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com