File Coverage

blib/lib/SelectPdf/HtmlToPdfClient.pm
Criterion Covered Total %
statement 12 365 3.2
branch 0 36 0.0
condition 0 36 0.0
subroutine 4 100 4.0
pod 95 96 98.9
total 111 633 17.5


line stmt bran cond sub pod time code
1             package SelectPdf::HtmlToPdfClient;
2            
3 1     1   71231 use SelectPdf::ApiClient;
  1         4  
  1         35  
4 1     1   479 use SelectPdf::AsyncJobClient;
  1         4  
  1         33  
5 1     1   421 use SelectPdf::WebElementsClient;
  1         4  
  1         33  
6 1     1   8 use strict;
  1         2  
  1         5154  
7             our @ISA = qw(SelectPdf::ApiClient);
8            
9             =head1 NAME
10            
11             SelectPdf::HtmlToPdfClient - Html To Pdf Conversion with SelectPdf Online API.
12            
13             =head1 SYNOPSIS
14            
15             Convert URL to PDF and save result into a file on disk.
16            
17             use SelectPdf;
18             print "This is SelectPdf-$SelectPdf::VERSION\n";
19            
20             my $url = "https://selectpdf.com/";
21             my $local_file = "Test.pdf";
22             my $apiKey = "Your API key here";
23            
24             eval {
25             my $client = new HtmlToPdfClient($apiKey);
26            
27             $client
28             ->setPageSize("A4")
29             ->setMargins(0)
30             ->setShowPageNumbers('False')
31             ->setPageBreaksEnhancedAlgorithm('True')
32             ;
33            
34             $client->convertUrlToFile($url, $local_file);
35             };
36            
37             if ($@) {
38             print "An error occurred: $@\n";
39             }
40            
41             Convert raw HTML string to PDF and save result into a file on disk.
42            
43             use SelectPdf;
44             print "This is SelectPdf-$SelectPdf::VERSION\n";
45            
46             my $html = "This is a test HTML.";
47             my $local_file = "Test.pdf";
48             my $apiKey = "Your API key here";
49            
50             eval {
51             my $client = new HtmlToPdfClient($apiKey);
52            
53             $client
54             ->setPageSize("A4")
55             ->setMargins(0)
56             ->setShowPageNumbers('False')
57             ->setPageBreaksEnhancedAlgorithm('True')
58             ;
59            
60             $client->convertHtmlStringToFile($html, $local_file);
61             };
62            
63             if ($@) {
64             print "An error occurred: $@\n";
65             }
66            
67             For more details and full list of parameters see L.
68            
69             =head1 METHODS
70            
71             =head2 new( $apiKey )
72            
73             Construct the Html To Pdf Client.
74            
75             my $client = SelectPdf::HtmlToPdfClient->new($apiKey);
76            
77             Parameters:
78            
79             - $apiKey API Key.
80             =cut
81             sub new {
82 0     0 1   my $type = shift;
83 0           my $self = $type->SUPER::new;
84            
85             # API endpoint
86 0           $self->{apiEndpoint} = "https://selectpdf.com/api2/convert/";
87            
88 0           $self->{parameters}{"key"} = shift;
89            
90 0           bless $self, $type;
91 0           return $self;
92             }
93            
94             =head2 convertUrl( $url )
95            
96             Convert the specified url to PDF.
97             SelectPdf online API can convert http:// and https:// publicly available urls.
98            
99             $content = $client->convertUrl($url);
100            
101             Parameters:
102            
103             - $url Address of the web page being converted.
104            
105             Returns:
106            
107             - Byte array containing the resulted PDF.
108             =cut
109             sub convertUrl($) {
110 0     0 1   my($self, $url) = @_;
111            
112 0           $self->{parameters}{"url"} = $url;
113 0           $self->{parameters}{"async"} = "False";
114 0           $self->{parameters}{"html"} = "";
115 0           $self->{parameters}{"base_url"} = "";
116            
117 0           return $self->SUPER::performPost();
118             }
119            
120             =head2 convertUrl( $url, $filePath )
121            
122             Convert the specified url to PDF and writes the resulted PDF to a local file.
123             SelectPdf online API can convert http:// and https:// publicly available urls.
124            
125             $client->convertUrlToFile($url, $filePath);
126            
127             Parameters:
128            
129             - $url Address of the web page being converted.
130            
131             - $filePath Local file including path if necessary.
132             =cut
133             sub convertUrlToFile($;$) {
134 0     0 0   my($self, $url, $filePath) = @_;
135            
136 0           my $content = $self->convertUrl($url);
137            
138 0 0         my $file = IO::File->new( $filePath, '>' ) or die "Unable to open output file - $!\n";
139 0           $file->binmode;
140 0           $file->print( $content );
141 0           $file->close;
142             }
143            
144             =head2 convertUrlAsync( $url )
145            
146             Convert the specified url to PDF using an asynchronous call.
147             SelectPdf online API can convert http:// and https:// publicly available urls.
148            
149             $content = $client->convertUrlAsync($url);
150            
151             Parameters:
152            
153             - $url Address of the web page being converted.
154            
155             Returns:
156            
157             - Byte array containing the resulted PDF.
158             =cut
159             sub convertUrlAsync($) {
160 0     0 1   my($self, $url) = @_;
161            
162 0           $self->{parameters}{"url"} = $url;
163 0           $self->{parameters}{"html"} = "";
164 0           $self->{parameters}{"base_url"} = "";
165            
166 0 0         my $JobID = $self->SUPER::startAsyncJob() or die "An error occurred launching the asynchronous call.";
167            
168 0           my $noPings = 0;
169            
170             do
171             {
172 0           $noPings++;
173            
174             # sleep for a few seconds before next ping
175 0           sleep($self->{AsyncCallsPingInterval});
176            
177 0           my $asyncJobClient = new SelectPdf::AsyncJobClient($self->{parameters}{"key"}, $JobID);
178 0           $asyncJobClient->setApiEndpoint($self->{apiAsyncEndpoint});
179            
180 0           my $result = $asyncJobClient->getResult();
181            
182 0 0         if ($asyncJobClient->finished)
183             {
184 0           $self->{numberOfPages} = $asyncJobClient->getNumberOfPages();
185            
186 0           return $result;
187             }
188            
189 0           } while ($noPings <= $self->{AsyncCallsMaxPings});
190            
191 0           die "Asynchronous call did not finish in expected timeframe.";
192            
193             }
194            
195             =head2 convertUrlToFileAsync( $url, $filePath )
196            
197             Convert the specified url to PDF using an asynchronous call and writes the resulted PDF to a local file.
198             SelectPdf online API can convert http:// and https:// publicly available urls.
199            
200             $client->convertUrlToFileAsync($url, $filePath);
201            
202             Parameters:
203            
204             - $url Address of the web page being converted.
205            
206             - $filePath Local file including path if necessary.
207             =cut
208             sub convertUrlToFileAsync($;$) {
209 0     0 1   my($self, $url, $filePath) = @_;
210            
211 0           my $content = $self->convertUrlAsync($url);
212            
213 0 0         my $file = IO::File->new( $filePath, '>' ) or die "Unable to open output file - $!\n";
214 0           $file->binmode;
215 0           $file->print( $content );
216 0           $file->close;
217             }
218            
219             =head2 convertHtmlStringWithBaseUrl( $htmlString, $baseUrl )
220            
221             Convert the specified HTML string to PDF. Use a base url to resolve relative paths to resources.
222            
223             $content = $client->convertHtmlStringWithBaseUrl($htmlString, $baseUrl);
224            
225             Parameters:
226            
227             - $htmlString HTML string with the content being converted.
228            
229             - $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.
230            
231             Returns:
232            
233             - Byte array containing the resulted PDF.
234             =cut
235             sub convertHtmlStringWithBaseUrl($,$) {
236 0     0 1   my($self, $htmlString, $baseUrl) = @_;
237            
238 0           $self->{parameters}{"url"} = "";
239 0           $self->{parameters}{"async"} = "False";
240 0           $self->{parameters}{"html"} = $htmlString;
241 0           $self->{parameters}{"base_url"} = $baseUrl;
242            
243 0           return $self->SUPER::performPost();
244             }
245            
246             =head2 convertHtmlStringWithBaseUrlToFile( $htmlString, $baseUrl, $filePath )
247            
248             Convert the specified HTML string to PDF and writes the resulted PDF to a local file. Use a base url to resolve relative paths to resources.
249            
250             $client->convertHtmlStringWithBaseUrlToFile($htmlString, $baseUrl, $filePath);
251            
252             Parameters:
253            
254             - $htmlString HTML string with the content being converted.
255            
256             - $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.
257            
258             - $filePath: Local file including path if necessary.
259            
260             =cut
261             sub convertHtmlStringWithBaseUrlToFile($,$,$) {
262 0     0 1   my($self, $htmlString, $baseUrl, $filePath) = @_;
263            
264 0           my $content = $self->convertHtmlStringWithBaseUrl($htmlString, $baseUrl);
265            
266 0 0         my $file = IO::File->new( $filePath, '>' ) or die "Unable to open output file - $!\n";
267 0           $file->binmode;
268 0           $file->print( $content );
269 0           $file->close;
270             }
271            
272             =head2 convertHtmlStringWithBaseUrlAsync( $htmlString, $baseUrl )
273            
274             Convert the specified HTML string to PDF with an asynchronous call. Use a base url to resolve relative paths to resources.
275            
276             $content = $client->convertHtmlStringWithBaseUrlAsync($htmlString, $baseUrl);
277            
278             Parameters:
279            
280             - $htmlString HTML string with the content being converted.
281            
282             - $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.
283            
284             Returns:
285            
286             - Byte array containing the resulted PDF.
287             =cut
288             sub convertHtmlStringWithBaseUrlAsync($,$) {
289 0     0 1   my($self, $htmlString, $baseUrl) = @_;
290            
291 0           $self->{parameters}{"url"} = "";
292 0           $self->{parameters}{"async"} = "False";
293 0           $self->{parameters}{"html"} = $htmlString;
294 0           $self->{parameters}{"base_url"} = $baseUrl;
295            
296 0 0         my $JobID = $self->SUPER::startAsyncJob() or die "An error occurred launching the asynchronous call.";
297            
298 0           my $noPings = 0;
299            
300             do
301             {
302 0           $noPings++;
303            
304             # sleep for a few seconds before next ping
305 0           sleep($self->{AsyncCallsPingInterval});
306            
307 0           my $asyncJobClient = new SelectPdf::AsyncJobClient($self->{parameters}{"key"}, $JobID);
308 0           $asyncJobClient->setApiEndpoint($self->{apiAsyncEndpoint});
309            
310 0           my $result = $asyncJobClient->getResult();
311            
312 0 0         if ($asyncJobClient->finished)
313             {
314 0           $self->{numberOfPages} = $asyncJobClient->getNumberOfPages();
315            
316 0           return $result;
317             }
318            
319 0           } while ($noPings <= $self->{AsyncCallsMaxPings});
320            
321 0           die "Asynchronous call did not finish in expected timeframe.";
322            
323             }
324            
325             =head2 convertHtmlStringWithBaseUrlToFileAsync( $htmlString, $baseUrl, $filePath )
326            
327             Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file. Use a base url to resolve relative paths to resources.
328            
329             $client->convertHtmlStringWithBaseUrlToFileAsync($htmlString, $baseUrl, $filePath);
330            
331             Parameters:
332            
333             - $htmlString HTML string with the content being converted.
334            
335             - $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.
336            
337             - $filePath: Local file including path if necessary.
338            
339             =cut
340             sub convertHtmlStringWithBaseUrlToFileAsync($,$,$) {
341 0     0 1   my($self, $htmlString, $baseUrl, $filePath) = @_;
342            
343 0           my $content = $self->convertHtmlStringWithBaseUrlAsync($htmlString, $baseUrl);
344            
345 0 0         my $file = IO::File->new( $filePath, '>' ) or die "Unable to open output file - $!\n";
346 0           $file->binmode;
347 0           $file->print( $content );
348 0           $file->close;
349             }
350            
351             =head2 convertHtmlString( $htmlString )
352            
353             Convert the specified HTML string to PDF.
354            
355             $content = $client->convertHtmlString($htmlString);
356            
357             Parameters:
358            
359             - $htmlString HTML string with the content being converted.
360            
361             Returns:
362            
363             - Byte array containing the resulted PDF.
364             =cut
365             sub convertHtmlString($) {
366 0     0 1   my($self, $htmlString) = @_;
367            
368 0           return $self->convertHtmlStringWithBaseUrl($htmlString, "");
369             }
370            
371             =head2 convertHtmlStringToFile( $htmlString, $filePath )
372            
373             Convert the specified HTML string to PDF and writes the resulted PDF to a local file.
374            
375             $client->convertHtmlStringToFile($htmlString, $filePath);
376            
377             Parameters:
378            
379             - $htmlString HTML string with the content being converted.
380            
381             - $filePath: Local file including path if necessary.
382            
383             =cut
384             sub convertHtmlStringToFile($,$) {
385 0     0 1   my($self, $htmlString, $filePath) = @_;
386            
387 0           $self->convertHtmlStringWithBaseUrlToFile($htmlString, "", $filePath);
388             }
389            
390             =head2 convertHtmlStringAsync( $htmlString )
391            
392             Convert the specified HTML string to PDF with an asynchronous call.
393            
394             $content = $client->convertHtmlStringAsync($htmlString);
395            
396             Parameters:
397            
398             - $htmlString HTML string with the content being converted.
399            
400             Returns:
401            
402             - Byte array containing the resulted PDF.
403             =cut
404             sub convertHtmlStringAsync($) {
405 0     0 1   my($self, $htmlString) = @_;
406            
407 0           return $self->convertHtmlStringWithBaseUrlAsync($htmlString, "");
408             }
409            
410             =head2 convertHtmlStringToFileAsync( $htmlString, $filePath )
411            
412             Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file.
413            
414             $client->convertHtmlStringToFileAsync($htmlString, $filePath);
415            
416             Parameters:
417            
418             - $htmlString HTML string with the content being converted.
419            
420             - $filePath: Local file including path if necessary.
421            
422             =cut
423             sub convertHtmlStringToFileAsync($,$) {
424 0     0 1   my($self, $htmlString, $filePath) = @_;
425            
426 0           $self->convertHtmlStringWithBaseUrlToFileAsync($htmlString, "", $filePath);
427             }
428            
429             =head2 setPageSize( $pageSize )
430            
431             Set PDF page size. Default value is A4. If page size is set to Custom, use setPageWidth and setPageHeight methods to set the custom width/height of the PDF pages.
432            
433             Parameters:
434            
435             - $pageSize: PDF page size. Possible values: Custom, A0, A1, A2, A3, A4, A5, A6, A7, A8, Letter, HalfLetter, Ledger, Legal.
436            
437             Returns:
438            
439             - Reference to the current object.
440             =cut
441             sub setPageSize($) {
442 0     0 1   my($self, $pageSize) = @_;
443            
444 0 0         if ($pageSize !~ m/^(Custom|A0|A1|A2|A3|A4|A5|A6|A7|A8|Letter|HalfLetter|Ledger|Legal)$/i) {
445 0           die ("Allowed values for Page Size: Custom, A0, A1, A2, A3, A4, A5, A6, A7, A8, Letter, HalfLetter, Ledger, Legal.");
446             }
447            
448 0           $self->{parameters}{"page_size"} = $pageSize;
449 0           return $self;
450             }
451            
452             =head2 setPageWidth( $pageWidth )
453            
454             Set PDF page width in points. Default value is 595pt (A4 page width in points). 1pt = 1/72 inch.
455             This is taken into account only if page size is set to Custom using setPageSize method.
456            
457             Parameters:
458            
459             - $pageWidth: Page width in points.
460            
461             Returns:
462            
463             - Reference to the current object.
464             =cut
465             sub setPageWidth($) {
466 0     0 1   my($self, $pageWidth) = @_;
467            
468 0           $self->{parameters}{"page_width"} = $pageWidth;
469 0           return $self;
470             }
471            
472             =head2 setPageHeight( $pageHeight )
473            
474             Set PDF page height in points. Default value is 842pt (A4 page height in points). 1pt = 1/72 inch.
475             This is taken into account only if page size is set to Custom using setPageSize method.
476            
477             Parameters:
478            
479             - $pageHeight: Page height in points.
480            
481             Returns:
482            
483             - Reference to the current object.
484             =cut
485             sub setPageHeight($) {
486 0     0 1   my($self, $pageHeight) = @_;
487            
488 0           $self->{parameters}{"page_height"} = $pageHeight;
489 0           return $self;
490             }
491            
492             =head2 setPageOrientation( $pageOrientation )
493            
494             Set PDF page orientation. Default value is Portrait.
495            
496             Parameters:
497            
498             - $pageOrientation: PDF page orientation. Possible values: Portrait, Landscape.
499            
500             Returns:
501            
502             - Reference to the current object.
503             =cut
504             sub setPageOrientation($) {
505 0     0 1   my($self, $pageOrientation) = @_;
506            
507 0 0         if ($pageOrientation !~ m/^(Portrait|Landscape)$/i) {
508 0           die ("Allowed values for Page Orientation: Portrait, Landscape.");
509             }
510            
511 0           $self->{parameters}{"page_orientation"} = $pageOrientation;
512 0           return $self;
513             }
514            
515             =head2 setMarginTop( $marginTop )
516            
517             Set top margin of the PDF pages. Default value is 5pt.
518            
519             Parameters:
520            
521             - $marginTop: Margin value in points. 1pt = 1/72 inch.
522            
523             Returns:
524            
525             - Reference to the current object.
526             =cut
527             sub setMarginTop($) {
528 0     0 1   my($self, $marginTop) = @_;
529            
530 0           $self->{parameters}{"margin_top"} = $marginTop;
531 0           return $self;
532             }
533            
534             =head2 setMarginRight( $marginRight )
535            
536             Set right margin of the PDF pages. Default value is 5pt.
537            
538             Parameters:
539            
540             - $marginRight: Margin value in points. 1pt = 1/72 inch.
541            
542             Returns:
543            
544             - Reference to the current object.
545             =cut
546             sub setMarginRight($) {
547 0     0 1   my($self, $marginRight) = @_;
548            
549 0           $self->{parameters}{"margin_right"} = $marginRight;
550 0           return $self;
551             }
552            
553             =head2 setMarginBottom( $marginBottom )
554            
555             Set bottom margin of the PDF pages. Default value is 5pt.
556            
557             Parameters:
558            
559             - $marginBottom: Margin value in points. 1pt = 1/72 inch.
560            
561             Returns:
562            
563             - Reference to the current object.
564             =cut
565             sub setMarginBottom($) {
566 0     0 1   my($self, $marginBottom) = @_;
567            
568 0           $self->{parameters}{"margin_bottom"} = $marginBottom;
569 0           return $self;
570             }
571            
572             =head2 setMarginLeft( $marginLeft )
573            
574             Set left margin of the PDF pages. Default value is 5pt.
575            
576             Parameters:
577            
578             - $marginLeft: Margin value in points. 1pt = 1/72 inch.
579            
580             Returns:
581            
582             - Reference to the current object.
583             =cut
584             sub setMarginLeft($) {
585 0     0 1   my($self, $marginLeft) = @_;
586            
587 0           $self->{parameters}{"margin_left"} = $marginLeft;
588 0           return $self;
589             }
590            
591             =head2 setMargins( $margin )
592            
593             Set all margins of the PDF pages to the same value. Default value is 5pt.
594            
595             Parameters:
596            
597             - $margin: Margin value in points. 1pt = 1/72 inch.
598            
599             Returns:
600            
601             - Reference to the current object.
602             =cut
603             sub setMargins($) {
604 0     0 1   my($self, $margin) = @_;
605            
606 0           return $self->setMarginTop($margin)->setMarginRight($margin)->setMarginBottom($margin)->setMarginLeft($margin);
607             }
608            
609             =head2 setPdfName( $pdfName )
610            
611             Specify the name of the pdf document that will be created. The default value is Document.pdf.
612            
613             Parameters:
614            
615             - $pdfName: Name of the generated PDF document.
616            
617             Returns:
618            
619             - Reference to the current object.
620             =cut
621             sub setPdfName($) {
622 0     0 1   my($self, $pdfName) = @_;
623            
624 0           $self->{parameters}{"pdf_name"} = $pdfName;
625 0           return $self;
626             }
627            
628             =head2 setRenderingEngine( $renderingEngine )
629            
630             Set the rendering engine used for the HTML to PDF conversion. Default value is WebKit.
631            
632             Parameters:
633            
634             - $renderingEngine: HTML rendering engine. Possible values: WebKit, Restricted, Blink.
635            
636             Returns:
637            
638             - Reference to the current object.
639             =cut
640             sub setRenderingEngine($) {
641 0     0 1   my($self, $renderingEngine) = @_;
642            
643 0 0         if ($renderingEngine !~ m/^(WebKit|Restricted|Blink)$/i) {
644 0           die ("Allowed values for Rendering Engine: WebKit, Restricted, Blink.");
645             }
646            
647 0           $self->{parameters}{"engine"} = $renderingEngine;
648 0           return $self;
649             }
650            
651             =head2 setUserPassword( $userPassword )
652            
653             Set PDF user password.
654            
655             Parameters:
656            
657             - $userPassword: PDF user password.
658            
659             Returns:
660            
661             - Reference to the current object.
662             =cut
663             sub setUserPassword($) {
664 0     0 1   my($self, $userPassword) = @_;
665            
666 0           $self->{parameters}{"user_password"} = $userPassword;
667 0           return $self;
668             }
669            
670             =head2 setOwnerPassword( $ownerPassword )
671            
672             Set PDF owner password.
673            
674             Parameters:
675            
676             - $ownerPassword: PDF owner password.
677            
678             Returns:
679            
680             - Reference to the current object.
681             =cut
682             sub setOwnerPassword($) {
683 0     0 1   my($self, $ownerPassword) = @_;
684            
685 0           $self->{parameters}{"owner_password"} = $ownerPassword;
686 0           return $self;
687             }
688            
689             =head2 setWebPageWidth( $webPageWidth )
690            
691             Set the width used by the converter's internal browser window in pixels. The default value is 1024px.
692            
693             Parameters:
694            
695             - $webPageWidth: Browser window width in pixels.
696            
697             Returns:
698            
699             - Reference to the current object.
700             =cut
701             sub setWebPageWidth($) {
702 0     0 1   my($self, $webPageWidth) = @_;
703            
704 0           $self->{parameters}{"web_page_width"} = $webPageWidth;
705 0           return $self;
706             }
707            
708             =head2 setWebPageHeight( $webPageHeight )
709            
710             Set the height used by the converter's internal browser window in pixels.
711             The default value is 0px and it means that the page height is automatically calculated by the converter.
712            
713             Parameters:
714            
715             - $webPageHeight: Browser window height in pixels. Set it to 0px to automatically calculate page height.
716            
717             Returns:
718            
719             - Reference to the current object.
720             =cut
721             sub setWebPageHeight($) {
722 0     0 1   my($self, $webPageHeight) = @_;
723            
724 0           $self->{parameters}{"web_page_height"} = $webPageHeight;
725 0           return $self;
726             }
727            
728             =head2 setMinLoadTime( $minLoadTime )
729            
730             Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load. This method is an alias for setConversionDelay.
731             The default value is 1 second. Use a larger value if the web page has content that takes time to render when it is displayed in the browser.
732            
733             Parameters:
734            
735             - $minLoadTime: Delay in seconds.
736            
737             Returns:
738            
739             - Reference to the current object.
740             =cut
741             sub setMinLoadTime($) {
742 0     0 1   my($self, $minLoadTime) = @_;
743            
744 0           $self->{parameters}{"min_load_time"} = $minLoadTime;
745 0           return $self;
746             }
747            
748             =head2 setConversionDelay( $delay )
749            
750             Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load. This method is an alias for setMinLoadTime.
751             The default value is 1 second. Use a larger value if the web page has content that takes time to render when it is displayed in the browser.
752            
753             Parameters:
754            
755             - $delay: Delay in seconds.
756            
757             Returns:
758            
759             - Reference to the current object.
760             =cut
761             sub setConversionDelay($) {
762 0     0 1   my($self, $delay) = @_;
763            
764 0           return $self->setMinLoadTime($delay);
765             }
766            
767             =head2 setMaxLoadTime( $maxLoadTime )
768            
769             Set the maximum amount of time (in seconds) that the convert will wait for the page to load. This method is an alias for setNavigationTimeout.
770             A timeout error is displayed when this time elapses. The default value is 30 seconds.
771             Use a larger value (up to 120 seconds allowed) for pages that take a long time to load.
772            
773             Parameters:
774            
775             - $maxLoadTime: Timeout in seconds.
776            
777             Returns:
778            
779             - Reference to the current object.
780             =cut
781             sub setMaxLoadTime($) {
782 0     0 1   my($self, $maxLoadTime) = @_;
783            
784 0           $self->{parameters}{"max_load_time"} = $maxLoadTime;
785 0           return $self;
786             }
787            
788             =head2 setNavigationTimeout( $timeout )
789            
790             Set the maximum amount of time (in seconds) that the convert will wait for the page to load. This method is an alias for setMaxLoadTime.
791             A timeout error is displayed when this time elapses. The default value is 30 seconds.
792             Use a larger value (up to 120 seconds allowed) for pages that take a long time to load.
793            
794             Parameters:
795            
796             - $timeout: Timeout in seconds.
797            
798             Returns:
799            
800             - Reference to the current object.
801             =cut
802             sub setNavigationTimeout($) {
803 0     0 1   my($self, $timeout) = @_;
804            
805 0           return $self->setMaxLoadTime($timeout);
806             }
807            
808             =head2 setSecureProtocol( $secureProtocol )
809            
810             Set the protocol used for secure (HTTPS) connections. Set this only if you have an older server that only works with older SSL connections.
811            
812             Parameters:
813            
814             - $secureProtocol: Secure protocol. Possible values: 0 (TLS 1.1 or newer), 1 (TLS 1.0), 2 (SSL v3 only).
815            
816             Returns:
817            
818             - Reference to the current object.
819             =cut
820             sub setSecureProtocol($) {
821 0     0 1   my($self, $secureProtocol) = @_;
822            
823 0 0 0       if ($secureProtocol ne 0 and $secureProtocol ne 1 and $secureProtocol ne 2) {
      0        
824 0           die ("Allowed values for Secure Protocol: 0 (TLS 1.1 or newer), 1 (TLS 1.0), 2 (SSL v3 only).");
825             }
826            
827 0           $self->{parameters}{"protocol"} = $secureProtocol;
828 0           return $self;
829             }
830            
831             =head2 setUseCssPrint( $useCssPrint )
832            
833             Specify if the CSS Print media type is used instead of the Screen media type. The default value is False.
834            
835             Parameters:
836            
837             - $useCssPrint: Use CSS Print media or not.
838            
839             Returns:
840            
841             - Reference to the current object.
842             =cut
843             sub setUseCssPrint($) {
844 0     0 1   my($self, $useCssPrint) = @_;
845            
846 0           $self->{parameters}{"use_css_print"} = $self->SUPER::serializeBoolean($useCssPrint);
847 0           return $self;
848             }
849            
850             =head2 setBackgroundColor( $backgroundColor )
851            
852             Specify the background color of the PDF page in RGB html format. The default is #FFFFFF.
853            
854             Parameters:
855            
856             - $backgroundColor: Background color in #RRGGBB format.
857            
858             Returns:
859            
860             - Reference to the current object.
861             =cut
862             sub setBackgroundColor($) {
863 0     0 1   my($self, $backgroundColor) = @_;
864            
865 0 0         if ($backgroundColor !~ m/^#?[0-9a-fA-F]{6}$/) {
866 0           die ("Color value must be in #RRGGBB format.");
867             }
868            
869 0           $self->{parameters}{"background_color"} = $backgroundColor;
870 0           return $self;
871             }
872            
873             =head2 setDrawHtmlBackground( $drawHtmlBackground )
874            
875             Set a flag indicating if the web page background is rendered in PDF. The default value is True.
876            
877             Parameters:
878            
879             - $drawHtmlBackground: Draw the HTML background or not.
880            
881             Returns:
882            
883             - Reference to the current object.
884             =cut
885             sub setDrawHtmlBackground($) {
886 0     0 1   my($self, $drawHtmlBackground) = @_;
887            
888 0           $self->{parameters}{"draw_html_background"} = $self->SUPER::serializeBoolean($drawHtmlBackground);
889 0           return $self;
890             }
891            
892             =head2 setDisableJavascript( $disableJavascript )
893            
894             Do not run JavaScript in web pages. The default value is False and javascript is executed.
895            
896             Parameters:
897            
898             - $disableJavascript: Disable javascript or not.
899            
900             Returns:
901            
902             - Reference to the current object.
903             =cut
904             sub setDisableJavascript($) {
905 0     0 1   my($self, $disableJavascript) = @_;
906            
907 0           $self->{parameters}{"disable_javascript"} = $self->SUPER::serializeBoolean($disableJavascript);
908 0           return $self;
909             }
910            
911             =head2 setDisableInternalLinks( $disableInternalLinks )
912            
913             Do not create internal links in the PDF. The default value is False and internal links are created.
914            
915             Parameters:
916            
917             - $disableInternalLinks: Disable internal links or not.
918            
919             Returns:
920            
921             - Reference to the current object.
922             =cut
923             sub setDisableInternalLinks($) {
924 0     0 1   my($self, $disableInternalLinks) = @_;
925            
926 0           $self->{parameters}{"disable_internal_links"} = $self->SUPER::serializeBoolean($disableInternalLinks);
927 0           return $self;
928             }
929            
930             =head2 setDisableExternalLinks( $disableExternalLinks )
931            
932             Do not create external links in the PDF. The default value is False and external links are created.
933            
934             Parameters:
935            
936             - $disableExternalLinks: Disable external links or not.
937            
938             Returns:
939            
940             - Reference to the current object.
941             =cut
942             sub setDisableExternalLinks($) {
943 0     0 1   my($self, $disableExternalLinks) = @_;
944            
945 0           $self->{parameters}{"disable_external_links"} = $self->SUPER::serializeBoolean($disableExternalLinks);
946 0           return $self;
947             }
948            
949             =head2 setRenderOnTimeout( $renderOnTimeout )
950            
951             Try to render the PDF even in case of the web page loading timeout. The default value is False and an exception is raised in case of web page navigation timeout.
952            
953             Parameters:
954            
955             - $renderOnTimeout: Render in case of timeout or not.
956            
957             Returns:
958            
959             - Reference to the current object.
960             =cut
961             sub setRenderOnTimeout($) {
962 0     0 1   my($self, $renderOnTimeout) = @_;
963            
964 0           $self->{parameters}{"render_on_timeout"} = $self->SUPER::serializeBoolean($renderOnTimeout);
965 0           return $self;
966             }
967            
968             =head2 setKeepImagesTogether( $keepImagesTogether )
969            
970             Avoid breaking images between PDF pages. The default value is False and images are split between pages if larger.
971            
972             Parameters:
973            
974             - $keepImagesTogether: Try to keep images on same page or not.
975            
976             Returns:
977            
978             - Reference to the current object.
979             =cut
980             sub setKeepImagesTogether($) {
981 0     0 1   my($self, $keepImagesTogether) = @_;
982            
983 0           $self->{parameters}{"keep_images_together"} = $self->SUPER::serializeBoolean($keepImagesTogether);
984 0           return $self;
985             }
986            
987             =head2 setDocTitle( $docTitle )
988            
989             Set the PDF document title.
990            
991             Parameters:
992            
993             - $docTitle: Document title.
994            
995             Returns:
996            
997             - Reference to the current object.
998             =cut
999             sub setDocTitle($) {
1000 0     0 1   my($self, $docTitle) = @_;
1001            
1002 0           $self->{parameters}{"doc_title"} = $docTitle;
1003 0           return $self;
1004             }
1005            
1006             =head2 setDocSubject( $docSubject )
1007            
1008             Set the PDF document subject.
1009            
1010             Parameters:
1011            
1012             - $docSubject: Document subject.
1013            
1014             Returns:
1015            
1016             - Reference to the current object.
1017             =cut
1018             sub setDocSubject($) {
1019 0     0 1   my($self, $docSubject) = @_;
1020            
1021 0           $self->{parameters}{"doc_subject"} = $docSubject;
1022 0           return $self;
1023             }
1024            
1025             =head2 setDocKeywords( $docKeywords )
1026            
1027             Set the PDF document keywords.
1028            
1029             Parameters:
1030            
1031             - $docKeywords: Document keywords.
1032            
1033             Returns:
1034            
1035             - Reference to the current object.
1036             =cut
1037             sub setDocKeywords($) {
1038 0     0 1   my($self, $docKeywords) = @_;
1039            
1040 0           $self->{parameters}{"doc_keywords"} = $docKeywords;
1041 0           return $self;
1042             }
1043            
1044             =head2 setDocAuthor( $docAuthor )
1045            
1046             Set the PDF document author.
1047            
1048             Parameters:
1049            
1050             - $docAuthor: Document author.
1051            
1052             Returns:
1053            
1054             - Reference to the current object.
1055             =cut
1056             sub setDocAuthor($) {
1057 0     0 1   my($self, $docAuthor) = @_;
1058            
1059 0           $self->{parameters}{"doc_author"} = $docAuthor;
1060 0           return $self;
1061             }
1062            
1063             =head2 setDocAddCreationDate( $docAddCreationDate )
1064            
1065             Add the date and time when the PDF document was created to the PDF document information. The default value is False.
1066            
1067             Parameters:
1068            
1069             - $docAddCreationDate: Add creation date to the document metadata or not.
1070            
1071             Returns:
1072            
1073             - Reference to the current object.
1074             =cut
1075             sub setDocAddCreationDate($) {
1076 0     0 1   my($self, $docAddCreationDate) = @_;
1077            
1078 0           $self->{parameters}{"doc_add_creation_date"} = $self->SUPER::serializeBoolean($docAddCreationDate);
1079 0           return $self;
1080             }
1081            
1082             =head2 setViewerPageLayout( $pageLayout )
1083            
1084             Set the page layout to be used when the document is opened in a PDF viewer. The default value is 1 - OneColumn.
1085            
1086             Parameters:
1087            
1088             - $pageLayout: Page layout. Possible values: 0 (Single Page), 1 (One Column), 2 (Two Column Left), 3 (Two Column Right).
1089            
1090             Returns:
1091            
1092             - Reference to the current object.
1093             =cut
1094             sub setViewerPageLayout($) {
1095 0     0 1   my($self, $pageLayout) = @_;
1096            
1097 0 0 0       if ($pageLayout ne 0 and $pageLayout ne 1 and $pageLayout ne 2 and $pageLayout ne 3) {
      0        
      0        
1098 0           die ("Allowed values for Page Layout: 0 (Single Page), 1 (One Column), 2 (Two Column Left), 3 (Two Column Right).");
1099             }
1100            
1101 0           $self->{parameters}{"viewer_page_layout"} = $pageLayout;
1102 0           return $self;
1103             }
1104            
1105             =head2 setViewerPageMode( $pageMode )
1106            
1107             Set the document page mode when the pdf document is opened in a PDF viewer. The default value is 0 - UseNone.
1108            
1109             Parameters:
1110            
1111             - $pageMode: Page mode. Possible values: 0 (Use None), 1 (Use Outlines), 2 (Use Thumbs), 3 (Full Screen), 4 (Use OC), 5 (Use Attachments).
1112            
1113             Returns:
1114            
1115             - Reference to the current object.
1116             =cut
1117             sub setViewerPageMode($) {
1118 0     0 1   my($self, $pageMode) = @_;
1119            
1120 0 0 0       if ($pageMode ne 0 and $pageMode ne 1 and $pageMode ne 2 and $pageMode ne 3 and $pageMode ne 4 and $pageMode ne 5) {
      0        
      0        
      0        
      0        
1121 0           die ("Allowed values for Page Mode: 0 (Use None), 1 (Use Outlines), 2 (Use Thumbs), 3 (Full Screen), 4 (Use OC), 5 (Use Attachments).");
1122             }
1123            
1124 0           $self->{parameters}{"viewer_page_mode"} = $pageMode;
1125 0           return $self;
1126             }
1127            
1128             =head2 setViewerCenterWindow( $viewerCenterWindow )
1129            
1130             Set a flag specifying whether to position the document's window in the center of the screen. The default value is False.
1131            
1132             Parameters:
1133            
1134             - $viewerCenterWindow: Center window or not.
1135            
1136             Returns:
1137            
1138             - Reference to the current object.
1139             =cut
1140             sub setViewerCenterWindow($) {
1141 0     0 1   my($self, $viewerCenterWindow) = @_;
1142            
1143 0           $self->{parameters}{"viewer_center_window"} = $self->SUPER::serializeBoolean($viewerCenterWindow);
1144 0           return $self;
1145             }
1146            
1147             =head2 setViewerDisplayDocTitle( $viewerDisplayDocTitle )
1148            
1149             Set a flag specifying whether the window's title bar should display the document title taken from document information. The default value is False.
1150            
1151             Parameters:
1152            
1153             - $viewerDisplayDocTitle: Display title or not.
1154            
1155             Returns:
1156            
1157             - Reference to the current object.
1158             =cut
1159             sub setViewerDisplayDocTitle($) {
1160 0     0 1   my($self, $viewerDisplayDocTitle) = @_;
1161            
1162 0           $self->{parameters}{"viewer_display_doc_title"} = $self->SUPER::serializeBoolean($viewerDisplayDocTitle);
1163 0           return $self;
1164             }
1165            
1166             =head2 setViewerFitWindow( $viewerFitWindow )
1167            
1168             Set a flag specifying whether to resize the document's window to fit the size of the first displayed page. The default value is False.
1169            
1170             Parameters:
1171            
1172             - $viewerFitWindow: Fit window or not.
1173            
1174             Returns:
1175            
1176             - Reference to the current object.
1177             =cut
1178             sub setViewerFitWindow($) {
1179 0     0 1   my($self, $viewerFitWindow) = @_;
1180            
1181 0           $self->{parameters}{"viewer_fit_window"} = $self->SUPER::serializeBoolean($viewerFitWindow);
1182 0           return $self;
1183             }
1184            
1185             =head2 setViewerHideMenuBar( $viewerHideMenuBar )
1186            
1187             Set a flag specifying whether to hide the pdf viewer application's menu bar when the document is active. The default value is False.
1188            
1189             Parameters:
1190            
1191             - $viewerHideMenuBar: Hide menu bar or not.
1192            
1193             Returns:
1194            
1195             - Reference to the current object.
1196             =cut
1197             sub setViewerHideMenuBar($) {
1198 0     0 1   my($self, $viewerHideMenuBar) = @_;
1199            
1200 0           $self->{parameters}{"viewer_hide_menu_bar"} = $self->SUPER::serializeBoolean($viewerHideMenuBar);
1201 0           return $self;
1202             }
1203            
1204             =head2 setViewerHideToolbar( $viewerHideToolbar )
1205            
1206             Set a flag specifying whether to hide the pdf viewer application's tool bars when the document is active. The default value is False.
1207            
1208             Parameters:
1209            
1210             - $viewerHideToolbar: Hide tool bars or not.
1211            
1212             Returns:
1213            
1214             - Reference to the current object.
1215             =cut
1216             sub setViewerHideToolbar($) {
1217 0     0 1   my($self, $viewerHideToolbar) = @_;
1218            
1219 0           $self->{parameters}{"viewer_hide_toolbar"} = $self->SUPER::serializeBoolean($viewerHideToolbar);
1220 0           return $self;
1221             }
1222            
1223             =head2 setViewerHideWindowUI( $viewerHideWindowUI )
1224            
1225             Set a flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls),
1226             leaving only the document's contents displayed.
1227            
1228             Parameters:
1229            
1230             - $viewerHideWindowUI: Hide window UI or not.
1231            
1232             Returns:
1233            
1234             - Reference to the current object.
1235             =cut
1236             sub setViewerHideWindowUI($) {
1237 0     0 1   my($self, $viewerHideWindowUI) = @_;
1238            
1239 0           $self->{parameters}{"viewer_hide_window_ui"} = $self->SUPER::serializeBoolean($viewerHideWindowUI);
1240 0           return $self;
1241             }
1242            
1243             =head2 setShowHeader( $showHeader )
1244            
1245             Control if a custom header is displayed in the generated PDF document. The default value is False.
1246            
1247             Parameters:
1248            
1249             - $showHeader: Show header or not.
1250            
1251             Returns:
1252            
1253             - Reference to the current object.
1254             =cut
1255             sub setShowHeader($) {
1256 0     0 1   my($self, $showHeader) = @_;
1257            
1258 0           $self->{parameters}{"show_header"} = $self->SUPER::serializeBoolean($showHeader);
1259 0           return $self;
1260             }
1261            
1262             =head2 setHeaderHeight( $height )
1263            
1264             The height of the pdf document header. This height is specified in points. 1 point is 1/72 inch. The default value is 50.
1265            
1266             Parameters:
1267            
1268             - $height: Header height.
1269            
1270             Returns:
1271            
1272             - Reference to the current object.
1273             =cut
1274             sub setHeaderHeight($) {
1275 0     0 1   my($self, $height) = @_;
1276            
1277 0           $self->{parameters}{"header_height"} = $height;
1278 0           return $self;
1279             }
1280            
1281             =head2 setHeaderUrl( $url )
1282            
1283             Set the url of the web page that is converted and rendered in the PDF document header.
1284            
1285             Parameters:
1286            
1287             - $url: The url of the web page that is converted and rendered in the pdf document header.
1288            
1289             Returns:
1290            
1291             - Reference to the current object.
1292             =cut
1293             sub setHeaderUrl($) {
1294 0     0 1   my($self, $url) = @_;
1295            
1296 0           $self->{parameters}{"header_url"} = $url;
1297 0           return $self;
1298             }
1299            
1300             =head2 setHeaderHtml( $html )
1301            
1302             Set the raw html that is converted and rendered in the pdf document header.
1303            
1304             Parameters:
1305            
1306             - $html: The raw html that is converted and rendered in the pdf document header.
1307            
1308             Returns:
1309            
1310             - Reference to the current object.
1311             =cut
1312             sub setHeaderHtml($) {
1313 0     0 1   my($self, $html) = @_;
1314            
1315 0           $self->{parameters}{"header_html"} = $html;
1316 0           return $self;
1317             }
1318            
1319             =head2 setHeaderBaseUrl( $baseUrl )
1320            
1321             Set an optional base url parameter can be used together with the header HTML to resolve relative paths from the html string.
1322            
1323             Parameters:
1324            
1325             - $baseUrl: Header base url.
1326            
1327             Returns:
1328            
1329             - Reference to the current object.
1330             =cut
1331             sub setHeaderBaseUrl($) {
1332 0     0 1   my($self, $baseUrl) = @_;
1333            
1334 0           $self->{parameters}{"header_base_url"} = $baseUrl;
1335 0           return $self;
1336             }
1337            
1338             =head2 setHeaderDisplayOnFirstPage( $displayOnFirstPage )
1339            
1340             Control the visibility of the header on the first page of the generated pdf document. The default value is True.
1341            
1342             Parameters:
1343            
1344             - $displayOnFirstPage: Display header on the first page or not.
1345            
1346             Returns:
1347            
1348             - Reference to the current object.
1349             =cut
1350             sub setHeaderDisplayOnFirstPage($) {
1351 0     0 1   my($self, $displayOnFirstPage) = @_;
1352            
1353 0           $self->{parameters}{"header_display_on_first_page"} = $self->SUPER::serializeBoolean($displayOnFirstPage);
1354 0           return $self;
1355             }
1356            
1357             =head2 setHeaderDisplayOnOddPages( $displayOnOddPages )
1358            
1359             Control the visibility of the header on the odd numbered pages of the generated pdf document. The default value is True.
1360            
1361             Parameters:
1362            
1363             - $displayOnOddPages: Display header on odd pages or not.
1364            
1365             Returns:
1366            
1367             - Reference to the current object.
1368             =cut
1369             sub setHeaderDisplayOnOddPages($) {
1370 0     0 1   my($self, $displayOnOddPages) = @_;
1371            
1372 0           $self->{parameters}{"header_display_on_odd_pages"} = $self->SUPER::serializeBoolean($displayOnOddPages);
1373 0           return $self;
1374             }
1375            
1376             =head2 setHeaderDisplayOnEvenPages( $displayOnEvenPages )
1377            
1378             Control the visibility of the header on the even numbered pages of the generated pdf document. The default value is True.
1379            
1380             Parameters:
1381            
1382             - $displayOnEvenPages: Display header on even pages or not.
1383            
1384             Returns:
1385            
1386             - Reference to the current object.
1387             =cut
1388             sub setHeaderDisplayOnEvenPages($) {
1389 0     0 1   my($self, $displayOnEvenPages) = @_;
1390            
1391 0           $self->{parameters}{"header_display_on_even_pages"} = $self->SUPER::serializeBoolean($displayOnEvenPages);
1392 0           return $self;
1393             }
1394            
1395             =head2 setHeaderWebPageWidth( $headerWebPageWidth )
1396            
1397             Set the width in pixels used by the converter's internal browser window during the conversion of the header content. The default value is 1024px.
1398            
1399             Parameters:
1400            
1401             - $headerWebPageWidth: Browser window width in pixels.
1402            
1403             Returns:
1404            
1405             - Reference to the current object.
1406             =cut
1407             sub setHeaderWebPageWidth($) {
1408 0     0 1   my($self, $headerWebPageWidth) = @_;
1409            
1410 0           $self->{parameters}{"header_web_page_width"} = $headerWebPageWidth;
1411 0           return $self;
1412             }
1413            
1414             =head2 setHeaderWebPageHeight( $headerWebPageHeight )
1415            
1416             Set the height in pixels used by the converter's internal browser window during the conversion of the header content.
1417             The default value is 0px and it means that the page height is automatically calculated by the converter.
1418            
1419             Parameters:
1420            
1421             - $headerWebPageHeight: Browser window height in pixels. Set it to 0px to automatically calculate page height.
1422            
1423             Returns:
1424            
1425             - Reference to the current object.
1426             =cut
1427             sub setHeaderWebPageHeight($) {
1428 0     0 1   my($self, $headerWebPageHeight) = @_;
1429            
1430 0           $self->{parameters}{"header_web_page_height"} = $headerWebPageHeight;
1431 0           return $self;
1432             }
1433            
1434            
1435            
1436             =head2 setShowFooter( $showFooter )
1437            
1438             Control if a custom footer is displayed in the generated PDF document. The default value is False.
1439            
1440             Parameters:
1441            
1442             - $showFooter: Show footer or not.
1443            
1444             Returns:
1445            
1446             - Reference to the current object.
1447             =cut
1448             sub setShowFooter($) {
1449 0     0 1   my($self, $showFooter) = @_;
1450            
1451 0           $self->{parameters}{"show_footer"} = $self->SUPER::serializeBoolean($showFooter);
1452 0           return $self;
1453             }
1454            
1455             =head2 setFooterHeight( $height )
1456            
1457             The height of the pdf document footer. This height is specified in points. 1 point is 1/72 inch. The default value is 50.
1458            
1459             Parameters:
1460            
1461             - $height: Footer height.
1462            
1463             Returns:
1464            
1465             - Reference to the current object.
1466             =cut
1467             sub setFooterHeight($) {
1468 0     0 1   my($self, $height) = @_;
1469            
1470 0           $self->{parameters}{"footer_height"} = $height;
1471 0           return $self;
1472             }
1473            
1474             =head2 setFooterUrl( $url )
1475            
1476             Set the url of the web page that is converted and rendered in the PDF document footer.
1477            
1478             Parameters:
1479            
1480             - $url: The url of the web page that is converted and rendered in the pdf document footer.
1481            
1482             Returns:
1483            
1484             - Reference to the current object.
1485             =cut
1486             sub setFooterUrl($) {
1487 0     0 1   my($self, $url) = @_;
1488            
1489 0           $self->{parameters}{"footer_url"} = $url;
1490 0           return $self;
1491             }
1492            
1493             =head2 setFooterHtml( $html )
1494            
1495             Set the raw html that is converted and rendered in the pdf document footer.
1496            
1497             Parameters:
1498            
1499             - $html: The raw html that is converted and rendered in the pdf document footer.
1500            
1501             Returns:
1502            
1503             - Reference to the current object.
1504             =cut
1505             sub setFooterHtml($) {
1506 0     0 1   my($self, $html) = @_;
1507            
1508 0           $self->{parameters}{"footer_html"} = $html;
1509 0           return $self;
1510             }
1511            
1512             =head2 setFooterBaseUrl( $baseUrl )
1513            
1514             Set an optional base url parameter can be used together with the footer HTML to resolve relative paths from the html string.
1515            
1516             Parameters:
1517            
1518             - $baseUrl: Footer base url.
1519            
1520             Returns:
1521            
1522             - Reference to the current object.
1523             =cut
1524             sub setFooterBaseUrl($) {
1525 0     0 1   my($self, $baseUrl) = @_;
1526            
1527 0           $self->{parameters}{"footer_base_url"} = $baseUrl;
1528 0           return $self;
1529             }
1530            
1531             =head2 setFooterDisplayOnFirstPage( $displayOnFirstPage )
1532            
1533             Control the visibility of the footer on the first page of the generated pdf document. The default value is True.
1534            
1535             Parameters:
1536            
1537             - $displayOnFirstPage: Display footer on the first page or not.
1538            
1539             Returns:
1540            
1541             - Reference to the current object.
1542             =cut
1543             sub setFooterDisplayOnFirstPage($) {
1544 0     0 1   my($self, $displayOnFirstPage) = @_;
1545            
1546 0           $self->{parameters}{"footer_display_on_first_page"} = $self->SUPER::serializeBoolean($displayOnFirstPage);
1547 0           return $self;
1548             }
1549            
1550             =head2 setFooterDisplayOnOddPages( $displayOnOddPages )
1551            
1552             Control the visibility of the footer on the odd numbered pages of the generated pdf document. The default value is True.
1553            
1554             Parameters:
1555            
1556             - $displayOnOddPages: Display footer on odd pages or not.
1557            
1558             Returns:
1559            
1560             - Reference to the current object.
1561             =cut
1562             sub setFooterDisplayOnOddPages($) {
1563 0     0 1   my($self, $displayOnOddPages) = @_;
1564            
1565 0           $self->{parameters}{"footer_display_on_odd_pages"} = $self->SUPER::serializeBoolean($displayOnOddPages);
1566 0           return $self;
1567             }
1568            
1569             =head2 setFooterDisplayOnEvenPages( $displayOnEvenPages )
1570            
1571             Control the visibility of the footer on the even numbered pages of the generated pdf document. The default value is True.
1572            
1573             Parameters:
1574            
1575             - $displayOnEvenPages: Display footer on even pages or not.
1576            
1577             Returns:
1578            
1579             - Reference to the current object.
1580             =cut
1581             sub setFooterDisplayOnEvenPages($) {
1582 0     0 1   my($self, $displayOnEvenPages) = @_;
1583            
1584 0           $self->{parameters}{"footer_display_on_even_pages"} = $self->SUPER::serializeBoolean($displayOnEvenPages);
1585 0           return $self;
1586             }
1587            
1588             =head2 setFooterDisplayOnLastPage( $displayOnLastPage )
1589            
1590             Add a special footer on the last page of the generated pdf document only. The default value is False.
1591             Use setFooterUrl or setFooterHtml and setFooterBaseUrl to specify the content of the last page footer.
1592             Use setFooterHeight to specify the height of the special last page footer.
1593            
1594             Parameters:
1595            
1596             - $displayOnLastPage: Display special footer on the last page or not.
1597            
1598             Returns:
1599            
1600             - Reference to the current object.
1601             =cut
1602             sub setFooterDisplayOnLastPage($) {
1603 0     0 1   my($self, $displayOnLastPage) = @_;
1604            
1605 0           $self->{parameters}{"footer_display_on_last_page"} = $self->SUPER::serializeBoolean($displayOnLastPage);
1606 0           return $self;
1607             }
1608            
1609             =head2 setFooterWebPageWidth( $footerWebPageWidth )
1610            
1611             Set the width in pixels used by the converter's internal browser window during the conversion of the footer content. The default value is 1024px.
1612            
1613             Parameters:
1614            
1615             - $footerWebPageWidth: Browser window width in pixels.
1616            
1617             Returns:
1618            
1619             - Reference to the current object.
1620             =cut
1621             sub setFooterWebPageWidth($) {
1622 0     0 1   my($self, $footerWebPageWidth) = @_;
1623            
1624 0           $self->{parameters}{"footer_web_page_width"} = $footerWebPageWidth;
1625 0           return $self;
1626             }
1627            
1628             =head2 setFooterWebPageHeight( $footerWebPageHeight )
1629            
1630             Set the height in pixels used by the converter's internal browser window during the conversion of the footer content.
1631             The default value is 0px and it means that the page height is automatically calculated by the converter.
1632            
1633             Parameters:
1634            
1635             - $footerWebPageHeight: Browser window height in pixels. Set it to 0px to automatically calculate page height.
1636            
1637             Returns:
1638            
1639             - Reference to the current object.
1640             =cut
1641             sub setFooterWebPageHeight($) {
1642 0     0 1   my($self, $footerWebPageHeight) = @_;
1643            
1644 0           $self->{parameters}{"footer_web_page_height"} = $footerWebPageHeight;
1645 0           return $self;
1646             }
1647            
1648            
1649             =head2 setShowPageNumbers( $showPageNumbers )
1650            
1651             Show page numbers. Default value is True. Page numbers will be displayed in the footer of the PDF document.
1652            
1653             Parameters:
1654            
1655             - $showPageNumbers: Show page numbers or not.
1656            
1657             Returns:
1658            
1659             - Reference to the current object.
1660             =cut
1661             sub setShowPageNumbers($) {
1662 0     0 1   my($self, $showPageNumbers) = @_;
1663            
1664 0           $self->{parameters}{"page_numbers"} = $self->SUPER::serializeBoolean($showPageNumbers);
1665 0           return $self;
1666             }
1667            
1668             =head2 setPageNumbersFirst( $firstPageNumber )
1669            
1670             Control the page number for the first page being rendered. The default value is 1.
1671            
1672             Parameters:
1673            
1674             - $firstPageNumber: First page number.
1675            
1676             Returns:
1677            
1678             - Reference to the current object.
1679             =cut
1680             sub setPageNumbersFirst($) {
1681 0     0 1   my($self, $firstPageNumber) = @_;
1682            
1683 0           $self->{parameters}{"page_numbers_first"} = $firstPageNumber;
1684 0           return $self;
1685             }
1686            
1687             =head2 setPageNumbersOffset( $totalPagesOffset )
1688            
1689             Control the total number of pages offset in the generated pdf document. The default value is 0.
1690            
1691             Parameters:
1692            
1693             - $totalPagesOffset: Offset for the total number of pages in the generated pdf document.
1694            
1695             Returns:
1696            
1697             - Reference to the current object.
1698             =cut
1699             sub setPageNumbersOffset($) {
1700 0     0 1   my($self, $totalPagesOffset) = @_;
1701            
1702 0           $self->{parameters}{"page_numbers_offset"} = $totalPagesOffset;
1703 0           return $self;
1704             }
1705            
1706             =head2 setPageNumbersTemplate( $template )
1707            
1708             Set the text that is used to display the page numbers. It can contain the placeholder {page_number} for the current page number and {total_pages}
1709             for the total number of pages. The default value is "Page: {page_number} of {total_pages}".
1710            
1711             Parameters:
1712            
1713             - $template: Page numbers template.
1714            
1715             Returns:
1716            
1717             - Reference to the current object.
1718             =cut
1719             sub setPageNumbersTemplate($) {
1720 0     0 1   my($self, $template) = @_;
1721            
1722 0           $self->{parameters}{"page_numbers_template"} = $template;
1723 0           return $self;
1724             }
1725            
1726             =head2 setPageNumbersFontName( $fontName )
1727            
1728             Set the font used to display the page numbers text. The default value is "Helvetica".
1729            
1730             Parameters:
1731            
1732             - $fontName: The font used to display the page numbers text.
1733            
1734             Returns:
1735            
1736             - Reference to the current object.
1737             =cut
1738             sub setPageNumbersFontName($) {
1739 0     0 1   my($self, $fontName) = @_;
1740            
1741 0           $self->{parameters}{"page_numbers_font_name"} = $fontName;
1742 0           return $self;
1743             }
1744            
1745             =head2 setPageNumbersFontSize( $fontSize )
1746            
1747             Set the size of the font used to display the page numbers. The default value is 10 points.
1748            
1749             Parameters:
1750            
1751             - $fontSize: The size in points of the font used to display the page numbers.
1752            
1753             Returns:
1754            
1755             - Reference to the current object.
1756             =cut
1757             sub setPageNumbersFontSize($) {
1758 0     0 1   my($self, $fontSize) = @_;
1759            
1760 0           $self->{parameters}{"page_numbers_font_size"} = $fontSize;
1761 0           return $self;
1762             }
1763            
1764             =head2 setPageNumbersAlignment( $alignment )
1765            
1766             Set the alignment of the page numbers text. The default value is "2" - Right.
1767            
1768             Parameters:
1769            
1770             - $alignment: The alignment of the page numbers text. Possible values: 1 (Left), 2 (Center), 3 (Right).
1771            
1772             Returns:
1773            
1774             - Reference to the current object.
1775             =cut
1776             sub setPageNumbersAlignment($) {
1777 0     0 1   my($self, $alignment) = @_;
1778            
1779 0 0 0       if ($alignment ne 1 and $alignment ne 2 and $alignment ne 3) {
      0        
1780 0           die ("Allowed values for Page Numbers Alignment: 1 (Left), 2 (Center), 3 (Right).");
1781             }
1782            
1783 0           $self->{parameters}{"page_numbers_alignment"} = $alignment;
1784 0           return $self;
1785             }
1786            
1787             =head2 setPageNumbersColor( $color )
1788            
1789             Specify the color of the page numbers text in #RRGGBB html format. The default value is #333333.
1790            
1791             Parameters:
1792            
1793             - $color: Page numbers color.
1794            
1795             Returns:
1796            
1797             - Reference to the current object.
1798             =cut
1799             sub setPageNumbersColor($) {
1800 0     0 1   my($self, $color) = @_;
1801            
1802 0 0         if ($color !~ m/^#?[0-9a-fA-F]{6}$/) {
1803 0           die ("Color value must be in #RRGGBB format.");
1804             }
1805            
1806 0           $self->{parameters}{"page_numbers_color"} = $color;
1807 0           return $self;
1808             }
1809            
1810             =head2 setPageNumbersVerticalPosition( $position )
1811            
1812             Specify the position in points on the vertical where the page numbers text is displayed in the footer. The default value is 10 points.
1813            
1814             Parameters:
1815            
1816             - $position: Page numbers Y position in points.
1817            
1818             Returns:
1819            
1820             - Reference to the current object.
1821             =cut
1822             sub setPageNumbersVerticalPosition($) {
1823 0     0 1   my($self, $position) = @_;
1824            
1825 0           $self->{parameters}{"page_numbers_pos_y"} = $position;
1826 0           return $self;
1827             }
1828            
1829             =head2 setPdfBookmarksSelectors( $selectors )
1830            
1831             Generate automatic bookmarks in pdf. The elements that will be bookmarked are defined using CSS selectors.
1832             For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and
1833             the selector for the elements with the id 'myid' is "*#myid".
1834             Read more about CSS selectors here.
1835            
1836             Parameters:
1837            
1838             - $selectors: CSS selectors used to identify HTML elements, comma separated.
1839            
1840             Returns:
1841            
1842             - Reference to the current object.
1843             =cut
1844             sub setPdfBookmarksSelectors($) {
1845 0     0 1   my($self, $selectors) = @_;
1846            
1847 0           $self->{parameters}{"pdf_bookmarks_selectors"} = $selectors;
1848 0           return $self;
1849             }
1850            
1851             =head2 setPdfHideElements( $selectors )
1852            
1853             Exclude page elements from the conversion. The elements that will be excluded are defined using CSS selectors.
1854             For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and
1855             the selector for the elements with the id 'myid' is "*#myid".
1856             Read more about CSS selectors here.
1857            
1858             Parameters:
1859            
1860             - $selectors: CSS selectors used to identify HTML elements, comma separated.
1861            
1862             Returns:
1863            
1864             - Reference to the current object.
1865             =cut
1866             sub setPdfHideElements($) {
1867 0     0 1   my($self, $selectors) = @_;
1868            
1869 0           $self->{parameters}{"pdf_hide_elements"} = $selectors;
1870 0           return $self;
1871             }
1872            
1873             =head2 setPdfShowOnlyElementID( $elementID )
1874            
1875             Convert only a specific section of the web page to pdf. The section that will be converted to pdf is specified by the html element ID.
1876             The element can be anything (image, table, table row, div, text, etc).
1877            
1878             Parameters:
1879            
1880             - $elementID: HTML element ID.
1881            
1882             Returns:
1883            
1884             - Reference to the current object.
1885             =cut
1886             sub setPdfShowOnlyElementID($) {
1887 0     0 1   my($self, $elementID) = @_;
1888            
1889 0           $self->{parameters}{"pdf_show_only_element_id"} = $elementID;
1890 0           return $self;
1891             }
1892            
1893             =head2 setPdfWebElementsSelectors( $selectors )
1894            
1895             Get the locations of page elements from the conversion. The elements that will have their locations retrieved are defined using CSS selectors.
1896             For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and
1897             the selector for the elements with the id 'myid' is "*#myid".
1898             Read more about CSS selectors here.
1899            
1900             Parameters:
1901            
1902             - $selectors: CSS selectors used to identify HTML elements, comma separated.
1903            
1904             Returns:
1905            
1906             - Reference to the current object.
1907             =cut
1908             sub setPdfWebElementsSelectors($) {
1909 0     0 1   my($self, $selectors) = @_;
1910            
1911 0           $self->{parameters}{"pdf_web_elements_selectors"} = $selectors;
1912 0           return $self;
1913             }
1914            
1915             =head2 setStartupMode( $startupMode )
1916            
1917             Set converter startup mode. The default value is Automatic and the conversion is started immediately.
1918             By default this is set to Automatic and the conversion is started as soon as the page loads (and conversion delay set with setConversionDelay elapses).
1919             If set to Manual, the conversion is started only by a javascript call to SelectPdf.startConversion() from within the web page.
1920            
1921             Parameters:
1922            
1923             - $startupMode: Converter startup mode. Possible values: Automatic, Manual.
1924            
1925             Returns:
1926            
1927             - Reference to the current object.
1928             =cut
1929             sub setStartupMode($) {
1930 0     0 1   my($self, $startupMode) = @_;
1931            
1932 0 0         if ($startupMode !~ m/^(Automatic|Manual)$/i) {
1933 0           die ("Allowed values for Startup Mode: Automatic, Manual.");
1934             }
1935            
1936 0           $self->{parameters}{"startup_mode"} = $startupMode;
1937 0           return $self;
1938             }
1939            
1940             =head2 setSkipDecoding( $skipDecoding )
1941            
1942             Internal use only.
1943            
1944             Parameters:
1945            
1946             - $skipDecoding: The default value is True.
1947            
1948             Returns:
1949            
1950             - Reference to the current object.
1951             =cut
1952             sub setSkipDecoding($) {
1953 0     0 1   my($self, $skipDecoding) = @_;
1954            
1955 0           $self->{parameters}{"skip_decoding"} = $self->SUPER::serializeBoolean($skipDecoding);
1956 0           return $self;
1957             }
1958            
1959             =head2 setScaleImages( $scaleImages )
1960            
1961             Set a flag indicating if the images from the page are scaled during the conversion process. The default value is False and images are not scaled.
1962            
1963             Parameters:
1964            
1965             - $scaleImages: Scale images or not.
1966            
1967             Returns:
1968            
1969             - Reference to the current object.
1970             =cut
1971             sub setScaleImages($) {
1972 0     0 1   my($self, $scaleImages) = @_;
1973            
1974 0           $self->{parameters}{"scale_images"} = $self->SUPER::serializeBoolean($scaleImages);
1975 0           return $self;
1976             }
1977            
1978             =head2 setSinglePagePdf( $generateSinglePagePdf )
1979            
1980             Generate a single page PDF. The converter will automatically resize the PDF page to fit all the content in a single page.
1981             The default value of this property is False and the PDF will contain several pages if the content is large.
1982            
1983             Parameters:
1984            
1985             - $generateSinglePagePdf: Generate a single page PDF or not.
1986            
1987             Returns:
1988            
1989             - Reference to the current object.
1990             =cut
1991             sub setSinglePagePdf($) {
1992 0     0 1   my($self, $generateSinglePagePdf) = @_;
1993            
1994 0           $self->{parameters}{"single_page_pdf"} = $self->SUPER::serializeBoolean($generateSinglePagePdf);
1995 0           return $self;
1996             }
1997            
1998             =head2 setPageBreaksEnhancedAlgorithm( $enableEnhancedPageBreaksAlgorithm )
1999            
2000             Get or set a flag indicating if an enhanced custom page breaks algorithm is used.
2001             The enhanced algorithm is a little bit slower but it will prevent the appearance of hidden text in the PDF when custom page breaks are used.
2002             The default value for this property is False.
2003            
2004             Parameters:
2005            
2006             - $enableEnhancedPageBreaksAlgorithm: Enable enhanced page breaks algorithm or not.
2007            
2008             Returns:
2009            
2010             - Reference to the current object.
2011             =cut
2012             sub setPageBreaksEnhancedAlgorithm($) {
2013 0     0 1   my($self, $enableEnhancedPageBreaksAlgorithm) = @_;
2014            
2015 0           $self->{parameters}{"page_breaks_enhanced_algorithm"} = $self->SUPER::serializeBoolean($enableEnhancedPageBreaksAlgorithm);
2016 0           return $self;
2017             }
2018            
2019             =head2 setCookies( $cookies )
2020            
2021             Set HTTP cookies for the web page being converted.
2022            
2023             Parameters:
2024            
2025             - $cookies: Dictionary with HTTP cookies that will be sent to the page being converted.
2026            
2027             Returns:
2028            
2029             - Reference to the current object.
2030             =cut
2031             sub setCookies($) {
2032 0     0 1   my($self, $cookies) = @_;
2033            
2034 0           my $url = URI->new('', 'http');
2035 0           $url->query_form(%$cookies);
2036 0           my $cookiesString = $url->query;
2037            
2038 0           $self->{parameters}{"cookies_string"} = $cookiesString;
2039 0           return $self;
2040             }
2041            
2042             =head2 setCustomParameter( $parameterName, $parameterValue )
2043            
2044             Set a custom parameter. Do not use this method unless advised by SelectPdf.
2045            
2046             Parameters:
2047            
2048             - $parameterName: Parameter name.
2049            
2050             - $parameterValue: Parameter value.
2051            
2052             Returns:
2053            
2054             - Reference to the current object.
2055             =cut
2056             sub setCustomParameter($,$) {
2057 0     0 1   my($self, $parameterName, $parameterValue) = @_;
2058            
2059 0           $self->{parameters}{$parameterName} = $parameterValue;
2060 0           return $self;
2061             }
2062            
2063             =head2 getWebElements
2064            
2065             Get the locations of certain web elements. This is retrieved if pdf_web_elements_selectors parameter is set and elements were found to match the selectors.
2066            
2067             Returns:
2068            
2069             - Json with web elements locations.
2070             =cut
2071             sub getWebElements {
2072 0     0 1   my($self) = @_;
2073            
2074 0           my $webElementsClient = SelectPdf::WebElementsClient->new($self->{parameters}{"key"}, $self->{jobId});
2075 0           $webElementsClient->setApiEndpoint($self->{apiWebElementsEndpoint});
2076            
2077 0           return $webElementsClient->getWebElements();
2078             }
2079            
2080            
2081            
2082             1;