java - Image not displaying (but loading) in PDF generation using resource stream -


i created pdf using pdfbox. entire pdf generates , images loaded while using

pdimagexobject ptabelle = pdimagexobject.createfromfile("src/main/resources/pdf/ptabelle.png", pddocument); 

but project need go live sometime have replace static path class loader. after doing pdf generates, text displayed, not image.

the interesting thing inside pdf "box" image should there, not image.

box image should be

here code stream generation.

classloader classloader = getclass().getclassloader(); pdstream pdstream = new pdstream(pddocument, classloader.getresourceasstream("pdf/ptabelle.png")); pdresources pdresources = new pdresources(); pdimagexobject ptabelle = new pdimagexobject(pdstream, pdresources);  pdpagecontentstream pdpagecontentstream = new pdpagecontentstream(pddocument, page4); 

and here call in code, length + width variables defined in code.

 pdpagecontentstream.drawimage(ptabelle, text_begin, currentycoord, 172, 107); 

instead of new pdimagexobject(pdstream, pdresources) pdfbox internal use, please use appropriate losslessfactory method. code this:

bufferedimage bim = imageio.read(classloader.getresourceasstream("pdf/ptabelle.png")); pdimagexobject img = losslessfactory.createfromimage(pddocument, bim); 

see javadoc of pdimagexobject.createfromfilebyextension, explains factory methods can called instead.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -