简体   繁体   English

使用jsPDF在服务器端保存pdf

[英]Saving pdf on server side with jsPDF

I have an application that generates a HTML page with data which the user can edit. 我有一个应用程序,该应用程序生成带有用户可以编辑的数据的HTML页面。 At the end I generate a .pdf file with jsPDF. 最后,我使用jsPDF生成一个.pdf文件。 Is there any way that I can save this generated .pdf on my server-side database? 有什么方法可以将生成的.pdf保存在服务器端数据库中?

I'm using PrimeFaces. 我正在使用PrimeFaces。

Thanks in advance 提前致谢

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. 用户按下按钮生成.pdf后,我将保存他填写在数据库中的所有数据,仅是数据。

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. 当用户想要查看他生成的pdf时,我将使用他第一次提交时收集的数据生成一个新的pdf。

Thank you all for the answers, they were helpful. 谢谢大家的回答,它们对您有所帮助。

Updating my solution for other users: 为其他用户更新我的解决方案:

I found the .output('datauristring') method of the jsPDF which returns me a BASE64 String. 我发现.output('datauristring').output('datauristring')方法返回了BASE64字符串。

Then the String is sent via JSON to my backed bean and converted as my will. 然后,通过JSON将字符串发送到我支持的bean,并按照我的意愿进行转换。

I suggest to use wkhtmltopdf . 我建议使用wkhtmltopdf

It is a open source cross platform command line tool to generate pdf files from html content. 它是一个开源的跨平台命令行工具,可以从html内容生成pdf文件。

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. 因此,根据您的要求,您可以做的是,需要将html内容发送到服务器并将该内容保存到html文件中。

Once you saved html content into html you can call wkhtmltopdf like you execute MS-DOS commands in java. 将html内容保存到html后,可以像在Java中执行MS-DOS命令一样调用wkhtmltopdf。

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

Once pdf file is generated you can read and store into database. 生成pdf文件后,您可以读取并存储到数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM