【发布时间】:2021-02-23 02:57:24
【问题描述】:
长话短说, 我想创建将 PDF 文件打印到用户计算机的按钮 因此,首先,我在服务器数据库/文件中创建 PDF 文件,然后将其下载给用户。
使用此代码,我可以在服务器中创建 PDF 文件, 然后我搜索了如何使其可下载给用户.. 到目前为止没有运气,大多数错误说“......是物理路径,但应该是虚拟路径。”
这是代码
private void cetak_pdf(string s_id, string CompanyCode , string zpath)
{
bool SUCCESS = true;
string sErrMsg = "";
string sFileName = "";
DiskFileDestinationOptions diskOpts = null;
try
{
sFileName = s_id;
diskOpts = new DiskFileDestinationOptions();
diskOpts.DiskFileName = Server.MapPath("~" + "\\pdf\\" + zpath + CompanyCode + "_" + sFileName + ".pdf");
//Response.Write(diskOpts.DiskFileName);Response.End();
// this is the file created E:\GIA_25\pdf\CompanyAddress00000003_003.pdf
rptDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
rptDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
rptDoc.ExportOptions.DestinationOptions = diskOpts;
rptDoc.Export();
Response.ContentType = "application/pdf";
//Response.AppendHeader("Content-Disposition", "attachment; filename=MyFile.pdf");
Response.TransmitFile(Server.MapPath("E:\\GIA_25\\pdf\\CompanyAddress00000003_003.pdf"));
Response.End();
}
catch (Exception ex)
{
SUCCESS = false;
sErrMsg = ex.Message;
throw new Exception(sErrMsg);
}
}
请帮忙,这门语言有点新
【问题讨论】:
标签: asp.net asp.net-core pdf