我正在尝试从多部分XML soap响应中打开pdf。
我正在使用的FrameWork是Angular 6
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'url', true);
strRequest =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn://ecm.rmv.com/document/2013/06/01">' +
'<soapenv:Header/>' +
'<soapenv:Body>' +
'<ns:searchDocumentRequest>' +
'<ns:repositoryId>CrashReport</ns:repositoryId>' +
'<ns:actorId>CrashPortal</ns:actorId>' +
'<ns:documentType>CrashReport</ns:documentType>' +
'<ns:properties>' +
'<ns:property name="CrashDocNum"/>' +
'</ns:properties>' +
'<ns:filters>' +
'<ns:filter>' +
'<ns:condition property="CrashDocNum" operator="eq" value="PR201104900247"/>' +
'</ns:filter>' +
'</ns:filters>' +
'<ns:options>' +
'<ns:option name="retrieveContent">true</ns:option>' +
'</ns:options>' +
'</ns:searchDocumentRequest>' +
'</soapenv:Body>' +
'</soapenv:Envelope>'
xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xmlhttp.setRequestHeader('SOAPAction', 'searchDocument');
xmlhttp.send(strRequest);
HTTP/1.1 200 OK
X-Powered-By: Servlet/3.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, OPTIONS, HEAD, PUT, POST
Access-Control-Allow-Headers: content-type, soapaction
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:2112c517-ca6a-433f-b264-fd363b09aead"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Content-Language: en-US
Date: Fri, 04 Jan 2019 00:27:18 GMT
Content-Length: 514549
--uuid:2112c517-ca6a-433f-b264-fd363b09aead
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<searchDocumentResponse xmlns="urn://ecm.rmv.com/document/2013/06/01">
<success>true</success>
<documents>
...
</documents>
</searchDocumentResponse>
</soap:Body>
</soap:Envelope>
--uuid:2112c517-ca6a-433f-b264-fd363b09aead
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-ID: <adea784f-5e63-4b03-9736-bcdbf456bebe-1@urn://ecm.rmv.com/document/2013/06/01>
%PDF-1.6
%âãÏÓ
1 0 obj
<</DGAP_FIndex 1/DGAP_FList[/APF1/Helvetica 5 0 R]/DGAP_GSIndex 1/DGAP_GSList[/APGS1 6 0 R]/MarkInfo<</Marked true>>/Metadata 7 0 R/Pages 3 0 R/StructTreeRoot 8 0 R/Type/Catalog>>
endobj
7 0 obj
<</Length 3591/Subtype/XML/Type/Metadata>>stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c043 52.389687, 2009/06/02-13:20:35 ">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<xmp:ModifyDate>2017-09-06T14:32:15-05:00</xmp:ModifyDate>
<xmp:CreateDate>2017-09-06T14:32:15-05:00</xmp:CreateDate>
<xmp:MetadataDate>2017-09-06T14:32:14-05:00</xmp:MetadataDate>
<xmp:CreatorTool>Appligent Redax Enterprise Server 3.1.2</xmp:CreatorTool>
</rdf:Description>
...
<rdf:Description rdf:about="" xmlns:pdfx="http://ns.adobe.com/pdfx/1.3/">
<pdfx:Appligent>Redax Enterprise Server 3.1.2 Linux Kernel 2.6 64bit Dec 6 2010 Library 9.0.1</pdfx:Appligent>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
endstream
endobj
3 0 obj
<</Count 3/Kids[9 0 R 10 0 R 11 0 R]/MediaBox[0.0 0.0 614.4 792.0]/Resources<</Font<</APF1 5 0 R>>>>/Type/Pages>>
endobj
8 0 obj
<</K 12 0 R/ParentTree 13 0 R/ParentTreeNextKey 3/Type/StructTreeRoot>>
endobj
12 0 obj
<</K[14 0 R 15 0 R 16 0 R 17 0 R 18 0 R 19 0 R 20 0 R 21 0 R 22 0 R 23 0 R 24 0 R 25 0 R 26 0 R 27 0 R 28 0 R 29 0 R 30 0 R 31 0 R 32 0 R 33 0 R 34 0 R 35 0 R 36 0 R 37 0 R 38 0 R 39 0 R]/P 8 0 R/S/Document>>
endobj
13 0 obj
...
0000429477 00000 n
0000429405 00000 n
0000429333 00000 n
trailer
<</Size 3721/Root 1 0 R/Info 4 0 R/ID[<782E5FB7ACA6B2110A0020744EB2FD7F><AAC95FB7ACA6B2110A00D84D84010000>]>>
startxref
438658
%%EOF
--uuid:2112c517-ca6a-433f-b264-fd363b09aead--
我尝试了多种方法,但似乎无济于事:
注意:如果我将回复保存在文本文件中,然后将扩展名更改为pdf,则会显示pdf。
我在网上阅读了很多有关将其转换为Base64的显示代码,但是鉴于肥皂响应的回馈,我不知道是否可以这样做。
在上一次尝试中,我试图使用边界来分割xml,以获取以%PDF-1.6 开头的部分。拆分后,我运行下面的代码下载文件。
downloadReponse(doc_data) {
var newBlob = new Blob([doc_data], {type: "application/pdf"})
var url = window.URL.createObjectURL(newBlob);
var link = document.createElement('a');
link.href = url;
link.download = "file.pdf";
link.click();
setTimeout(function () {
URL.revokeObjectURL(url);
}, 10000);
}
这确实下载了文件,但是当我打开它时,pdf会以三个空白页面打开。本来我想让它在新标签页中打开,但是我在网上找到的代码仅适用于Base64。