c# - How can I get this iTextSharp Image to "float right"? -


i'm adding image pdf file so:

string imagepath = @"c:\users\default\"; if (system.io.file.exists(imagepath + "officeuseonlyimgsmaller.png")) {     itextsharp.text.image png = itextsharp.text.image.getinstance(imagepath + "officeuseonlyimg.png");     png.scaletofitlinewhenoverflow = true;     doc.add(png); } 

it working, after fashion - image indeed added pdf file:

[enter image description here

however, need image (the "office use only" rectangle) magnetize right, on same "row" varicolored text shown left, so:

[enter image description here

how can that? setting "scaletofitlinewhenoverflow" true didn't help. reduced size of image itself, made no difference - took smaller file , ballooned out same (screen) size previously.

update

once remembered load smaller image, (rather checking existence), image has been punified:

enter image description here

...but still tucks under, instead of right of, blocks of text.

update 2

i tried implement nelek's idea:

string imagepath = @"c:\users\default\"; if (system.io.file.exists(imagepath + "officeuseonlyimgsmaller.png")) {     itextsharp.text.image png = itextsharp.text.image.getinstance(imagepath + "officeuseonlyimgsmaller.png");     png.scaletofitlinewhenoverflow = true; // doesn't hoped (keep img on same line)     pdfptable tblimg = new pdfptable(1);     tblimg.widthpercentage = 35;     tblimg.horizontalalignment = element.align_right;     var parimg = new paragraph();     parimg.add(png);     pdfpcell imgcell = new pdfpcell();     imgcell.addelement(parimg);     imgcell.borderwidth = pdfpcell.no_border;     tblimg.addcell(imgcell);     doc.add(tblimg); } 

...but image not display @ all. hammer? chain?

update 3

okay, sort of works (still needs tweaking):

if (system.io.file.exists(imagepath + "officeuseonlyimgsmaller.png")) {     itextsharp.text.image png = itextsharp.text.image.getinstance(imagepath + "officeuseonlyimgsmaller.png");     pdfptable tblimg = new pdfptable(1);     tblimg.widthpercentage = 35;     tblimg.horizontalalignment = element.align_right;     pdfpcell imgcell = new pdfpcell();     imgcell.addelement(png); //parimg);     imgcell.borderwidth = pdfpcell.no_border;     tblimg.addcell(imgcell);     doc.add(tblimg); } 

(we don't need no stinkin' paragraphs!)

for life's not paragraph , death think no parenthesis 

update 4

with little code-tweaking (reverted original, fullsize image, , changed widthpercentage of table 35 45), see in generated pdf:

enter image description here

...so how pull img pre-twitter bootstraps align better text left? have wrap both tables in yet another, two-celled table?

  • i reckon might make more sense, on reflection, use 1 table, , make 2 column/cell table (rather wrap 2 single-celled amoebas, mean tables, yet table).

update 5

one step closer latest code:

pdfptable tbl = new pdfptable(2); tbl.widthpercentage = 55; tbl.horizontalalignment = element.align_left; var par = new paragraph(); par.setleading(0, 1.2f); par.add(boldpart); par.add(ini); par.add(anchor); par.add(middlepart); par.add(anchorcco); pdfpcell chunky = new pdfpcell(); chunky.addelement(par); chunky.borderwidth = pdfpcell.no_border; tbl.addcell(chunky);  string imagepath = @"c:\users\default\"; if (system.io.file.exists(imagepath + "officeuseonlyimg.png")) {     itextsharp.text.image png = itextsharp.text.image.getinstance(imagepath + "officeuseonlyimg.png");     pdfpcell imgcell = new pdfpcell();     imgcell.addelement(png);     imgcell.borderwidth = pdfpcell.no_border;     tbl.addcell(imgcell);     doc.add(tbl); } 

...but image puny , squarshes text in table's first cell:

enter image description here

...maybe need add empty cell or something...

the way code in update 5 (make table 2 cells/rows, , put image in second holding tank), percentage changed 55 100 (which default, , redundant).

pdfptable tbl = new pdfptable(2); tbl.widthpercentage = 100; tbl.horizontalalignment = element.align_left; var par = new paragraph(); par.setleading(0, 1.2f); par.add(boldpart); par.add(ini); par.add(anchor); par.add(middlepart); par.add(anchorcco); pdfpcell chunky = new pdfpcell(); chunky.addelement(par); chunky.borderwidth = pdfpcell.no_border; tbl.addcell(chunky);  string imagepath = @"c:\users\default\"; if (system.io.file.exists(imagepath + "officeuseonlyimg.png")) {     itextsharp.text.image png = itextsharp.text.image.getinstance(imagepath + "officeuseonlyimg.png");     pdfpcell imgcell = new pdfpcell();     imgcell.addelement(png);     imgcell.borderwidth = pdfpcell.no_border;     tbl.addcell(imgcell);     doc.add(tbl); } 

with code, image displays pretty envisioned:

enter image description here

note: working code based on online example found here.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -