相关疑难解决方法(0)

在HTML中嵌入PDF的推荐方法?

在HTML中嵌入PDF的推荐方法是什么?

  • 的iFrame?
  • 宾语?
  • 嵌入?

Adobe对此有何看法?

就我而言,PDF是即时生成的,因此在刷新之前无法将其上传到第三方解决方案.

html pdf

1128
推荐指数
15
解决办法
136万
查看次数

通过jQuery.Ajax下载文件

我在服务器端有一个Struts2动作用于文件下载.

<action name="download" class="com.xxx.DownAction">
    <result name="success" type="stream">
        <param name="contentType">text/plain</param>
        <param name="inputName">imageStream</param>
        <param name="contentDisposition">attachment;filename={fileName}</param>
        <param name="bufferSize">1024</param>
    </result>
</action>
Run Code Online (Sandbox Code Playgroud)

但是当我使用jQuery调用动作时:

$.post(
  "/download.action",{
    para1:value1,
    para2:value2
    ....
  },function(data){
      console.info(data);
   }
);
Run Code Online (Sandbox Code Playgroud)

在Firebug中我看到使用二进制流检索数据.我想知道如何打开用户可以在本地保存文件的文件下载窗口

javascript ajax jquery jsp download

391
推荐指数
14
解决办法
68万
查看次数

PDF Blob - 弹出窗口不显示内容

过去几天我一直在研究这个问题.试图在<embed src>标签上显示流没有运气,我只是试图在新窗口上显示它.

新窗口显示PDF 控件 在此输入图像描述)

知道为什么没有显示pdf的内容吗?

码:

$http.post('/fetchBlobURL',{myParams}).success(function (data) {
    var file = new Blob([data], {type: 'application/pdf'});
    var fileURL = URL.createObjectURL(file);
    window.open(fileURL);
});
Run Code Online (Sandbox Code Playgroud)

javascript pdf angularjs

37
推荐指数
3
解决办法
11万
查看次数

Angular2显示PDF

我有一个带有ASP.Net Web API的angular2项目.我有代码从我的数据库中检索文件路径,该文件路径转到我服务器上的文档.然后,我想在浏览器中的新选项卡中显示此文档.有没有人有任何建议怎么做?

我很高兴在Angular2(Typescript)或我的API中检索文件并将其流式传输.

这是我尝试在我的API中检索它但我无法弄清楚如何在Angular2中接收它并正确显示它:

public HttpResponseMessage GetSOP(string partnum, string description)
    {
        var sopPath = _uow.EpicorService.GetSOP(partnum, description).Path;
        HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
        var stream = new FileStream(sopPath, FileMode.Open);
        result.Content = new StreamContent(stream);
        result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
        return result;
    }
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

非常感谢!!!

pdf filestream asp.net-web-api angular

20
推荐指数
3
解决办法
3万
查看次数

使用blob从ajax结果下载文件

我使用此代码从服务器下载excel文件.

$.ajax({
    headers: CLIENT.authorize(),
    url: '/server/url',
    type: 'POST',
    contentType: "application/json; charset=utf-8",
    data: JSON.stringify(jsonData),
    success: function (data) {
        alert('Data size: ' + data.length);
        var blob = new Blob([data], { type: "application/vnd.ms-excel" });
        alert('BLOB SIZE: ' + data.length);
        var URL = window.URL || window.webkitURL;
        var downloadUrl = URL.createObjectURL(blob);
        document.location = downloadUrl;
    },
});
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,尽管数据和blob大小相同,但是时刻document.location被分配我被提示下载almoste两倍大的excel文件.当我尝试打开它时,excel抱怨错误的文件格式,打开的文件包含很多垃圾,即使所需的文本仍然存在.

是什么导致了这个以及如何避免它?

javascript jquery

19
推荐指数
1
解决办法
5万
查看次数

需要在IE窗口中打开blob/PDF

我在我的打字稿中有下面的代码来调用web api方法并检索一个PDF的二进制字节数组(blob).我的用户要求是在新窗口中打开PDF.

