Use Html2canvas screenshot to save to database using Itextpdf to PDF

Source: Internet
Author: User
Tags remote ftp server

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.