pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: display an image in pdf
Date Fri, 18 Mar 2016 18:38:41 GMT
Am 18.03.2016 um 18:13 schrieb Haddy, Diane E:
> Hello
> I have two questions.  I would like to display a .gif image into a pdf.  Can I use PDJpeg
class for .gif image?
> And in this piece of code, which I got form the internet:
> String imageName = "/images/arrow.gif;
>    PDXObjectImage image = new PDJpeg(doc, new FileInputStream(imageName));
>    PDPageContentStream content = new PDPageContentStream (doc, page)
>    content.drawImage(image, 200, 500)
>    content.close();
>    doc.save(fileName)
>    doc.close();
> the file path is in the web directory of my java project.  However when I run this, I
get FileNotFoundException.  Any suggestions?

Better use PDPixelMap for gif files. Just read it into a BufferedImage 
with ImageIO.read().

The second problem ("file path is in the web directory of my java 
project") sounds like you're doing a tomcat project. 
"/images/arrow.gif"is wrong for sure, obviously your image isn't there, 
maybe "images/arrow.gif" would be correct, maybe not. Do this to find 
out where you are:

System.out.println (new File(".").getAbsolutePath());

then search where your image directory is relative to that.


> Thank you
> Diane
> Diane Haddy
> Health Care Information Systems
> Application Developer
> 3281 Ridgeway Dr
> Coralville, IA 52241
> Phone  (319) 384-9725
> ________________________________
> Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic
Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.
 If you are not the intended recipient, you are hereby notified that any retention, dissemination,
distribution, or copying of this communication is strictly prohibited.  Please reply to the
sender that you have received the message in error, then delete it.  Thank you.
> ________________________________

To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org

View raw message