$scope.selectRow = (itemImageNumber: string, printProcessId: string, printXmlId: string) => {
        itemService.GetOutgoingDocument($scope.item.ItemId, itemImageNumber, printProcessId, printXmlId).success((response) => {
            var file = new Blob([response], { type: 'application/pdf' });
            var fileUrl = URL.createObjectURL(file);
            //$scope.outDocContent = $sce.trustAsResourceUrl(fileUrl);
            var win = window.open($sce.trustAsResourceUrl(fileUrl));
            win.focus();
        }).error(() => {
            var message = 
                "The document you selected can’t be displayed at this time. Please call Customer Service at xxx-xxx-xxxx for assistance.";
            $rootScope.$broadcast("app-message", {
                type : "danger",
                message : message
            });
        });
    }
Run Code Online (Sandbox Code Playgroud)

此代码在Chrome中运行良好.该文件按预期打开.然而,IE问"你想让这个网站在你的电脑上打开一个应用程序吗?" 如果允许,请告诉我"没有安装应用程序来打开这种链接(blob)".

有关如何在新选项卡中打开它或将blob保存为文件作为最后手段的任何想法?

javascript internet-explorer google-chrome typescript

15
推荐指数
1
解决办法
7642
查看次数

在带有angularjs的Internet Explorer中的Blob网址

鉴于此代码(来自其他人):

var module = angular.module('myApp', []);

module.controller('MyCtrl', function ($scope){
    $scope.json = JSON.stringify({a:1, b:2});
});

module.directive('myDownload', function ($compile) {
    return {
        restrict:'E',
        scope:{ data: '=' },
        link:function (scope, elm, attrs) {
            function getUrl(){
                return URL.createObjectURL(new Blob([JSON.stringify(scope.data)], {type: "application/json"}));
            }

            elm.append($compile(
                    '<a class="btn" download="backup.json"' +
                    'href="' + getUrl() + '">' +
                    'Download' +
                    '</a>'
            )(scope));                    

            scope.$watch(scope.data, function(){
                elm.children()[0].href = getUrl();
            });
        }
    };
});
Run Code Online (Sandbox Code Playgroud)

小提琴示例可以在Chrome中下载.但是单击"下载"链接在IE11中没有任何作用.没有错误,没有警告,没有任何响应.

但根据这个它在IE10和11.1的支持.

是否有一些需要更改的IE安全设置或正在进行的操作?

javascript html5 internet-explorer angularjs bloburls

12
推荐指数
1
解决办法
2万
查看次数

在新选项卡中打开PDF文件角4?

我尝试使用window.open()打开PDF文件,但窗口会自动打开和关闭,文件会像任何其他文件一样下载.如何在新标签页中打开PDF文件?FYI没有安装广告拦截器

javascript pdf angular

11
推荐指数
2
解决办法
2万
查看次数

Windows Edge并打开一个blob网址

尝试在Windows Edge(20.10240.16384,这是Microsoft提供的IE11 VM中的版本)中打开带有blob URL的新窗口时,我得到了一些奇怪的结果.

var xhr = new XMLHttpRequest();
xhr.open('POST', sourceUrl, true);
xhr.responseType = 'blob';

xhr.onload = function(e,form) {
    if (this.status == 200) {
        var blob = this.response;
        var url = window.URL.createObjectURL(blob);
        var w = window.open(url);
    }
}
Run Code Online (Sandbox Code Playgroud)

在线上

var w = window.open(url);
Run Code Online (Sandbox Code Playgroud)

我得到一个"访问被拒绝"错误,它看起来与CORS捆绑在一起,这有点意义,因为它在技术上并不是同一个域.但是BLOB网址在技术上没有域名?

这是Edge中的错误吗?或者我做的事情不太对劲?此代码适用于IE,Chrome等.

javascript bloburls microsoft-edge

9
推荐指数
1
解决办法
1万
查看次数

通过Angular $ http而不是XMLHttpRequest呈现PDF

