asp.net - iTextSharp - MVC / HTMLWorker one string to add to a paragraph -
i sending contents of telerik mvc editor controller using ajax string: comes out as:
"<strong>hello world!</strong> <object height=\"1\" id=\"plugin0\" style=\"position:absolute;z-index:1000;\" type=\"application/x-dgnria\" width=\"1\"><param name=\"tabid\" value=\"{84594b7b-865f-4ad7-a798-294a8b0eb376}\" /></object>"
in controller, save string session variable using following:
string comments = httputility.htmldecode(text); mysession.current.pdftext = comments;
i can convert pdf using
..... htmlworker parser = new htmlworker(document); .......
however not add other paragraphes same page, makes new page.
i tried use following make new paragraph using htmlwork:
string pdftext = mysession.current.pdftext; string pdftext1 = htmlworker.parse(pdftext); stringreader reader = new stringreader(pdftext1); paragraph.add(reader);
i got these errors:
cannot convert 'system.io.stringreader' 'string', , best overloaded method match 'itextsharp.text.html.simpleparser.htmlworker.parse(system.io.textreader)' has invalid arguments, , best overloaded method match 'itextsharp.text.phrase.add(string)' has invalid arguments
i appreciate suggestions, in advance.
i have worked lot on itextsharp , follow approach of creating table or nested tables; if needed, multiple rows , columns , using colspan spread out content on page.
pdfptable table = new pdfptable(1); //create new table 1 column pdfpcell cell = new pdfpcell(); //create empty cell stylesheet style = new stylesheet(); //declare stylesheet style.loadtagstyle("h1", "color", "red"); //create styles html tags think there in pdftext arraylist objects = htmlworker.parsetolist(new stringreader(pdftext),style); //this transforms html list of pdf compatible objects (int k = 0; k < objects.count; ++k) { cell.addelement((ielement)objects[k]); //add these objects cell 1 one } table.addcell(cell); //add cell table document.add(table) //add table document
try out paragraph once trying in question. otherwise approach not result in new page.
edit:
please see updated code
pdfptable table = new pdfptable(2); //create new table 1 column pdfpcell cellleft = new pdfpcell(); //create empty cell stylesheet style = new stylesheet(); //declare stylesheet style.loadtagstyle("h1", "color", "red"); //create styles html tags think there in pdftext list<ielement> objects = htmlworker.parsetolist(new stringreader(pdftext),style); //this transforms html list of pdf compatible objects (int k = 0; k < objects.count; ++k) { cellleft.addelement((ielement)objects[k]); //add these objects cell 1 one } table.addcell(cellleft); //add cell table string url = "http://localhost:1713/pdf/images/sample.jpg"; //image path(can give local machine path testing) pdfpcell cellright = new pdfpcell(); image jpg = image.getinstance(new uri(url)); cellright.addelement(jpg); table.addcell(cellright); document.add(table);
please google padding, margins, borders , coloring etc..
Comments
Post a Comment