admin管理员组

文章数量:1323175

I have an application that generates a HTML page with data which the user can edit. At the end I generate a .pdf file with jsPDF. Is there any way that I can save this generated .pdf on my server-side database?

I'm using PrimeFaces.

Thanks in advance

I have an application that generates a HTML page with data which the user can edit. At the end I generate a .pdf file with jsPDF. Is there any way that I can save this generated .pdf on my server-side database?

I'm using PrimeFaces.

Thanks in advance

Share Improve this question edited Feb 2, 2017 at 21:51 Vasil Lukach 3,7483 gold badges34 silver badges41 bronze badges asked Feb 2, 2017 at 13:54 jlwollingerjlwollinger 901 gold badge3 silver badges12 bronze badges 4
  • This question is not javascript, not java-se, not html, nor PrimeFaces related. And where do you generate the pdf? Client Side? Can you store it in an input element? Then this question boils down to getting the value of an input element to the server. Please break down your problem to what it actually boils down to. Now it is way to broad and unclear – Kukeltje Commented Feb 2, 2017 at 13:58
  • Do you mean that you want to upload your file in some repository to save it ?!? it's true that it's a little bit unclear. – Yagami Light Commented Feb 2, 2017 at 14:19
  • Sorry for not being clear, yes, I generate the pdf on client side. The point is that in this HTML sheet the user is able to type texts and change some datas fetched by the application on the database. I want to save the .pdf generated by the jsPDF library. – jlwollinger Commented Feb 2, 2017 at 15:05
  • 1 This may help you it also work for me. stackoverflow./questions/51786132/…. – kantsverma Commented Mar 15, 2021 at 9:15
Add a ment  | 

3 Answers 3

Reset to default 3

Updating my solution for other users:

I found the .output('datauristring') method of the jsPDF which returns me a BASE64 String.

Then the String is sent via JSON to my backed bean and converted as my will.

Thanks all for the help! I've found my solution:

Once the user presses on the button to generate the .pdf, I'll save all the data he filled on the database, just the data.

When the user wants to see the pdf he generated back, I'll generate a new one with the data collected on his first submit.

Thank you all for the answers, they were helpful.

I suggest to use wkhtmltopdf.

It is a open source cross platform mand line tool to generate pdf files from html content.

So to your requirement what you can do is, you need to send the html content to the server and save this content into a html file.

Once you saved html content into html you can call wkhtmltopdf like you execute MS-DOS mands in java.

Example: new ProcessBuilder("wkhtmltopdf.exe", htmlFilePath, pdfFilePath);

Once pdf file is generated you can read and store into database.

本文标签: javascriptSaving pdf on server side with jsPDFStack Overflow