Convert HTML form data into a PDF file using PHP

前端 未结 4 1339
悲&欢浪女
悲&欢浪女 2021-02-03 11:57

I have been looking and testing this for a couple days now and was wondering if anyone could point me in a different direction. I have a very long job application HTML form (jo

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-03 12:16

    One way you can consider is using an online API that converts any HTML to PDF. You can send them a generated HTML (easier to produce) that will contains your user's submitted data, and receive back a high fidelity PDF.

    There are quite a few services available on the market. I like to mention PDFShift because it offers a package in PHP that simplifies the work for you.

    Once you've installed it (using Composer, or downloaded it directly, depending on your choices) you can quickly convert an HTML document like this:

    require_once('vendor/autoload.php');
    use \PDFShift\PDFShift;
    
    PDFShift::setApiKey('{your api key}');
    PDFShift::convertTo('https://link/to/your/html', null, 'invoice.pdf');
    

    And that's it. There are quite a few features you can implement (accessing secured documents, adding a watermark, and more).

    Hope that helps!

提交回复
热议问题