Converting html string (from asp.net view) to PDF

Hi Team,
I am trying to convert html string (which is generated from asp.net mvc view ) to PDF using Aspose.PDF 18.11 version. I am using below code for converting to pdf. But unfortunately i am not getting the proper output in pdf (Styles and controls are not coming up).

string htmlToConvert = RenderViewAsString(“Index”, null);
String thisPageUrl = this.ControllerContext.HttpContext.Request.Url.AbsoluteUri;
String baseUrl = thisPageUrl.Substring(0, thisPageUrl.Length - “HEQMaintenance/ViewTemplate/Download”.Length);
byte[] content=System.Text.Encoding.UTF8.GetBytes(htmlToConvert);
//Instantiate the HtmlLoadOptions object while passing the web page URL.
HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions(baseUrl);
htmlLoadOptions.PageInfo.Margin.Bottom = 10;
htmlLoadOptions.PageInfo.Margin.Top = 20;
Document doc = new Document(new MemoryStream(content), htmlLoadOptions);
var dataDir = @“H:”;
doc.Save(dataDir + “output.pdf”);

Please suggest.

output.pdf (108.6 KB)

Thanks,
Anand

@aca123

Thanks for contacting support.

Could you please try using latest version i.e. Aspose.PDF for .NET 19.3 in your environment. Also, please make sure to use valid license before using API methods. In case you do not have a valid license, you can get a free 30-days temporary license from our website in order to evaluate our API without any limitation.

If issue still persists, please share sample HTML string (in ZIP Archive) with us or a sample Visual Studio project. We will test the scenario in our environment and address it accordingly.

Thanks @asad.ali for the respose.

Currently we have valid 18.11 licensed version only. If it didnt meet our need then we will look for the latest one. Since we cant share the VS project so herewith attached html string along with output generated PDF.

output.zip (26.9 KB)

@aca123

Thanks for sharing sample files.

We have checked the HTML string that you shared by creating a sample HTML page with it. The HTML page did not contain any style and with this type of HTML, output PDF is correct. Would you please share sample expected output PDF document along with respective HTML data with all resources (i.e. styles, images, etc.). We will test the scenario in our environment and address it accordingly.