0

I am trying to add an image which is on the web with below code with pdfbox library.

  PDPage page = doc.getPage(0);
  PDImageXObject pdImage = PDImageXObject.createFromFile("https://XXXXXX.png",doc);
  PDPageContentStream contents = new PDPageContentStream(doc, page);
  contents.drawImage(pdImage, 70, 250);

With above code I get below error.

javax.imageio.IIOException: Can't read input file! at javax.imageio.ImageIO.read(Unknown Source) at org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.createFromFileByExtension(PDImageXObject.java:223) at org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.createFromFile(PDImageXObject.java:183)

But If I download this file in my local machine and then try with this code then it works fine. Please let me know if I miss something.

Thanks.

Dhaval Goti
  • 447
  • 2
  • 10
  • 25
  • 1
    AFAIK PDFBox does not support directly reading from HTTP etc (which makes sense - I wouldn't expect it to). You should download the file and either save it as a temporary file or write it to a byte-array. See e.g. [this question](https://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java). – Itai May 07 '18 at 08:12
  • Thanks for the response. – Dhaval Goti May 07 '18 at 08:50

0 Answers0