问题描述
我是新来的角的js,我希望在浏览器的新窗口中打开PDF文档后pressing一个按钮。
I'm new to angular js and I wish to open a PDF document in a new window of the browser after pressing a button.
我做与 $ http.get()
在前端的GET请求,在后端有一个Java休息服务,以响应GET并生成一个PDF文件。我想打开这个PDF浏览器。
I make a GET request with $http.get()
at front end, at backend there is a Java rest service that respond to the GET and generates a PDF. I wish to open this PDF on the browser.
如果无法打开这样的PDF则至少打开带有AngularJs任何PDF,我怎么能这样做呢?
If is not possible to open the PDF in this way then at least open any PDF with AngularJs, how could I do this?
@GET
@Path("/printPdf")
public Response printService(){
//generates the pdf
File reportFile = new File(filePath);
String name = reportName + "." + "pdf";
ResponseBuilder response = Response.ok(new TemporaryFileInputStream(reportFile));
response.header("Content-Disposition", "attachment; filename=" + name);
response.header("Content-Type", "application/pdf");
response.header("Access-Control-Expose-Headers", "x-filename");
response.header("x-filename", name);
return response.build();
}
这是什么有一个在后台生成在休息服务的响应。
this is what there is at backend to generate the response in the rest service.
推荐答案
如果你有这样的事情:
var myPdfUrl = 'something'
$http.get(myPdfUrl);
做到这一点,而不是:
Do this instead:
var myPdfUrl = 'something'
$window.open(myPdfUrl);
如果相反,你有这样的事情:
If instead you have something like this:
$http
.get(generatePdfUrl)
.success(function(data){
//data is link to pdf
});
做到这一点:
$http
.get(generatePdfUrl)
.success(function(data){
//data is link to pdf
$window.open(data);
});
这篇关于在angularjs浏览器的一个新窗口中打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!