我需要您的帮助,可以在bean写入PDF文件后自动打开生成的PDF文件。 我使用了iText
库来编写PDF文件,在下面的方法中,我能够生成PDF,但我不知道如何即时为用户打开它。
public static void main(String[] args) throws DocumentException, FileNotFoundException, IOException {
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
document.open();
BaseFont bf = BaseFont.createFont(
"c://windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf, 25);
PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell(new Phrase("Good Morning", font));
cell.setBorder(Rectangle.NO_BORDER);
cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
table.addCell(cell);
document.add(table);
document.close();
}
我希望用户在PDF文件被写入后能够查看并打印,那么我该如何做呢?
main
方法),想要显示一个PDF文件而不保存它,即仅存在于内存中的PDF。据我所知,使用用户计算机上现有的标准PDF查看器是不可能实现的。相反,你可以尝试使用Java PDF查看器组件,例如jPedal。 - mkl