POST XML to server, receiving PDF

Like this question , we are developing a web application in which the client presses a button to receive a PDF file from the server. Right now we are using the .ajax () method with jQuery for the POST data that the backend should generate PDF (we send the XML) at the click of a button, and then the backend will generate a fully PDF file and send it back as an application / pdf in the HTTP response.

One answer to this question requires the server side to save the PDF to disk so that it can return the URL to the GET client. But I do not want the caching content to be at all.

Another answer involves using the jQuery plugin, but when you look at its code, it actually generates the element formand then sends form. This method will not work for us, because we send XML data to the body of the HTTP request.

Is there a way to open the PDF browser without caching the server side of the PDF and not require us to abandon our send-data-to-server-using-XML solution?

(I would like the browser to behave this way when the element was sent form- POST is performed, and then the browser looks at the header Content-typeto determine what to do next, for example, download the PDF in a browser window, a la Safari)

+3
source share
4

:

1) , xslt (, saxon), xsl-fo ( xml), PDF FOP RenderX.

2) , xml bean , , (, Birt, JasperReports,...) PDF . XML , . , Javascript Data Source, .

3) iText PDF xml , , , .

+1

, , PDF. , . , , PDF , PDF /pdf. .

. http://129.33.194.254:8080/makepdf.rsp .

, http wirehark.

<html>
<body>
<%
    either none? text: select request/content 'data [
        %>
        <strong> PDF Test </strong>
        <form method="post">
        Enter some text:
        <input type="text" name="data" value="">
        <input type="submit" value="Submit">
        </form>
        <%
    ][
    if not exists? %pdf-maker.r [
        write %pdf-maker.r read http://www.colellachiara.com/soft/Misc/pdf-maker.r
    ]
    if not value? 'layout-pdf [
        *do %pdf-maker.r
    ]
    response/buffer: layout-pdf compose/deep [[textbox [(dehex text)]]]
    response/set-header 'Content-type "application/pdf"
    ]
%>
</body>
</html>
+1

PDF . PDF , html .

0

, : JSON . :

Create a hidden form (#printform) on your page with an input field (#printdata) and send the parameters as a string:

  $("#printdata").val(JSON.stringify(my_json_data_object));
  $("#printform").submit();

In my_json_data_object, I saved all the necessary data to create a pdf. On the server, I had to parse the parameters back to the JSON object using JSON.parse (...). With this solution, I can create and transfer PDF files to the client without saving them to the server. Remember to set the following response headers:

content-type: application/json
content-disposition: attachment; filename="output.pdf"
0
source

Source: https://habr.com/ru/post/1747455/


All Articles