该程序在netbeans中运行良好,但是当通过jar文件pdf文件运行时,它会创建但为空。我也无法打开它。它说不支持该文件。
public void print() {
// TODO add your handling code here:
try {
document = new Document(PageSize.A4, 36, 36, 110, 80);
writer = PdfWriter.getInstance(document, new FileOutputStream("Weekly Report.pdf"));
// ReportHeader();.
HeaderFooterPageEvent event = new HeaderFooterPageEvent();
writer.setPageEvent(event);
document.open();
// add table
PdfPTable pdfTable = new PdfPTable(5);
pdfTable.setTotalWidth(527);
pdfTable.setLockedWidth(true);
pdfTable.setWidths(new int[]{5, 3, 11, 5, 4});
//adding table headers
int H[] = {4, 0, 1, 2, 3};
for (int i = 0; i < jTable_Display_Users.getColumnCount(); i++) {
PdfPCell cell = new PdfPCell(new Paragraph(jTable_Display_Users.getColumnName(H[i]), bold));
cell.setBackgroundColor(background_color);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setBorder(Rectangle.NO_BORDER);
cell.setBorderWidth(1);
cell.setFixedHeight(30);
pdfTable.addCell(cell);
}
//extracting data from the JTable
} catch (DocumentException | FileNotFoundException e) {
JOptionPane.showMessageDialog(null,e.getMessage());
}
//closePdf();
document.close();
writer.close();
}