c# - iTextSharp - html to pdf with background color for font -


i'm using itextsharp convert html pdf , email it. it's working fine, except doesn't seem support "background" style. code i'm using parse html

        private memorystream createpdf(string html){         memorystream msoutput = new memorystream();         textreader reader = new stringreader(html);          document document = new document(pagesize.a4, 30, 30, 30, 30);          pdfwriter writer = pdfwriter.getinstance(document, msoutput);          htmlworker worker = new htmlworker(document);          document.open();          writer.closestream = false;         worker.startdocument();          worker.parse(reader);          worker.enddocument();         worker.close();         document.close();         msoutput.position = 0;         return msoutput; } 

and html looks this:

<p> have <span style="background:red;padding:0.1em 0;" title="this has been brought attention.">ever switched electronic medical records vendor? if so...</span></p> 

which doesn't highlight text, to. however, using "color:red", works, changing color of text, need highlight, 'background' do.

anyway, i've been searching last day , can't find solution. possible? if not, there library supports this? i've tried pechkin library, same thing happens.

zero work being done in htmlworker, work being done in separate related project xmlworker please move that. can pretty plug in instead of htmlworker:

//bind reader our text using (textreader reader = new stringreader(html)) {     //parse html , write document     xmlworkerhelper.getinstance().parsexhtml(writer, document, reader); } 

side note, i'd recommend not passing around memorystream unless need , instead pass around underlying byte array. when passing around raw stream have worrying current position, checking if closed you, etc. i'd recommend changing method (also note using pattern):

private byte[] createpdf(string html) {     //basic pdf setup     using (var msoutput = new memorystream()) {         using (var document = new document(pagesize.a4, 30, 30, 30, 30)) {             using (var writer = pdfwriter.getinstance(document, msoutput)) {                  //open our document writing                 document.open();                  //bind reader our text                 using (textreader reader = new stringreader(html)) {                     //parse html , write document                     xmlworkerhelper.getinstance().parsexhtml(writer, document, reader);                 }                  //close main document                 document.close();             }              //return our raw bytes             return msoutput.toarray();         }     } } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -