iText 文档获取 URL
iText Document get URL
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();
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();