spring - Add image in pdf using itext -
i'am creating spring mvc web application.my image in folder webapp/resources/img/logo.png of mvc application.how load image folder pdf.
i tried code.but trowing java.io.filenotfoundexception.
string imageurl = "webapp/resources/img/logo.png" logo = image.getinstance(imageurl);
enhanced find example how it:
document document = new document(); pdfwriter.getinstance(document, new fileoutputstream("c:\\test.pdf")); document.open(); image img = image.getinstance(classloader.getsystemresource("attention-icon.jpg")); img.scaleabsolute(10, 10); phrase phrase = new phrase(); phrase.add(new chunk(img, 0,0)); document.add(new paragraph(phrase)); document.close();
i think case file "webapp/resources/img/logo.png" relativ. try create file object check location:
file logo = new file("webapp/resources/img/logo.png"); if(! logo.exists()){ log.warn("file " + logo.getname() + " not exists"); }
Comments
Post a Comment