Hallo,
ich möchte per AJAX ein PDF über einen RestFUL-Service generieren und anzeigen lassen.
@Path("/download")
@Produces("application/pdf")
public Response getFullImage(final PDFWebSocket pdfWebSocket) throws Exception {
// ziehe Dinge aus pdfWebsocket und erzeuge PDF
final Response.ResponseBuilder response = Response.ok(file);
response.header("Content-Disposition","attachment; filename=export.pdf");
return response.build();
}```
[XML]var jsonMessage = JSON.stringify({
"webSocketClientId": webSocketClientId
});
jQuery.ajax({
type: 'POST',
url: rootURL,
contentType: 'application/json',
data: jsonMessage,
success: function (data, textStatus, jqXHR) {
console.log('success');
console.log(data);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('error');
console.log(textStatus);
console.log(errorThrown);
}
});[/XML]
Ergebnis:
success
%PDF-1.4
%����
1 0 obj
<<
/Type /Catalog
/Version /1.4
/Pages 2 0 R
endobj
2 0 obj
<<
/Type /Pages
/Kids [3 0 R]
/Count 1
endobj
3 0 obj
<<
/Type /Page
/MediaBox [0.0 0.0 612.0 792.0]
/Parent 2 0 R
/Contents 4 0 R
/Resources 5 0 R
endobj
4 0 obj
<<
/Filter [/FlateDecode]
/Length 6 0 R
stream
x�s
��w3P04RI�240P0a��.
�Ԝ�|�����M��,.�.��
�
endstream
endobj
5 0 obj
<<
/Font 7 0 R
endobj
6 0 obj
50
endobj
7 0 obj
<<
/F0 8 0 R
endobj
8 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Helvetica-Bold
/Encoding /WinAnsiEncoding
endobj
xref
0 9
0000000000 65535 f
0000000015 00000 n
0000000078 00000 n
0000000135 00000 n
0000000247 00000 n
0000000375 00000 n
0000000408 00000 n
0000000426 00000 n
0000000457 00000 n
trailer
<<
/Root 1 0 R
/ID [ ]
/Size 9
startxref
559
%%EOF
data ist somit Text. Wenn ich nun den dataType vom AJAX auf 'application/pdf' setze, erhalte ich:
parsererror
No conversion from text to application/pdf
Habe ich da ein Problem in der Denke? Hat jemand eine Idee?