asp.net - 如何打开PDF文件而不是在浏览器中以角度下载它?
问题描述
我在 Angular 4 中有前端,在 Dot net 有后端,我有一个 URL,当我在浏览器中点击该 URL 时,正在下载 PDF,但我想在浏览器中显示它。
我通过 get 调用收到了该 URL,然后我在新窗口中打开了该 URL,但它总是被下载。
这是我尝试过的:
ts文件代码:
this.http.get(this.pdfUrl, { params: { data: JSON.stringify(prospect) }})
.subscribe(data => {
var strWindowFeatures = "location=yes,height=570,width=520,scrollbars=yes,status=yes";
window.open(data.url, "_blank", strWindowFeatures);
},
error => {
console.log(error);
})
]).then(function (result) {
if (result) {
console.log("ok");
}
});
在此 get 调用的响应中,我收到加密格式的 PDF 文件数据和下载 PDF 的 URL。
我的控制器代码:
HtmlToPdf converter = new HtmlToPdf();
var rootDir = this.environment.ContentRootPath;
rootDir = this.environment.ContentRootPath + "/bin/Debug/netcoreapp2.0";
IHTMLTemplateProvider proposalProvider = new ProposalProvider();
proposalProvider.LoadDocument(rootDir + "/templates/Proposal.html");
proposalProvider.ParseDocument();
string notificationContent = await proposalProvider.GetDocumentInText().ConfigureAwait(false);
SelectPdf.PdfDocument doc = converter.ConvertHtmlString(notificationContent);
byte[] pdfData = doc.Save();
doc.Close();
return File(pdfData, "application/pdf", "document.pdf");
解决方案
推荐阅读
- kotlin - 如何在 Kotlin 中加载
- r - 使用 purrr 进行真实数据分析时的一个问题
- assimp - numWeights 对应于 mnumVertices?
- java - 如何使用java在线阅读pdf文件并保存在本地机器上
- java - 如何在使用 Java 和 Spring 的 REST Web 服务中等待()?
- php - 连接到 SQL Server.PDOException 对象时出错 (Azure)
- c# - 如何用 func 委托替换 Action 委托,将值返回给函数
- r - 操作方法:在同一图上叠加 2 组点的简单 R 图形
- c++ - 引用捕获和在 lambda (C++) 中通过引用发送参数有什么区别
- kubernetes - k8s ingress nginx 为每个域设置重写目标