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

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?

mkl
  • 90,588
  • 15
  • 125
  • 265
farahm
  • 1,326
  • 6
  • 32
  • 70

1 Answers1

1

I believe something like this could work:

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();
CodingTil
  • 447
  • 2
  • 16