A requirement in the project to save HTML to a PDF to a remote FTP server and database
Solution: Use Html2canvas to capture page elements, similar effects, and then use Itextpdf to convert PDFs to a database.
Advantages: Support Chinese (also want to use other plugins, such as Jspdf plug-ins, but not support Chinese, unfortunately); easy to get started
Disadvantage: Html2canvas's shortcomings are, not clear enough, this is not very satisfied;
Html2canvas This is not on the tutorial, a lot of official website.
The main problem here is that it's worth sharing: How to save to a remote FTP server and database
(1) using the Html2canvas interception interface is actually an image, in the form of byte[] array to the background processing, need to go through itextpdf processing to PDF, the following is the processing of itextpdf,
Need an output stream the FOS as the destination of the output, for uploading to the FTP server, there is no problem (FTP is a remote address URI). But how to save to the database?
(2) We know that there are generally two ways to save a file: 1. Save to a local or remote file system address 2. Temporarily in memory, after processing, into the database
This is our solution, put in memory
The key is this Bytearrayoutputstream, You can create a byte-type buffer, depending on the size of your virtual machine's memory,
The Tobytearray () method is then used to convert to byte data, which is stored in a BLOB-type database (Oracle is used here).
There is nothing wrong with the place, also please criticize, mutual progress. If someone knows how to improve the accuracy, welcome to the discussion, Google a lot of ways, no effect.
Reference Address:
How does insert itext PDF into database
Use Html2canvas screenshot to save to database using Itextpdf to PDF