Home >Backend Development >PHP Problem >How to generate pdf files in php and download them

How to generate pdf files in php and download them

藏色散人
藏色散人Original
2019-09-18 09:18:597353browse

How to generate pdf files in php and download them

How to generate pdf files with php and download them

1. First download and install pdf: test the effect

How to generate pdf files in php and download them

2. Calling the code in php is very simple. Just use the shell_exec function. If the shell_exec function cannot be used, check whether it is in php.ini. The supplement is disabled.

How to generate pdf files in php and download them

3.wkhtmltopdf is very useful, but it is also somewhat unsatisfactory. The developers of wkhtmltopdf did not take this into consideration when developing, for example, this html page:

How to generate pdf files in php and download them

4. When I generate pdf, I want each block to be They are all one page, but the values ​​are wrong the further they go. We still don’t know how many pixels there are in one PDF page. But wkhtmltopdf has a good method, which is to add a page-break-inside:avoid; after the style of that div, and it will be ok.

Introducing css files:

How to generate pdf files in php and download them

5.css style code:

How to generate pdf files in php and download them

6.html page Code

How to generate pdf files in php and download them

For more PHP knowledge, please visit the PHP Chinese websitePHP Tutorial!

The above is the detailed content of How to generate pdf files in php and download them. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Linux upgrade php methodNext article:Linux upgrade php method