简体   繁体   中英

itextSharp font size not matches when converting html to pdf

We are using itextsharp library in one of our project for creating pdf from html. Everything works fine, but PDF does not create exact replica of html text.

Like for example if html is like :-

<font size="3"><font face="Courier New, Courier, monospace">Plesae <strong>enter     
your</strong> text in below editor and click <font size="4">Generate button to view pdf 
from html to publish add in india</font></font>

and below code is being used to generate PDF then the font size are not properly taken by itext

StringReader strReader = new StringReader(content);
arrList = HTMLWorker.parseToList(strReader, null);

Paragraph para = new Paragraph();  
for (int k = 0; k < arrList.size(); ++k) {                   
  para.add((com.lowagie.text.Element)arrList.get(k)); 
}

We have made changes in library for mapping font size like if font size 3 is given then take 12 but still exact replica is not being created, may be for Courier 3 we need to map 13, 14 what i really looking forward is, if there is any formula for setting font size accrodingly. The Html being generated from CkEditor.

You need to use LoadTagStyle to handle it.

EX.

StyleSheet styles = new StyleSheet();

styles.LoadTagStyle(HtmlTags.P, HtmlTags.FONTSIZE, "16");

arrList = HTMLWorker.parseToList(strReader, style);

And add tag

to wrap your whole thing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM