PHP generated PDF

Source: Internet
Author: User
Tags wkhtmltopdf

A project needs to use a Web page to generate a PDF, which is to generate a PDF file of the entire page,

Used to be html2pdf, can only generate some simple HTML code, complex HTML + CSS generated by the effect of a miserable,

Baidu a bit, found that there is a wkhtmltopdf,wkhtmltoimage, download to try it, sure enough, you can make the page intact as a PDF file, fully meet the project requirements.

But this is a command-line program, and the next thing is the point.

Wkhtmltopdf is a program executed at the command line, PHP can execute the command through Exec,system and so on, I have tried it, I can use it, can call Wkhtmltopdf to generate PDF file,

But the efficiency is too low, the generation is too slow, the test is a person, the generation of a file, if the production environment a lot of people at the same time, the estimate certainly not.

But executing the wkthmltopdf command directly at the command line is fast.

How to solve the efficiency problem.

Also did not think of any good method, my solution to the idea:

will need to generate the URL, commit to save to the database, and then write a command line execution of the PHP script, read the table needs to generate the record, if so, the call command generation file, the script is set to 5 seconds to execute the time,

on the Web page, write a Ajxa poll, 1 seconds at a time, to detect whether the file has been generated .

This solves the problem.

Although not perfect, but the project is really available, if the speed requirements of a bit higher can be PHP execution 3 seconds once, 2 seconds. should be faster. This has not been tried.

PHP generated 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.