if (string.IsNullOrEmpty(txtFileNumber.Text))
{
return;
}
LoadReport();
var sb1 = new StringBuilder();
var sb2 = new StringBuilder();
var sb = new StringBuilder();
sb1.Append("<html>");
sb1.Append("<head>");
sb1.Append("<meta http-equiv='content-type' content='text/html; charset=utf-8'/>");
sb1.Append("<style>");
sb1.Append(strPrintCSS);
sb1.Append("</style></head><body>");
try
{
div_print.RenderControl(new HtmlTextWriter(new StringWriter(sb)));
}
catch (Exception ex)
{
ProcessException(ex);
}
sb2.Append("</body></html>");
var htmlContent = sb1.ToString() + sb.ToString() + sb2.ToString();
var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
byte[] bytes = htmlToPdf.GeneratePdf(htmlContent);
string fileNumber = String.Concat(txtFileNumber.Text.Where(c => !Char.IsWhiteSpace(c)));
Response.Clear();
MemoryStream ms = new MemoryStream(bytes);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + fileNumber + ".pdf");
Response.Buffer = true;
ms.WriteTo(Response.OutputStream);
btnFileMetaDataDownload.Enabled = true;
btnSave.Enabled = true;
btnClear.Enabled = true;
formUpdatePanel.Update();
PrintUpdatePanel.Update();
Response.End();
}
#region PrintCSS
public const string strPrintCSS = "table,td,th{border:solid 1px #ddd;padding:5px 5px}";
No comments:
Post a Comment