所以我花了几周时间研究如何通过ajax从服务器获取pdf,然后将其显示给客户端.我需要这样做的原因是用户不能直接在服务器上转到pdf,因为他们不会提供令牌来传递安全性,但我可以使用javascript.使用以下代码,我能够得到我所期望的:

 var xhr = new XMLHttpRequest();
 xhr.open('GET', url, true);
 xhr.responseType = 'arraybuffer';
 xhr.setRequestHeader("token", token.value);
 xhr.onload = function (e) {
    if (this.status == 200) {
       var file = new Blob([this.response], { type: 'application/pdf' });
       var fileURL = URL.createObjectURL(file);
       window.open(fileURL, '_blank');
    }
 };
 xhr.send();
Run Code Online (Sandbox Code Playgroud)

然而,当我尝试以这样的角度做这个确切的事情时(我正在做这个东西的一半,所以两者中的标题匹配):

var config = {
    url: url,
    method: 'GET',
    responseType: 'arraybuffer',
    headers: {
        'Accept':'*/*',
        "token": token.value
    }
}

$http(config)
    .success(function (response) {
        var file = new Blob([response], { type: 'application/pdf' });
        var fileURL = URL.createObjectURL(file);
        window.open(fileURL, '_blank')
    }); …
Run Code Online (Sandbox Code Playgroud)

javascript c# angularjs typescript

8
推荐指数
1
解决办法
875
查看次数

如何在Angular 2中打印Pdf

我有exf url的pdf文件的URL是"test.example.com/incoice/1/download?auth_token="some_token",当我访问此URL时,url将在浏览器中显示PDF.

现在我想用打印功能打开这个pdf,我的意思是用户不必按CTRL+P我想从我这边做这个.

我试过iframe,但它给了我错误的交叉起源.这是我使用的演示代码

//first try

 let _printIframe;
var iframe = _printIframe;
if (!_printIframe) {
    iframe = _printIframe = document.createElement('iframe');
    document.body.appendChild(iframe);

    iframe.style.display = 'none';
    iframe.id  = "printf";
    iframe.name = "printf";
    iframe.onload = function() {
      setTimeout(function() {
        iframe.focus();
        iframe.contentWindow.print();
      }, 1);
    };
  }

// second try 
   // SRC of pdf
iframe.src = "Some API URl " + "/download?access_token=" + 
this.authenticationService.currentTokenDetails.access_token;
let url = iframe.src + "&output=embed";

window.frames["printf"].focus();
window.frames["printf"].print();
var newWin = window.frames["printf"];
newWin.document.write('<body onload="window.print()">dddd</body>');
newWin.document.close();
Run Code Online (Sandbox Code Playgroud)

我在plunker中为print pdf创建了一个demo.http://embed.plnkr.co/WvaB9HZicxK6tC3OAUEw/在这个plunker我打开pdf在新窗口,但我想直接打印该pdf.我怎样才能做到这一点 …

javascript pdf angular

7
推荐指数
1
解决办法
2万
查看次数

不允许在Microsoft Edge中加载blob pdf资源

此应用程序用于从数据库收集信息并从中生成.pdf文件.

this.reportsService.getTelerikReport({ reportId: this.selectReportId, startDate: this.startDate, endDate: this.endDate, ReportItems: listCheckItems})
        .then(response => {
            this.fileLoading = false;
            var file = new Blob([response], { type: "application/pdf" });
            this.fileUrl = this.$sce.trustAsResourceUrl(URL.createObjectURL(file));
            this.isReportGenerated = true;
Run Code Online (Sandbox Code Playgroud)

我只在Microsoft Edge控制台中收到错误.很多人说这是Edge浏览器的安全问题.

有人能为我提供帮助吗?

javascript microsoft-edge

6
推荐指数
1
解决办法
3676
查看次数

Chrome 上 msSaveOrOpenBlob 的替代方案

我需要找到“msSaveOrOpenBlob”的替代品,它适用于 IE、Firefox 和 Chrome。特别是在 Chrome 上,这不起作用,并且不显示用于选择保存或打开文件的对话框。

你能建议我如何打开对话框让用户选择是否要保存或打开文件吗?

我实际上正在使用 Angular 6。

javascript internet-explorer mozilla google-chrome angular

6
推荐指数
2
解决办法
3万
查看次数