将html报告转换为pdf [英] Convert html report to pdf

查看:123
本文介绍了将html报告转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个htm报告,我想在页面加载事件中将其转换为pdf如何可能

谢谢

Hi
I have one htm report and i want to convert it to pdf in page load event how to it possible
Thanks

推荐答案

使用CrystalDecisions.CrystalReports.Engine;

使用CrystalDecisions.Shared;

使用CrystalDecisions.Shared.Interop;

使用System.IO;





bool status = false;

DataTable dt = new DataTable( );

学生stu =新学生();

dt = stu.getActiveBlockStudentReport(0,Convert.ToString(ddlDepartment.SelectedValue),Convert.ToString(ddlCourses.SelectedValue) ),Convert.ToString(ddlStatus.SelectedValue));

尝试

{

if(dt!= null && dt.Rows.Count> ; 0)

{

if(File.Exists(Server.MapPath(〜/ ActiveBlockStudent.Pdf)))

{

System.IO.File.Delete(Server.Ma pPath(ActiveBlockStudent.Pdf));

}



string rptName = Server.MapPath(〜\\Reports \\ \\\rptBlockActiveStudent.rpt);

ReportDocument RptDoc = new ReportDocument();

RptDoc.Load(rptName);

RptDoc。 SetDataSource(dt);

ExportOptions exportOpts1 = RptDoc.ExportOptions;
RptDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

RptDoc.ExportOptions。 ExportDestinationType = ExportDestinationType.DiskFile;

RptDoc.ExportOptions.DestinationOptions = new DiskFileDestinationOptions();

((DiskFileDestinationOptions)RptDoc.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath( ActiveBlockStudent.Pdf);

RptDoc.Export();

RptDoc.Close();
RptDoc.Dispose();

{

Response.ClearContent();

Response.ClearHeaders();

Response.ContentType =application / pdf;

Response.AppendHeader(Content-Disposition,附件; filename = ActiveBlockStudent.Pdf);

Response.WriteFile(ActiveBlockStudent.Pdf);

Response.Flush();

回复.Close();

}

if(File.Exists(Server.MapPath(〜/ ActiveBlockStudent.Pdf)))

{

System.IO.File.Delete(Server.MapPath(ActiveBlockStudent.Pdf));

}

status = true;

}

其他

{

status = false;

}

}

catch(例外情况)

{

status = false;

}

if(status == false)

{

Messagebox1.Show(No Record Found found。);

}
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Shared.Interop;
using System.IO;


bool status = false;
DataTable dt = new DataTable();
Student stu=new Student();
dt = stu.getActiveBlockStudentReport(0,Convert.ToString(ddlDepartment.SelectedValue),Convert.ToString(ddlCourses.SelectedValue),Convert.ToString(ddlStatus.SelectedValue));
try
{
if (dt != null && dt.Rows.Count>0)
{
if (File.Exists(Server.MapPath("~/ActiveBlockStudent.Pdf")))
{
System.IO.File.Delete(Server.MapPath("ActiveBlockStudent.Pdf"));
}

string rptName = Server.MapPath("~\\Reports\\rptBlockActiveStudent.rpt");
ReportDocument RptDoc = new ReportDocument();
RptDoc.Load(rptName);
RptDoc.SetDataSource(dt);
ExportOptions exportOpts1 = RptDoc.ExportOptions;
RptDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
RptDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
RptDoc.ExportOptions.DestinationOptions = new DiskFileDestinationOptions();
((DiskFileDestinationOptions)RptDoc.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath("ActiveBlockStudent.Pdf");
RptDoc.Export();
RptDoc.Close();
RptDoc.Dispose();
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=ActiveBlockStudent.Pdf");
Response.WriteFile("ActiveBlockStudent.Pdf");
Response.Flush();
Response.Close();
}
if (File.Exists(Server.MapPath("~/ActiveBlockStudent.Pdf")))
{
System.IO.File.Delete(Server.MapPath("ActiveBlockStudent.Pdf"));
}
status = true;
}
else
{
status = false;
}
}
catch (Exception ex)
{
status = false;
}
if (status == false)
{
Messagebox1.Show("No Record Found.");
}


请参阅此处,

http://forums.asp.net/t/1409856.aspx [ ^ ]


您可以参考以下链接



我如何通过.net代码将html转换为pdf



使用ASP.NET从HTML页面生成PDF文档



希望这有助于
You can refer the below links

how i can convert html to pdf by .net code

Generate PDF documents from a HTML page using ASP.NET

Hope this helps


这篇关于将html报告转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