Im Zusammenhang mit Need to open blob/PDF in IE window und Setting window.location or window.open in AngularJS gives "access is denied" in IE 11.Öffnen Sie PDF aus Binär in Internet Explorer
Ich brauche ein PDF zu öffnen, die in meinem Dienst von einem Byte-Array kommt:
@RequestMapping("/{dokumentId}")
public ResponseEntity<byte[]> getDoc(@PathVariable Integer docId, HttpServletRequest request, HttpServletResponse response) throws IOException {
byte[] contents = // .. get document
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/pdf"));
headers.add("Content-Disposition", "inline;filename=file");
headers.add("Cache-Control","private, must-revalidate, post-check=0, pre-check=0, max-age=1");
headers.add("Pragma", "no-cache");
headers.setContentLength(contents.length);
return new ResponseEntity<>(contents, headers, HttpStatus.OK);
}
, die ich versuche, in Internet Explorer 11 mit dem folgende JS zu öffnen:
$scope.openPdf = function(doc){
var winlogicalname = "document_" + doc.docId;
var winparams = 'dependent=yes,locationbar=no,scrollbars=yes,menubar=yes,resizable,screenX=50,screenY=50,width=850,height=1050';
var ieEDGE = navigator.userAgent.match(/Edge/g);
var ie = navigator.userAgent.match(/.NET/g); // IE 11+
var oldIE = navigator.userAgent.match(/MSIE/g);
if(!ie && !oldIE && !ieEDGE){
// Open PDF in new browser window
var detailWindow = window.open("", winlogicalname, winparams);
}
xxxService.getDoc(doc).success(function(data){
//for browser compatibility
if (ie || oldIE || ieEDGE) {
var blob = new window.Blob([data], { type: 'application/pdf' });
window.navigator.msSaveOrOpenBlob(blob);
} else {
var binaryAsString = ArrayBufferToString(data).replace(/"/g,"");
var pdfAsDataUri = "data:application/pdf;base64," + binaryAsString;
var htmlText = '<embed width=100% height=100% type="application/pdf" src="'+ pdfAsDataUri + '"></embed>';
detailWindow.document.write(htmlText);
detailWindow.document.close();
}
}).error(function(data, status, headers, config){
console.log(data, status, headers, config);
});
};
Dies funktioniert in Chrome und Firefox (öffnet in einem neuen Fenster, direkt aus Binär erstellt mit <embed>
. Allerdings scheint dieser Weg nicht in IE zu arbeiten, daher msSaveOrOpenBlob
. Aber beim Speichern/Öffnen der PDF in IE, erhalte ich einen Fehler in Adobe Leser: "Adobe Acrobat Reader DC could not open 'file.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
". Wh de Ich versuche, die PDF-Datei per Drag-and-drop in den IE zu laden, dort steht "File does not begin with '%PDF-'.
".
Haben Sie Ideen, wie Sie ein PDF in IE11 öffnen, indem Sie entweder direkt ein Byte-Array verwenden oder eine Blob
erstellen?
Ich verstehe nicht, wie dieses Ereignis funktioniert? Alles, was es tun wird, ist die Datei herunterladen, wenn es IE ist, richtig? Es ist nur ein Fallback. –
@JudsonTerrell richtig, es ist nur ein Fallback für IE –
Ich fand einen Weg, pdfJs in IE –