Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update README.md

  • Loading branch information...
commit 9d2c07d9160ca2b6ab5034a7fe6938a291370882 1 parent 71d4dca
Michael Härtl authored

Showing 1 changed file with 1 addition and 148 deletions. Show diff stats Hide diff stats

  1. +1 148 README.md
149 README.md
Source Rendered
... ... @@ -1,148 +1 @@
1   -# PHP wkhtmltopdf
2   -
3   -This class is a slim wrapper around wkhtmltopdf.
4   -
5   -It provides a simple and clean interface to ease PDF creation with wkhtmltopdf.
6   -The wkhtmltopdf binary must be installed and working on your system. The static
7   -binary is preferred but this class should also work with the non static version,
8   -even though a lot of features will be missing.
9   -
10   -This project is sponsored by [PeoplePerHour](http://www.peopleperhour.com).
11   -
12   -## Basic use
13   -
14   -```php
15   -<?php
16   -$pdf = new WkHtmlToPdf;
17   -$pdf->addPage('http://google.com');
18   -$pdf->addPage('/home/joe/my.pdf');
19   -$pdf->addCover('mycover.pdf');
20   -$pdf->addToc();
21   -
22   -// Save the PDF
23   -$pdf->saveAs('/tmp/new.pdf');
24   -
25   -// Send to client for inline display
26   -$pdf->send();
27   -
28   -// Send to client as file download
29   -$pdf->send('test.pdf');
30   -```
31   -
32   -## Setting options
33   -
34   -```php
35   -<?php
36   -$pdf = new WkHtmlToPdf($options); // Set global PDF options
37   -$pdf->setOptions($options); // Set global PDF options (alternative)
38   -$pdf->setPageOptions($options); // Set global default page options
39   -$pdf->addPage($page, $options); // Set page options (overrides default page options)
40   -```
41   -
42   -### Example options
43   -
44   -```php
45   -<?php
46   -// See "wkhtmltopdf -H" for all available options
47   -$options=array(
48   - 'no-outline',
49   - 'margin-top' =>0,
50   - 'margin-right' =>0,
51   -);
52   -```
53   -
54   -### Extra global options
55   -
56   -* bin: path to the wkhtmltopdf binary. Defaults to `/usr/bin/wkhtmltopdf`.
57   -* tmp: path to tmp directory. Defaults to PHP temp dir.
58   -
59   -## Error handling
60   -
61   -`saveAs()` and `save()` will return false on error. In this case the detailed error message from wkhtmltopdf can be obtained through `getError()`.
62   -
63   -## Full example
64   -
65   -For me `wkhtmltopdf` seems to create best results with smart shrinking turned off.
66   -But then i had scaling issues which went away if i set all margins to zero and instead
67   -add the margins through CSS. We can also use `cm` in CSS as this is more apropriate for print styles.
68   -
69   -```php
70   -<?php
71   -$pdf = new WkHtmlToPdf(array(
72   - 'no-outline', // Don't let Chrome complain ...
73   - 'margin-top' => 0,
74   - 'margin-right' => 0,
75   - 'margin-bottom' => 0,
76   - 'margin-left' => 0,
77   -);
78   -
79   -$pdf->setPageOptions(array(
80   - 'disable-smart-shrinking',
81   - 'user-style-sheet' => 'pdf.css',
82   -);
83   -
84   -$pdf->addPage('demo.html');
85   -
86   -$pdf->send();
87   -```
88   -
89   -**demo.html**
90   -```html
91   -<!DOCTYPE html>
92   -<head>
93   -</head>
94   -<body>
95   -
96   - <div id="print-area">
97   - <div id="header">
98   - This is an example header.
99   - </div>
100   - <div id="content">
101   - <h1>Demo</h1>
102   - <p>This is example content</p>
103   - </div>
104   - <div id="footer">
105   - This is an example footer.
106   - </div>
107   - </div>
108   -
109   -</body>
110   -</html>
111   -```
112   -
113   -**pdf.css**
114   -```css
115   -/* Define page size. Requires print-area adjustment! */
116   -body {
117   - margin: 0;
118   - padding: 0;
119   - width: 21cm;
120   - height: 29.7cm;
121   -}
122   -
123   -/* Printable area */
124   -#print-area {
125   - position: relative;
126   - top: 1cm;
127   - left: 1cm;
128   - width: 19cm;
129   - height: 27.6cm;
130   -
131   - font-size: 10px;
132   - font-family: Arial;
133   -}
134   -
135   -#header {
136   - height: 3cm;
137   -
138   - background: #ccc;
139   -}
140   -#footer {
141   - position: absolute;
142   - bottom: 0;
143   - width: 100%;
144   - height: 3cm;
145   -
146   - background: #ccc;
147   -}
148   -```
  1 +Find documentation on the project page: http://mikehaertl.github.com/phpwkhtmltopdf/

0 comments on commit 9d2c07d

Please sign in to comment.
Something went wrong with that request. Please try again.