【问题标题】:iText Document get URL [duplicate]iText 文档获取 URL [重复]
【发布时间】:2020-11-29 21:51:03
【问题描述】:
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。我怎样才能得到它?

【问题讨论】:

  • 是什么让你无法生成它?

标签: java pdf url itext


【解决方案1】:

我相信这样的事情会奏效:

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();

【讨论】:

    猜你喜欢
    • 2017-12-02
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    • 2017-04-26
    相关资源
    最近更新 更多