Installation of mikehaertl-phpwkhtmltopdf on xampp

2019-08-31 07:31发布

问题:

I've tried to use this post: How do I get WKHTMLTOPDF to execute via PHP? but I'm missing something.

I'm hoping for a real dummies guide here...

Installing mikehaertl-phpwkhtmltopdf on windows/xampp/codeigniter

  1. Acquire and install wkhtmltopdf. This will typically install to C:\program files\wkhtmltopdf\lib or similar on windows.
  2. Acquire and unpack Mikehaertl's wrapper (e.g. wkhtmltox-win64_0.12.0-03c001d)
  3. Place the WkHtmlToPdf.php file in ???????
  4. Do I edit the WkHtmlToPdf.php file and put in
    • the binPath (C:\program files\wkhtmltopdf\lib) ????
    • the output folder ????
  5. Now test it with

    shell_exec("c:/programs/wkhtmltopdf/wkhtmltopdf.exe http://www.google.com c:/google.pdf");
    

As I may have mentioned... the real dummies guide. :(

回答1:

(Old question I know, but spent a fair bit of time figuring out his example as well :|)

1) Install wkhtmltopdf (for the Bin files) and Mike's files @ https://github.com/mikehaertl/phpwkhtmltopdf

2) Copy all of wkhtmltopdf & Mike's files to a desired location in your codeigniter folder.

3) To recreate Mikes example, you can create his demo.html (or use an actual link) and pdf.css (no css will also work), however in his php example, you'll be calling on, the first few lines go like this (he subtly mentions these requirements in the documentation):

require_once('WkHtmlToPdf.php'); // link to where you placed Mike's WkHtmlToPdf.php


// Create a new WKHtmlToPdf object with some global PDF options
$pdf = new WkHtmlToPdf(array(
'binPath' => '/wkhtmltopdf/bin/wkhtmltopdf.exe', // link to where placed your bin files

 ... // rest of code

 $pdf->addPage('demo.html'); // or something like $pdf->addPage('http://google.com');
 $pdf->send();
 // or $pdf->saveAs('/save/to/see/your/new.pdf'); 

Hope that helps



回答2:

The real reason I was looking for this dummies guide, was that I wanted a way to generate a PDF from my PHP app.

Whilst trying to find any solution to this particular (mikehaertl-phpwkhtmltopdf) component, I came across another one called fpdf, which can be found at http://www.fpdf.org/

This was painless.

  1. Download FPDF (v1.7 2011-06-18) ZIP file
  2. Unzip
  3. Copy everything into /php/fpdf17 in your IDE
  4. in your Controller create a function like this:

    function PDF() 
    {
      require('fpdf17/fpdf.php');
      $pdf = new FPDF();
      $pdf->AddPage();
      $pdf->SetFont('Arial','B',16);
      $pdf->Cell(40,10,'Hello World!');
      $pdf->Output();
    }
    
  5. Call your function.