c# - Font not reflected while converting html to word document -


i have website in c#asp.net 4.0. here using html open xml code , dll.

for doing going following steps:-

1) first open existing word doc copy paragraph having font "arial". 2) parse html html word conversion code using htmltoopen xml dll.

and c# code here :-

protected void btnexporttoword_click(object sender, eventargs e)     {         string readtext = string.empty;         const string filename = "c:\\temp\\exporttodocnew1.docx";          try         {                            htmlfile = "<html><head><style type=\"text/css\" media=\"screen,print\">";             htmlfile += " .divpagebreak { page-break-after: always; display: block;  clear: both;}";             htmlfile += " table,td{border:1px solid black;border-collapse:collapse;}";             htmlfile += "</style></head><body><div class=\"divpagebreak\">" + "<p>&nbsp;</p> 
effective date of reporting duties, eligible salary, allowances , other benefits specified in enclosed annexure. remuneration indicated in annexure comprehensive , all-inclusive , hence shall deemed include liabilities of company. remuneration package strictly confidential between , company , should not discussed 1 nor divulged in manner whatsoever.

 

" + "";

            using (memorystream generateddocument = new memorystream())             {                 using (wordprocessingdocument package = wordprocessingdocument.create(generateddocument, wordprocessingdocumenttype.document))                 {                     maindocumentpart mainpart = package.maindocumentpart;                      if (mainpart == null)                     {                         mainpart = package.addmaindocumentpart();                         new documentformat.openxml.wordprocessing.document(new body()).save(mainpart);                     }                      htmlconverter converter = new htmlconverter(mainpart);                     body body = mainpart.document.body;                      sectionproperties sectionprops = new sectionproperties();                     pagemargin pagemargin = new pagemargin() { top = 1000, right = (uint32value)1008u, bottom = 2000, left = (uint32value)1008u, header = (uint32value)1600u, footer = (uint32value)720u, gutter = (uint32value)0u };                     sectionprops.append(pagemargin);                     body.append(sectionprops);                      var paragraphs = converter.parse(htmlfile);                     word.application wordapp = new word.application();                     (int = 0; < paragraphs.count; i++)                     {                         body.append(paragraphs[i]);                     }                      converter.excludelinkanchor = false;                                           mainpart.document.save();                 }                  file.writeallbytes(filename, generateddocument.toarray());             }            }         catch         {         }     } 

you haven't explicitly posed question see, i'll take you're interested in way honour fonts going html docx in c#/.net.

i don't know "htmltoopen xml dll", alternative, docx4j-importxhtml.net supports fonts:

 /**  * map font family, example "century gothic" in:  *   *    font-family:"century gothic", helvetica, arial, sans-serif;  *   * w:rfonts object, example:  *   *    <w:rfonts w:ascii="arial black" w:hansi="arial black"/>  *   * assuming style font-family:"century gothic", helvetica, arial, sans-serif;  * first font family there mapping 1  * used.   *   * xhtml-renderer's cssname defaults font-family: serif  *   * responsibility ensure suitable font available   * on target system (or embedded in docx package).  if   * (eventually) support css @font-face, docx4j  * (at least font formats can convert  * embeddable).  *   * should set these once, subsequent   * imports, since stuff cached , won't updated  * if add fonts later.  *   * @since 3.0  */ public static void addfontmapping(string cssfontfamily, rfonts rfonts) {     fonthandler.addfontmapping(cssfontfamily, rfonts); }  public static void addfontmapping(string cssfontfamily, string font) {      fonthandler.addfontmapping(cssfontfamily, font); } 

you can configure defaults:

# docx4j-importxhtml.properties  docx4j-importxhtml.fonts.default.serif=times new roman  docx4j-importxhtml.fonts.default.sans-serif=arial  docx4j-importxhtml.fonts.default.monospace=courier new 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -