ExceptionConverter: java.io.IOException: The document has no pages
I want to create 4 pdf files using iText. While running the code the first two of are successfully created. The remaning two throw an Exception "ExceptionConverter: java.io.IOException: The document has no pages."
Here is the code for pdf creation part:
public static Boolean createPDFFile(String filename, int headerType, List<DremelitemDetails> itemDetails) {
try {
path = new File(".").getCanonicalPath();
column = 0;
// create the pdf file
props.load(new FileInputStream("Properties\\eng.properties"));
COLUMNS = new float[][] {
{ MARGIN_LEFT, MARGIN_BOTTOM, (PageSize.LETTER.rotate().getWidt开发者_如何学编程h() - MARGIN_ENTER_COLUMNS) / 2,
PageSize.LETTER.rotate().getTop(MARGIN_TOP) },
{ (PageSize.LETTER.rotate().getWidth() + MARGIN_ENTER_COLUMNS) / 2, MARGIN_BOTTOM,
PageSize.LETTER.rotate().getRight(MARGIN_RIGHT), PageSize.LETTER.rotate().getTop(MARGIN_TOP) } };
String fontPath = "font\\arialuni.TTF";
unicodeFont = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
mmPDFDocument = new Document(PageSize.LETTER.rotate(), MARGIN_LEFT, MARGIN_RIGHT, MARGIN_TOP, MARGIN_BOTTOM);
pdfWriter = PdfWriter.getInstance(mmPDFDocument, new FileOutputStream(filename));
mmPDFDocument.setPageSize(PageSize.LETTER.rotate());
/*String[] footer = { props.getProperty("header"), "fdftfdbfbug",
"\u00a9" + props.getProperty("footer1"), props.getProperty("footer2")};*/
String[] footer = { "SUMMARY OF PROJECTS", "Home Décor",
"\u00a92011 Robert Bosch Tool Corporation. All Rigths Reserved.",
"Web content and services - on demand, on your printer www.eprintcentre.com" };
pdfWriter.setPageEvent(new HeaderFooter(mmPDFDocument.right() - mmPDFDocument.left(), footer, path, headerType, unicodeFont));
mmPDFDocument.open();
COLUMNS[0][3] = mmPDFDocument.top();
COLUMNS[1][3] = mmPDFDocument.top();
pdfColumn = new ColumnText(pdfWriter.getDirectContent());
pdfColumn.setSimpleColumn(COLUMNS[column][0], COLUMNS[column][1], COLUMNS[column][2], COLUMNS[column][3]);
pdfColumn.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
/* For generating Pdf */
addItemDetails(itemDetails);
mmPDFDocument.close();
} catch (FileNotFoundException e) {
System.out.println("FileNotFoundException-------"+e);
closePDFFile();
return false;
} catch (DocumentException e) {
System.out.println("DocumentException-------"+e);
closePDFFile();
return false;
} catch (Exception e) {
System.out.println("Exception-------"+e);
return false;
}
return true;
}
public static void main(String[] args) {
DremelData dremelData = new DremelData();
DremelPDFBulid dremelPDFBulid = new DremelPDFBulid();
Document doc = dremelData.readXml("C:\\eng.xml");
ArrayList<DremelitemDetails> homeDeco = dremelData.parseNode(1, 11, doc);
ArrayList<DremelitemDetails> artsAndCrafts = dremelData.parseNode(12, 24, doc);
ArrayList<DremelitemDetails> seasonalIdeas = dremelData.parseNode(25, 36, doc);
ArrayList<DremelitemDetails> DIYRestoration = dremelData.parseNode(37, 49, doc);
try {
dremelPDFBulid.createPDFFile("c:\\sam1.pdf", 0, homeDeco);
dremelPDFBulid.createPDFFile("c:\\sam2.pdf", 1, artsAndCrafts);
dremelPDFBulid.createPDFFile("c:\\sam3.pdf", 2, seasonalIdeas);
dremelPDFBulid.createPDFFile("c:\\sam4.pdf", 3, DIYRestoration);
} catch (Exception e) {
System.out.println("Error in readXml : " + e.toString());
}
}
In the above code the content of sam3 and samp4 pdf's are empty and showing "The document has no pages." exception
精彩评论