Java phantom JS completes the HTML image output function

Output HTML web pages as pictures @ h with phantomjs_ 502_ 1@

1. Background @ h_ 502_ 1@

How to generate a map in the applet and share it with the circle of friends? At present, the front end seems to have no good solution, so it can only be supported by the back end. How can we play@ H_ 502_ 1@

Generating pictures is relatively simple @ h_ 502_ 1@

Simple scenarios can be directly supported by JDK. Generally speaking, there is no too complex logic @ H_ 502_ 1@

I wrote a picture synthesis logic before, which is realized by AWT: picture synthesis @ H_ 502_ 1@

General and complex template @ h_ 502_ 1@

Simple ones can be supported directly, but complex ones can be supported by the back-end. It is undoubtedly disgusting. Some open-source libraries for rendering HTML have also been searched on GitHub. I don't know whether the posture is wrong or what. There are not very satisfactory results @ H_ 502_ 1@

Now, how to support complex templates@ H_ 502_ 1@

This is the guide of this article. It uses phantomjs to render HTML, supports generating PDF, generating pictures, and parsing dom. Next, it demonstrates how to build a web page rendering service @ h combined with phantomjs_ 502_ 1@

II. Prerequisite preparation @ h_ 502_ 1@

1. phantom. JS install @ h_ 502_ 1@

2. Java dependency configuration @ h_ 502_ 1@

Maven configuration add dependency @ h_ 502_ 1@

Start @ h_ 502_ 1@

The logic of calling phantomjs to render HTML pictures is as follows @ h_ 502_ 1@

test case@H_502_1 @

The generated pictures will not be posted. If you are interested, you can directly measure @ h on my website_ 502_ 1@

3. Network measurement @ h_ 502_ 1@

A simple web application is deployed on Alibaba cloud server, which supports the function of HTML output pictures; Because I bought the beggar version and used a cool front-end template, it opened slowly@ H_ 502_ 1@

Operation demonstration: @ h_ 502_ 1@

@H_ 502_ 1@@H_ 502_ 1@

5. Project @ h_ 502_ 1@

Project address: @ h_ 502_ 1@

quick-media @H_ 502_ 1@

Quickmedia is an open source project focusing on graphics, audio and video, QR code processing and other multimedia services @ H_ 502_ 1@

The above code has been tested by us. If you don't understand what you need to discuss, you can leave a message below. Thank you for your support for programming tips@ H_ 502_ 1@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>