blib/lib/WKHTMLTOPDF.pm untested

filter: Statementstmt 0.0% 0 / 85 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 89 CC 1 SCAR 6.9
CC
1
Cov
0%
generate
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1  
2 package WKHTMLTOPDF;
3  
4 use Moose;
5 with 'MooseX::Role::Cmd';
6  
7 our $VERSION = '0.02';
8  
9 =head1 NAME
10  
11 WKHTMLTOPDF - Perl interface to the wkhtmltopdf program for producing PDF-File from HTML-File.
12  
13 =head1 SYNOPSIS
14  
15 use WKHTMLTOPDF;
16  
17 my $pdf = new WKHTMLTOPDF;
18 $pdf->_input_file('test.html');
19 $pdf->_output_file('test.pdf');
20 $pdf->grayscale(1);
21  
22 $pdf->generate;
23  
24 =head1 DESCRIPTION
25  
26 Please, visit http://code.google.com/p/wkhtmltopdf/
27  
28 =cut
29  
30 use constant DEFAULT_BIN_NAME => '/usr/bin/wkhtmltopdf';
31  
32 =head1 ATTRIBUTES
33  
34 =head2 _input_file
35  
36 Path of input file.
37  
38 =cut
39  
40 has '_input_file' => ( is => 'rw', isa => 'Str' );
41  
42 =head2 _out_file
43  
44 Path of output file.
45  
46 =cut
47  
48 has '_output_file' => ( is => 'rw', isa => 'Str' );
49  
50 =head2 bin_name
51  
52 Sets the binary executable name for the command you want to run. Defaul is /usr/bin/wkhtmltopdf.
53  
54 =cut
55  
56 has 'bin_name' => ( is => 'rw', isa => 'Str', default => DEFAULT_BIN_NAME );
57  
58 =head2 General Options
59  
60 =head3 collate
61  
62 Collate when printing multiple copies.
63  
64 =cut
65  
66 has 'collate' => (is => 'rw', isa => 'Bool', default => 0);
67  
68 =head3 copies
69  
70 Number of copies to print into the pdf file. Default is 1.
71  
72 =cut
73  
74 has 'copies' => (is => 'rw', isa => 'Int');
75  
76 =head3 orientation
77  
78 Set orientation to Landscape or Portrait.
79  
80 =cut
81  
82 has 'orientation' => (is => 'rw', isa => 'Str');
83  
84 =head3 page-size
85  
86 Set paper size to: A4, Letter, etc.
87  
88 =cut
89  
90 has 'page-size' => (is => 'rw', isa => 'Str');
91  
92 =head3 proxy
93  
94 Use a proxy.
95  
96 =cut
97  
98 has 'proxy' => (is => 'rw', isa => 'Str');
99  
100 =head3 username
101  
102 HTTP Authentication username.
103  
104 =cut
105  
106 has 'username' => (is => 'rw', isa => 'Str');
107  
108 =head3 password
109  
110 HTTP Authentication password.
111  
112 =cut
113  
114 has 'password' => (is => 'rw', isa => 'Str');
115  
116 =head3 custom-header
117  
118 Set an additional HTTP header (repeatable).
119  
120 =cut
121  
122 has 'custom-header' => ( is => 'rw', isa => 'Str');
123  
124 =head3 book
125  
126 Set the options one would usually set when printing a book.
127  
128 =cut
129  
130 has 'book' => ( is => 'rw', isa => 'Bool', default => 0);
131  
132 =head3 cover
133  
134 Use html document as cover. It will be inserted before the toc with no headers and footers.
135  
136 =cut
137  
138 has 'cover' => (is => 'rw', isa => 'Str');
139  
140 =head3 default-header
141  
142 Add a default header, with the name of the page to the left, and the page number to the right, this is short for: --header-left='[webpage]' --header-right='[page]/[toPage]' --top 2cm --header-line.
143  
144 =cut
145  
146 has 'default-header' => (is => 'rw', isa => 'Bool', default => 0);
147  
148 =head3 toc
149  
150 Insert a table of content in the beginning of the document.
151  
152 =cut
153  
154 has 'toc' => (is => 'rw', isa => 'Bool', default => 0);
155  
156 =head3 dpi
157  
158 Change the dpi explicitly (this has no effect on X11 based systems).
159  
160 =cut
161  
162 has 'dpi' => (is => 'rw', isa => 'Str');
163  
164 =head3 disable-javascript
165  
166 Do not allow web pages to run javascript.
167  
168 =cut
169  
170 has 'disable-javascript' => (is => 'rw', isa => 'Bool', default => 0);
171  
172 =head3 grayscale
173  
174 PDF will be generated in grayscale.
175  
176 =cut
177  
178 has 'grayscale' => (is => 'rw', isa => 'Bool', default => 0);
179  
180 =head3 lowquality
181  
182 Generates lower quality pdf/ps. Useful to shrink the result document space.
183  
184 =cut
185  
186 has 'lowquality' => (is => 'rw', isa => 'Bool', default => 0);
187  
188 =head3 margin-bottom
189  
190 Set the page bottom margin (default 10mm).
191  
192 =cut
193  
194 has 'margin-bottom' => (is => 'rw', isa => 'Str');
195  
196 =head3 margin-left
197  
198 Set the page left margin (default 10mm).
199  
200 =cut
201  
202 has 'margin-left' => (is => 'rw', isa => 'Str');
203  
204 =head3 margin-right
205  
206 Set the page right margin (default 10mm).
207  
208 =cut
209  
210 has 'margin-right' => (is => 'rw', isa => 'Str');
211  
212 =head3 margin-top
213  
214 Set the page top margin (default 10mm).
215  
216 =cut
217  
218 has 'margin-top' => (is => 'rw', isa => 'Str');
219  
220 =head3 redirect-delay
221  
222 Wait some milliseconds for js-redirects (default 200).
223  
224 =cut
225  
226 has 'redirect-delay' => (is => 'rw', isa => 'Int');
227  
228 =head3 enable-plugins
229  
230 Enable installed plugins (such as flash).
231  
232 =cut
233  
234 has 'enable-plugins' => ( is => 'rw', isa => 'Bool', default => 0);
235  
236 =head3 zoom
237  
238 Use this zoom factor (default 1).
239  
240 =cut
241  
242 has 'zoom' => (is => 'rw', isa => 'Str');
243  
244 =head3 disable-internal-links
245  
246 Do no make local links.
247  
248 =cut
249  
250 has 'disable-internal-links' => (is => 'rw', isa => 'Bool', default => 0);
251  
252 =head3 disable-external-links
253  
254 Do no make links to remote web pages.
255  
256 =cut
257  
258 has 'disable-external-links' => (is => 'rw', isa => 'Bool', default => 0);
259  
260 =head3 print-media-type
261  
262 Use print media-type instead of screen.
263  
264 =cut
265  
266 has 'print-media-type' => (is => 'rw', isa => 'Bool', default => 0);
267  
268 =head3 page-offset
269  
270 Set the starting page number (default 1).
271  
272 =cut
273  
274 has 'page-offset' => (is => 'rw', isa => 'Int');
275  
276 =head3 disable-smart-shrinking
277  
278 Disable the intelligent shrinking strategy used by WebKit that makes the pixel/dpi ratio none constant.
279  
280 =cut
281  
282 has 'disable-smart-shrinking' => (is => 'rw', isa => 'Bool', default => 0);
283  
284 =head3 use-xserver
285  
286 Use the X server (some plugins and other stuff might not work without X11).
287  
288 =cut
289  
290 has 'use-xserver' => (is => 'rw', isa => 'Bool', default => 0);
291  
292 =head3 enconding
293  
294 Set the default text encoding, for input.
295  
296 =cut
297  
298 has 'encoding' => ( is => 'rw', isa => 'Str');
299  
300 =head3 no-background
301  
302 Do not print background.
303  
304 =cut
305  
306 has 'no-background' => (is => 'rw', isa => 'Bool', default => 0);
307  
308 =head3 user-style-sheet
309  
310 Specify a user style sheet, to load with every page.
311  
312 =cut
313  
314 has 'user-style-sheet' => (is => 'rw', isa => 'Str');
315  
316 =head2 Headers and footer options
317  
318 =head3 footer-center
319  
320 Centered footer text.
321  
322 =cut
323  
324 has 'footer-center' => (is => 'rw', isa => 'Str');
325  
326 =head3 footer-font-name
327  
328 Set footer font name (default Arial)
329  
330 =cut
331  
332 has 'footer-font-name' => (is => 'rw', isa => 'Str');
333  
334 =head3 footer-font-size
335  
336 Set footer font size (default 11)
337  
338 =cut
339  
340 has 'footer-font-size' => (is => 'rw', isa => 'Int');
341  
342 =head3 footer-left
343  
344 Left aligned footer text.
345  
346 =cut
347  
348 has 'footer-left' => (is => 'rw', isa => 'Str');
349  
350 =head3 footer-line
351  
352 Display line above the footer
353  
354 =cut
355  
356 has 'footer-line' => (is => 'rw', isa => 'Bool', default => 0);
357  
358 =head3 footer-right
359  
360 Right aligned footer text.
361  
362 =cut
363  
364 has 'footer-right' => (is => 'rw', isa => 'Str');
365  
366 =head3 footer-spacing
367  
368 Spacing between footer and content in mm (default 0).
369  
370 =cut
371  
372 has 'footer-spacing' => (is => 'rw', isa => 'Str');
373  
374 =head3 footer-html
375  
376 Adds a html footer.
377  
378 =cut
379  
380 has 'footer-html' => (is => 'rw', isa => 'Str');
381  
382  
383 =head3 header-center
384  
385 Centered header text.
386  
387 =cut
388  
389 has 'header-center' => (is => 'rw', isa => 'Str');
390  
391 =head3 header-font-name
392  
393 Set header font name (default Arial)
394  
395 =cut
396  
397 has 'header-font-name' => (is => 'rw', isa => 'Str');
398  
399 =head3 header-font-size
400  
401 Set header font size (default 11)
402  
403 =cut
404  
405 has 'header-font-size' => (is => 'rw', isa => 'Int');
406  
407 =head3 header-left
408  
409 Left aligned header text.
410  
411 =cut
412  
413 has 'header-left' => (is => 'rw', isa => 'Str');
414  
415 =head3 header-line
416  
417 Display line above the header.
418  
419 =cut
420  
421 has 'header-line' => (is => 'rw', isa => 'Bool', default => 0);
422  
423 =head3 header-right
424  
425 Right aligned header text.
426  
427 =cut
428  
429 has 'header-right' => (is => 'rw', isa => 'Str');
430  
431 =head3 header-spacing
432  
433 Spacing between header and content in mm (default 0).
434  
435 =cut
436  
437 has 'header-spacing' => (is => 'rw', isa => 'Str');
438  
439 =head3 header-html
440  
441 Adds a html header header.
442  
443 =cut
444  
445 has 'header-html' => (is => 'rw', isa => 'Str');
446  
447 =head2 Table of content options
448  
449 =head3 toc-font-name
450  
451 Set the font used for the toc (default Arial)
452  
453 =cut
454  
455 has 'toc-font-name' => (is => 'rw', isa => 'Str');
456  
457 =head3 toc-no-dots
458  
459 Do not use dots, in the toc
460  
461 =cut
462  
463 has 'toc-no-dots' => (is => 'rw', isa => 'Bool');
464  
465 =head3 toc-depth
466  
467 Set the depth of the toc (default 3).
468  
469 =cut
470  
471 has 'toc-depth' => (is => 'rw', isa => 'Int');
472  
473 =head3 toc-header-text
474  
475 The header text of the toc (default Table Of Contents).
476  
477 =cut
478  
479 has 'toc-header-text' => (is => 'rw', isa => 'Str');
480  
481 =head3 toc-header-fs
482  
483 The font size of the toc header (default 15).
484  
485 =cut
486  
487 has 'toc-hedaer-fs' => (is => 'rw', isa => 'Int');
488  
489 =head3 toc-disable-links
490  
491 Do not link from toc to sections
492  
493 =cut
494  
495 has 'toc-disable-links' => (is => 'rw', isa => 'Bool', default => 0);
496  
497 =head3 toc-disable-back-links
498  
499 Do not link from section header to toc.
500  
501 =cut
502  
503 has 'toc-disable-back-links' => (is => 'rw', isa => 'Bool', default => 0);
504  
505 =head3 toc-l1-font-size
506  
507 Set the font size on level 1 of the toc (default 12)
508  
509 =cut
510  
511 has 'toc-l1-font-size' => (is => 'rw', isa => 'Int');
512  
513 =head3 toc-l1-indentation
514  
515 Set indentation on level 1 of the toc (default 0)
516  
517 =cut
518  
519 has 'toc-l1-indentation' => (is => 'rw', isa => 'Int');
520  
521 =head3 toc-l2-font-size
522  
523 Set the font size on level 2 of the toc (default 10)
524  
525 =cut
526  
527 has 'toc-l2-font-size' => (is => 'rw', isa => 'Int');
528  
529 =head3 toc-l2-indentation
530  
531 Set indentation on level 2 of the toc (default 20)
532  
533 =cut
534  
535 has 'toc-l2-indentation' => (is => 'rw', isa => 'Int');
536  
537 =head3 toc-l3-font-size
538  
539 Set the font size on level 3 of the toc (default 8)
540  
541 =cut
542  
543 has 'toc-l3-font-size' => (is => 'rw', isa => 'Int');
544  
545 =head3 toc-l3-indentation
546  
547 Set indentation on level 3 of the toc (default 40)
548  
549 =cut
550  
551 has 'toc-l3-indentation' => (is => 'rw', isa => 'Int');
552  
553 =head3 toc-l4-font-size
554  
555 Set the font size on level 6 of the toc (default 6)
556  
557 =cut
558  
559 has 'toc-l4-font-size' => (is => 'rw', isa => 'Int');
560  
561 =head3 toc-l4-indentation
562  
563 Set indentation on level 4 of the toc (default 6)
564  
565 =cut
566  
567 has 'toc-l4-indentation' => (is => 'rw', isa => 'Int');
568  
569 =head3 toc-l5-font-size
570  
571 Set the font size on level 5 of the toc (default 4)
572  
573 =cut
574  
575 has 'toc-l5-font-size' => (is => 'rw', isa => 'Int');
576  
577 =head3 toc-l5-indentation
578  
579 Set indentation on level 5 of the toc (default 80)
580  
581 =cut
582  
583 has 'toc-l5-indentation' => (is => 'rw', isa => 'Int');
584  
585 =head3 toc-l6-font-size
586  
587 Set the font size on level 6 of the toc (default 2)
588  
589 =cut
590  
591 has 'toc-l6-font-size' => (is => 'rw', isa => 'Int');
592  
593 =head3 toc-l6-indentation
594  
595 Set indentation on level 6 of the toc (default 100)
596  
597 =cut
598  
599 has 'toc-l6-indentation' => (is => 'rw', isa => 'Int');
600  
601 =head3 toc-l7-font-size
602  
603 Set the font size on level 7 of the toc (default 0)
604  
605 =cut
606  
607 has 'toc-l7-font-size' => (is => 'rw', isa => 'Int');
608  
609 =head3 toc-l7-indentation
610  
611 Set indentation on level 7 of the toc (default 120)
612  
613 =cut
614  
615 has 'toc-l7-indentation' => (is => 'rw', isa => 'Int');
616  
617 =head2 Outline options
618  
619 =head3 outline
620  
621 Put an outline into the pdf.
622  
623 =cut
624  
625 has 'outline' => (is => 'rw', isa => 'Bool', default => 0);
626  
627 =head3 outline-depth
628  
629 Set the depth of the outline (default 4).
630  
631 =cut
632  
633 has 'outline-depth' => (is => 'rw', isa => 'Int');
634  
635 =head1 METHODS
636  
637 =head2 generate
638  
639 Generate the PDF-File form a HTML-File.
640  
641 =cut
642  
643 sub generate {
644 my $self = shift;
645 $self->run(($self->_input_file, $self->_output_file));
646  
647 }
648  
649 =head1 AUTHOR
650  
651 Thiago Rondon <thiago@aware.com.br>
652  
653 =head1 LICENSE
654  
655 This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
656  
657 =cut
658  
659  
660 1;
661