We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

HTML syles was removed when inserting it to a pdf document after running response.end

I am working on a asp.net website, i am using aspose.words to create and download pdf document using below code, i am inserting text and also html on it. Now the problem is, when i save the pdf, all the STYLES from the html that i am inserting was removed, it uses default styles font and font size and so on making my inserted html rendered different from what it usually looks on the page, but before, it was working well, it looks like how i get the html from the page. This all happens when i use Response.End(); and after that even if i removed that line of code, still it doesn't let the styles go back. Any one who know's how i can i get back the styles to be included when inserting the html?

This is how i insert the html:
DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);

This is the saving code.
Document.Save(Response, "MyFile.pdf", Aspose.Words.ContentDisposition.Attachment, pdfOptions);

Hi Felix,

Thanks for your inquiry. Could you please attach your input HTML file and output PDF document showing the undesired behavior here for testing? We will investigate the issue on our end and provide you more information.

Best regards,

Hi Awais,

I’ll tell you first how it is being done, first is i get a word doc which has text, form fields and tables.

string docPath = MapPath(“Vacation-Request Final.docx”);
Aspose.Words.Document myDoc= new Aspose.Words.Document(docPath);

And i have text in every cell of a table where i finds and insert the html, below is the code,

myDoc.Range.Replace(new Regex(@"{{january}}"), new ReplaceWithHtmlEvaluator(GenerateHTML(JanCalendar)), false);
myDoc.Range.Replace(new Regex(@"{{february}}"), new ReplaceWithHtmlEvaluator(GenerateHTML(FebCalendar)), false);
myDoc.Range.Replace(new Regex(@"{{march}}"), new ReplaceWithHtmlEvaluator(GenerateHTML(MarCalendar)), false);

The function GenerateHTML(MarCalendar) gets the string html from a control, parameter is a calendar control, this is how i get the INPUT HTML, see below function:

protected string GenerateHTML(Calendar cal)
StringWriter sw = new StringWriter();
HtmlTextWriter w = new HtmlTextWriter(sw);


string s = sw.GetStringBuilder().ToString();

s = s.Replace(“cellpadding=“2"”, “cellpadding=“0"”);
s = s.Replace(“border-width:1px;border-style:solid;border-collapse:collapse;”,
“border-width:1px;border-style:solid;border-collapse:collapse;font-size: 12px;”);
s = Regex.Replace(s, @”<a\b[^>]+>([^<](?:(?!</a)<[^<])*)”, “$1”);
return s;

And the class ReplaceWithHtmlEvaluator(GenerateHTML(JanCalendar)) inserts the html to the specified cell, before it was working well, it looks like what it is in the webpage. But when i add Response.End(); after saving the document, the calendar styles has been changed to default styles. Below is my code for the saving:

Aspose.Words.Saving.PdfSaveOptions pdfOptions = new Aspose.Words.Saving.PdfSaveOptions();
pdfOptions.PageIndex = 0;
pdfOptions.PageCount = 1;
pdfOptions.PreserveFormFields = true;
myDoc.Save(Response, “Vacation_Request.pdf”, Aspose.Words.ContentDisposition.Attachment, pdfOptions);

I attached here the input word document (Vacation-Request Final.docx), the pdf output using the same code before i run the RESPONSE.END(); (Vacation Request (17).pdf), and last is the pdf output now which has the undesired output (Vacation_Request (91).pdf). Please see the difference of the calendar.

Hi Felix,

Thanks for the additional information. Unfortunately, at the moment, we’re not able to reproduce this issue on our end because some bits of code are missing from your shared code (e.g. definition of ReplaceWithHtmlEvaluator class is missing). We suggest you please create a standalone runnable simple application that helps us reproduce the same problem on our end and attach it here for testing. As soon as you get this application ready, we’ll investigate the issue further and provide you more information. Thanks for your cooperation.

Best regards,

Hi Awais,

I am attaching a stand alone web application. It shows a page with calendars, in this page, i want this calendar exactly show on the output pdf file, the styles and the font used should be the same, but in my case it becomes times new roman, please help me to make the calendars appear on the output the exactly the same.


Hi Felix,

Thanks for the additional information. We are working over your query and will get back to you soon.

Best regards,


Any news on this please? Thanks

Hi Felix,

Thanks for being patient. I have extracted JanCalendar’s HTML string from GenerateHTML method into a separate HTML file, the problem can still be observed in the attached JanCalendar.html. So, this doesn’t seem to be a bug in Aspose.Words. If we can help you with anything else, please feel free to ask.

Best regards,