Skip to content

Commit fffce1b

Browse files
committed
Add example to README
1 parent 8dd13e7 commit fffce1b

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,88 @@ $options=array(
6060

6161
`saveAs()` and `save()` will return false on error. In this case the detailed error message from wkhtmltopdf can be obtained through `getError()`.
6262

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+
'margin-top' => 0,
73+
'margin-right' => 0,
74+
'margin-bottom' => 0,
75+
'margin-left' => 0,
76+
);
77+
78+
$pdf->setPageOptions(array(
79+
'disable-smart-shrinking',
80+
'user-style-sheet' => 'pdf.css',
81+
);
82+
83+
$pdf->addPage('demo.html');
84+
85+
$pdf->send();
86+
```
87+
88+
**demo.html**
89+
```html
90+
<!DOCTYPE html>
91+
<head>
92+
</head>
93+
<body>
94+
95+
<div id="print-area">
96+
<div id="header">
97+
This is an example header.
98+
</div>
99+
<div id="content">
100+
<h1>Demo</h1>
101+
<p>This is example content</p>
102+
</div>
103+
<div id="footer">
104+
This is an example footer.
105+
</div>
106+
</div>
107+
108+
</body>
109+
</html>
110+
```
111+
112+
**pdf.css**
113+
```css
114+
/* Define page size. Requires print-area adjustment! */
115+
body {
116+
margin: 0;
117+
padding: 0;
118+
width: 21cm;
119+
height: 29.7cm;
120+
}
121+
122+
/* Printable area */
123+
#print-area {
124+
position: relative;
125+
top: 1cm;
126+
left: 1cm;
127+
width: 19cm;
128+
height: 27.6cm;
129+
130+
font-size: 10px;
131+
font-family: Arial;
132+
}
133+
134+
#header {
135+
height: 3cm;
136+
137+
background: #ccc;
138+
}
139+
#footer {
140+
position: absolute;
141+
bottom: 0;
142+
width: 100%;
143+
height: 3cm;
144+
145+
background: #ccc;
146+
}
147+
```

0 commit comments

Comments
 (0)