I have one report and I'll use two different services to get PDF and HTML output. `StiPdfExportService` works fine and the result is as expected, but `StiHtml5ExportService` renders slightly different output. The HTML output is missing some labels, and strangely I get the desired result in debug mode, but not when I have published my app.
Please let me know about possible debugging steps, as I'm unable to provide test data.
This is the code that I'm using for HTML output:
Code: Select all
public static string GetHtml(string reportName, Dictionary<string, string> reportParams, HttpResponseBase Response)
{
string path = System.Web.Hosting.HostingEnvironment.MapPath(reportPath + reportName + ".mrt");
StiReport report = new StiReport();
report.Load(path);
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new StiSqlDatabase(connectionName, connectionString));
report.Compile();
foreach (KeyValuePair<string, string> param in reportParams)
{
report[param.Key] = param.Value;
}
try
{
report["userName"] = userName;
report["repDate"] = DateTime.Now.ToPersianDateAndTimeString();
report["orgName"] = orgName;
}
catch (Exception e) { }
report.Render(false);
MemoryStream stream = new MemoryStream();
StiHtml5ExportService svc = new StiHtml5ExportService() { };
svc.ExportHtml(report, stream, new StiHtmlExportSettings
{
AddPageBreaks = true
});
StreamReader reader = new StreamReader(stream);
stream.Position = 0;
var html = reader.ReadToEnd();
html = html
.Replace("<body", "<body onload='window.print();' ")
.Replace("<!DOCTYPE html>", "<!DOCTYPE html moznomarginboxes mozdisallowselectionprint>")
.Replace("</head>", @"<style type=""text/css"" media=""print"">@page { size: auto; margin: 0; }</style></head>");
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "text/html";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", html.Length.ToString());
Response.Write(html);
Response.End();
return html;
}