java - How to add inline images in itext when using ColumnText in text mode -
private void processimage(phrase phrase, picture picture, columntext column) { // todo auto-generated method stub byte[] picturedata = picture.getcontent(); float ls = 12.0f; float multiline = 1.0f; column.setleading(ls, multiline); picturedata = wordtopdfutils.getmetafileasimage(picturedata); if (picturedata != null) { try { image pic = image.getinstance(picturedata); float[] scwh = scaleinlinepicture(picture); pic.scaleabsolute(scwh[0], scwh[1]); phrase.add(new chunk(pic, 0, 0, true)); column.addtext(phrase); } catch (badelementexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (malformedurlexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } } when add phrase containing inline image columntext, image appears overlap on above paragraphs in generated pdf, how add inline images while working columntext. link sample pdf file generated issue below
pdf sample inline picture issue thank you.
please take @ columntextchunkimage example. adds text containing images wrapped in chunk. leading adapted automatically based on height of images:

the code achieve similar yours:
image dog = image.getinstance(dog); image fox = image.getinstance(fox); phrase p = new phrase("quick brown fox jumps on lazy dog."); p.add("or, in more colorful way: quick brown "); p.add(new chunk(fox, 0, 0, true)); p.add(" jumps on lazy "); p.add(new chunk(dog, 0, 0, true)); p.add("."); columntext ct = new columntext(writer.getdirectcontent()); ct.setsimplecolumn(new rectangle(50, 600, 400, 800)); ct.addtext(p); ct.go(); the apparent difference see, use:
column.add(phrase); this method doesn't exist in official version of itext. either have addtext() (text mode) or addelement() (composite mode). guess you're using unofficial version of itext. unfortunately individuals have created forks of itext using fff principle: fork, f***, forget. if using such fork , don't want f***ed or forgotten, please switch using official version of itext.
Comments
Post a Comment