.net core PDF下载接口
程序员文章站
2024-01-21 15:19:16
...
PDF下载接口
- Controller层
[Area("Api")]
public class DownloadPDFController : Controller
{
public readonly IWebHostEnvironment _webHostEnvironment;
public DownloadPDFController(IWebHostEnvironment webHostEnvironment)
{
_webHostEnvironment = webHostEnvironment;
}
public ActionResult DownloadFile(int goodID,string openID)
{
IH5Service m_H5Service = IocProxyFactory.GetService<IH5Service>();
try
{
//获取存储静态资源的wwwroot所在的根目录
string webRootPath = _webHostEnvironment.WebRootPath;
var reportInfo = m_H5Service.GetReportInfo(goodID,openID);
var path = reportInfo.Replace("/", "\\");
var fileName = webRootPath + path;
LogHelper.Info("pdf路径:" + fileName);
if (reportInfo != null)
{
var contentType = "application/msword";
if (fileName.ToLower().Contains(".pdf"))
{
contentType = "application/pdf";
}
else if (fileName.ToLower().Contains(".jpg"))
{
contentType = "image/jpeg";
}
else if (fileName.ToLower().Contains(".png"))
{
contentType = "image/png";
}
return File(reportInfo, contentType);
}
else
{
return Json("信息不存在");
}
}
catch (Exception ex)
{
LogHelper.Info("PDF_Error:" + ex.ToString());
return null;
}
}
}
2.service层
返回PDF文件路径
推荐阅读
-
.net core PDF下载接口
-
.net core Excel 下载接口
-
如何给asp.net core写个中间件记录接口耗时
-
【Dnc.Api.Throttle】适用于.Net Core WebApi接口限流框架
-
Asp.Net Core基于JWT认证的数据接口网关实例代码
-
.Net Core实现图片文件上传下载功能
-
.NET Core开发的iNeuOS工业互联平台,升级四大特性:配置数据接口、图元绑定数据、预警配置和自定义菜单
-
ASP.NET Core 2.2 WebApi 系列【三】AutoFac 仓储接口的依赖注入
-
如何在ASP.NET Core 中快速构建PDF文档
-
.net core 使用Rotativa创建PDF文档