c# - Convert HTML style (dotted underline) to PDF using iTextSharp -


i trying generate pdf below html i.e. text dotted underline. (below sample actual html bigger)

<u style="border-bottom: 1px dotted #000;text-decoration: none;"> hello </u> 

as explained in how convert html pdf using itextsharp . output supposed have dotted line can see in html file, pdf generated itextsharp shows normal underline , not dotted underline. here complete method

   public void usingxmlworker()     {                     byte[] bytes;          //create stream can write to, in case memorystream         using (var ms = new memorystream())         {              using (var doc = new document())             {                 //create writer that's bound our pdf abstraction , our stream                 using (var writer = pdfwriter.getinstance(doc, ms))                 {                      //open document writing                     doc.open();                      //sample html , css                     var example_html = @"<u style=""border-bottom: 1px dotted #000;text-decoration: none;"" >&nbsp;hello&nbsp;</u>";                      using (var srhtml = new stringreader(example_html))                     {                         //parse html                         itextsharp.tool.xml.xmlworkerhelper.getinstance().parsexhtml(writer, doc, srhtml);                     }                      //var example_html = @"<u class=""dottedborder"">&nbsp;hello&nbsp;</u>";                     //var example_css = @".dottedborder{border-bottom: 1px dotted #000;text-decoration: none;font-size:38px;}";                     //using (var mscss = new memorystream(system.text.encoding.utf8.getbytes(example_css)))                     //{                     //    using (var mshtml = new memorystream(system.text.encoding.utf8.getbytes(example_html)))                     //    {                      //        //parse html                     //        itextsharp.tool.xml.xmlworkerhelper.getinstance().parsexhtml(writer, doc, mshtml, mscss);                     //    }                     //}                     doc.close();                 }             }             bytes = ms.toarray();         }           var testfile = path.combine(environment.getfolderpath(environment.specialfolder.desktop), "test.pdf");         system.io.file.writeallbytes(testfile, bytes);     } 

i tried other methods below code still see pdf generated normal underline opposed dotted underline. missing here ?

                    var example_html = @"<u class=""dottedborder"">&nbsp;hello&nbsp;</u>";                     var example_css = @".dottedborder{border-bottom: 1px dotted #000;text-decoration: none;font-size:38px;}";                     using (var mscss = new memorystream(system.text.encoding.utf8.getbytes(example_css)))                     {                         using (var mshtml = new memorystream(system.text.encoding.utf8.getbytes(example_html)))                         {                              //parse html                             itextsharp.tool.xml.xmlworkerhelper.getinstance().parsexhtml(writer, doc, mshtml, mscss);                         }                     } 

according css conformance list, borders supported on table cells.

the line seeing <u> tag's default bottom border , text-decoration code being overwritten default code <u> tag. if watch resolvestyles method in itextsharp\tool\xml\css\styleattrcssresolver.cs, top chunk (around 170 in 5.5.6) sets keys , values tagcss correctly finds , sets property. next block of code after that, however, special-cases html tags , forces rules upon then.

// inherit css parent tags, defined in provided cssinheritancerules or if property = inherit idictionary<string, string> css = t.css; if (t.name != null) {     if (t.name.equals(html.tag.i) || t.name.equals(html.tag.cite)         || t.name.equals(html.tag.em) || t.name.equals(html.tag.var)         || t.name.equals(html.tag.dfn) || t.name.equals(html.tag.address)) {             tagcss[css.property.font_style] = css.value.italic;     }     else if (t.name.equals(html.tag.b) || t.name.equals(html.tag.strong)) {         tagcss[css.property.font_weight] = css.value.bold;     }     else if (t.name.equals(html.tag.u) || t.name.equals(html.tag.ins)) {         tagcss[css.property.text_decoration] = css.value.underline;     }     else if (t.name.equals(html.tag.s) || t.name.equals(html.tag.strike)               || t.name.equals(html.tag.del)) {                  tagcss[css.property.text_decoration] = css.value.line_through;     }     else if (t.name.equals(html.tag.big)) {         tagcss[css.property.font_size] = css.value.larger;     }     else if (t.name.equals(html.tag.small)) {         tagcss[css.property.font_size] = css.value.smaller;     } } 

since block happens after css you'll see can't remove underline on <u> tag because turned on. similarly, can't un-bold <strong> tag, un-italic <em> or explicitly set font size on <big> tag (i forgot tag!) unless have parent container's font size set.

so unfortunately, short of modifying source i'm not sure looking possible.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -