I'm having trouble figuring out how to add an external image (referenced by a URL) to a PDF using iText. Is this kind of thing possible?
The PDF spec in 7.1.5 says you should be able to reference a PDF via a URL by using a URL specification. This is what I've got so far:
PdfFileSpecification pdfSpec = PdfFileSpecification.url(writer, "http://www.someurl.com/test.jpg"); StringBufferInputStream sbis = new StringBufferInputStream(""); PdfStream dict = new PdfStream(sbis, writer); dict.put(PdfName.FILTER, PdfName.DCTDECODE) dict.put(PdfName.TYPE, PdfName.XOBJECT); dict.put(PdfName.SUBTYPE, PdfName.IMAGE); dict.put(PdfName.WIDTH, new PdfNumber(100)); dict.put(PdfName.HEIGHT, new PdfNumber(100)); dict.put(PdfName.BITSPERCOMPONENT, new PdfNumber(8)); dict.put(PdfName.LENGTH, new PdfNumber(0)); dict.put(PdfName.F, pdfSpec); PdfIndirectObject img = writer.addToBody(dict);
I know I still need to make sure the color space is added and stuff, but my main concern right now is actually getting this image into the body of the document. I can't figure out how to do this... it seems I can't get a reference to a PdfPage or the resources dictionary or anything. Is this possible using iText?
As a side note, this exercise is useless if I'm going to be presented with a security warning when the view tries to go load the image. Does anyone know if that is the case?