iText文档获取URL

huangapple go评论110阅读模式
英文:

iText Document get URL

问题

这生成了项目根文件夹中的 test.pdf。现在我需要获取该文件的 java.net.URL。我该如何获取?

英文:
  1. Document document = new Document();
  2. PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
  3. document.open();
  4. Font font = FontFactory.getFont(FontFactory.COURIER, 16, BaseColor.BLACK);
  5. Chunk chunk = new Chunk("Hello World", font);
  6. document.add(chunk);
  7. document.close();

This generates test.pdf on root folder of my project. Now I need a java.net.URL of that file. How can I get that?

答案1

得分: 1

我相信这样的方法可能会起作用:

  1. File output_file = new File("test.pdf");
  2. // 将第2行更改为:
  3. PdfWriter.getInstance(document, new FileOutputStream(output_file));
  4. // 要获取 java.net.URL
  5. URL url = output_file.toURI().toURL();
英文:

I believe something like this could work:

  1. File output_file = new File("test.pdf");
  2. //Change Line 2 to:
  3. PdfWriter.getInstance(document, new FileOutputStream(output_file));
  4. //To get the java.net.URL
  5. URL url = output_file.toURI().toURL();

huangapple
  • 本文由 发表于 2020年8月10日 17:39:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63337697.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定