dan_vitch dan_vitch - 10 months ago 90
C# Question

Add web image to pdf

I am trying to add a web image to a pdf using iTextSharp

I am attempting to use the same code that you would use for a local image

using (var pdfDoc = new Document())
using (var pdfWriter = PdfWriter.GetInstance(pdfDoc, pdfStream)) {
Image tif = Image.GetInstance("www.myimage.com");

Answer Source

Contrary to the other posted answer, you do NOT need to make a separate HTTP request. Just make sure you use an absolute URI when calling Image.GetInstance():

string url = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/8f/Pollinationn.jpg/320px-Pollinationn.jpg";
using (Document document = new Document()) {
  PdfWriter.GetInstance(document, Response.OutputStream);
  Image img = Image.GetInstance(url);

This is clearly documented for the overloaded method call.