Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
document.open();
Font font = FontFactory.getFont(FontFactory.COURIER, 16, BaseColor.BLACK);
Chunk chunk = new Chunk("Hello World", font);
document.add(chunk);
document.close();
这将test.pdf
在我项目的根文件夹中生成。现在我需要java.net.URL
那个文件。我该怎么办?
我相信这样的事情可能会起作用:
File output_file = new File("test.pdf");
//Change Line 2 to:
PdfWriter.getInstance(document, new FileOutputStream(output_file));
//To get the java.net.URL
URL url = output_file.toURI().toURL();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句