You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bold / italic style lost when writing as both RTF and HTML #245
When using the following code the bold and italic styles are not written to RTF:
usingiTextSharp.text;varhtmlFilePath="test.html";varrtfFilePath="test.rtf";varpdfFilePath="test.pdf";vardocument=newDocument(PageSize.A4);varhtmlFileStream=newFileStream(htmlFilePath,FileMode.Create);varhtmlWriter=html.HtmlWriter.GetInstance(document,htmlFileStream);varrtfFileStream=newFileStream(rtfFilePath,FileMode.Create);varrtfWriter=rtf.RtfWriter2.GetInstance(document,rtfFileStream);document.AddAuthor(System.Environment.UserName);document.Open();varfontTitle=FontFactory.GetFont(FontFactory.HELVETICA,16,Font.BOLD);varparTitle=newParagraph("This is a new document",fontTitle);varphrase=newPhrase();varboldChunk=newChunk("Bold, ",FontFactory.GetFont(FontFactory.HELVETICA,12,Font.BOLD));varitalicChunk=newChunk("italic, ",FontFactory.GetFont(FontFactory.HELVETICA,12,Font.ITALIC));varunderlineChunk=newChunk("underlined ",FontFactory.GetFont(FontFactory.HELVETICA,12,Font.UNDERLINE));varregularChunk=newChunk("text",FontFactory.GetFont(FontFactory.HELVETICA,12,Font.NORMAL));phrase.Add(boldChunk);phrase.Add(italicChunk);phrase.Add(underlineChunk);phrase.Add(regularChunk);varparBody=newParagraph(phrase);document.Add(parTitle);document.Add(parBody);document.Dispose();htmlFileStream.Dispose();rtfFileStream.Dispose();
It seems that the HTML writer removes the styles from the font, so the RTF writer finds the regular style only. If the RTF writer is initialized first, the opposite happens and bold/italic are written properly to RTF but not to HTML.
However, the styles are correct if for example the bold span is created like this:
var bold = FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD);
var boldFont = new Font(bold.BaseFont, 12, Font.BOLD);
var boldChunk = new Chunk("Bold", boldFont);
I would expect it to work the same way without setting the bold style twice, but maybe there is something I am doing wrong.
There are no issues if the PDF writer is initialized first, or with other styles such as underline and strikethrough.
Activity