PDF在线预览

代码归类 Views
PDF在线预览
插件: generic
采用mvc的webapi和页面方式
接口端控制器中:
[HttpGet]
[Route("GetPdfShow/{url}")]
public HttpResponseMessage GetPdfShow(string url)
{
try {
//获取需要展示的pdf文件流
Stream result = _attachmentService.GetPdfShow(url);
if (result != null)
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StreamContent(result);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
response.Content.Headers.ContentLength = result.Length;
return response;
}
else
return null;
}
catch (Exception ex) {
throw ex;
}
} 
页面中:
http://localhost:8444///PdfViewer/generic/web/viewer.html?file=/api/amt/GetPdfShow/2685B492B04248679A37B6212954C396$716613093636571662130108287.docx
查看按钮的链接指向包中的viewer.html页面,参数指向控制器方法,这种事需要去另外地方取pdf,如果pdf就在项目中,可以直接指向pdf文件
评论 --
  • 消灭零回复