1: <?php
2:
3: namespace WkHtmlToPdf\Options;
4:
5: use WkHtmlToPdf\WkHtmlToPdf;
6:
7: 8: 9: 10: 11:
12: trait PageOptionsTrait
13: {
14: 15: 16: 17: 18:
19: public function enableJavascriptDebugging()
20: {
21: if (array_key_exists('no-debug-javascript', $this->arguments)) {
22: unset($this->arguments ['no-debug-javascript']);
23: }
24: $this->arguments['debug-javascript'] = null;
25:
26: return $this;
27: }
28:
29: 30: 31: 32: 33:
34: public function disableJavascriptDebugging()
35: {
36: if (array_key_exists('debug-javascript', $this->arguments)) {
37: unset($this->arguments ['debug-javascript']);
38: }
39: $this->arguments['no-debug-javascript'] = null;
40:
41: return $this;
42: }
43:
44: 45: 46: 47: 48:
49: public function enableBackground()
50: {
51: if (array_key_exists('no-background', $this->arguments)) {
52: unset($this->arguments['no-background']);
53: }
54: $this->arguments['background'] = null;
55:
56: return $this;
57: }
58:
59: 60: 61: 62: 63:
64: public function disableBackground()
65: {
66: if (array_key_exists('background', $this->arguments)) {
67: unset($this->arguments['background']);
68: }
69: $this->arguments['no-background'] = null;
70:
71: return $this;
72: }
73:
74: 75: 76: 77: 78: 79: 80:
81: public function setCacheDir($path)
82: {
83: $this->arguments['cache-dir'] = $path;
84:
85: return $this;
86: }
87:
88: 89: 90: 91: 92: 93: 94:
95: public function setCheckboxCheckedSvg($path)
96: {
97: $this->arguments['checkbox-checked-svg'] = $path;
98:
99: return $this;
100: }
101:
102: 103: 104: 105: 106: 107: 108:
109: public function setCheckboxUncheckedSvg($path)
110: {
111: $this->arguments['checkbox-svg'] = $path;
112:
113: return $this;
114: }
115:
116: 117: 118: 119: 120: 121: 122:
123: public function setRadiobuttonCheckedSvg($path)
124: {
125: $this->arguments['radiobutton-checked-svg'] = $path;
126:
127: return $this;
128: }
129:
130: 131: 132: 133: 134: 135: 136:
137: public function setRadiobuttonUncheckedSvg($path)
138: {
139: $this->arguments['radiobutton-svg'] = $path;
140:
141: return $this;
142: }
143:
144: 145: 146: 147: 148: 149: 150: 151:
152: public function addCookie($name, $value)
153: {
154: $this->arguments['cookie'][$name] = urlencode($value);
155:
156: return $this;
157: }
158:
159: 160: 161: 162: 163: 164: 165:
166: public function addCookies(array $cookies)
167: {
168: foreach ($cookies as $name => $value) {
169: $this->arguments['cookie'][$name] = urlencode($value);
170: }
171:
172: return $this;
173: }
174:
175: 176: 177: 178: 179: 180: 181: 182:
183: public function addCustomHttpHeader($name, $value)
184: {
185: $this->arguments['custom-header'][$name] = $value;
186:
187: return $this;
188: }
189:
190: 191: 192: 193: 194: 195: 196:
197: public function addCustomHttpHeaders(array $headers)
198: {
199: foreach ($headers as $name => $value) {
200: $this->arguments['custom-header'][$name] = $value;
201: }
202:
203: return $this;
204: }
205:
206: 207: 208: 209: 210:
211: public function enableCustomHttpHeaderPropagination()
212: {
213: if (array_key_exists('no-custom-header-propagination', $this->arguments)) {
214: unset($this->arguments['no-custom-header-propagination']);
215: }
216: $this->arguments['custom-header-propagation'] = null;
217:
218: return $this;
219: }
220:
221: 222: 223: 224: 225:
226: public function disableCustomHttpHeaderPropagination()
227: {
228: if (array_key_exists('custom-header-propagination', $this->arguments)) {
229: unset($this->arguments['custom-header-propagination']);
230: }
231: $this->arguments['no-custom-header-propagation'] = null;
232:
233: return $this;
234: }
235:
236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246:
247: public function addDefaultHeader()
248: {
249: $this->arguments['default-header'] = null;
250:
251: return $this;
252: }
253:
254: 255: 256: 257: 258: 259: 260:
261: public function setEncoding($encoding)
262: {
263: $this->arguments['encoding'] = $encoding;
264:
265: return $this;
266: }
267:
268: 269: 270: 271: 272:
273: public function disableExternalLinks()
274: {
275: if (array_key_exists('enable-external-links', $this->arguments)) {
276: unset($this->arguments['enable-external-links']);
277: }
278: $this->arguments['disable-external-links'] = null;
279:
280: return $this;
281: }
282:
283: 284: 285: 286: 287:
288: public function enableExternalLinks()
289: {
290: if (array_key_exists('disable-external-links', $this->arguments)) {
291: unset($this->arguments['disable-external-links']);
292: }
293: $this->arguments['enable-external-links'] = null;
294:
295: return $this;
296: }
297:
298: 299: 300: 301: 302:
303: public function disableForms()
304: {
305: if (array_key_exists('enable-forms', $this->arguments)) {
306: unset($this->arguments['enable-forms']);
307: }
308: $this->arguments['disable-forms'] = null;
309:
310: return $this;
311: }
312:
313: 314: 315: 316: 317:
318: public function enableForms()
319: {
320: if (array_key_exists('disable-forms', $this->arguments)) {
321: unset($this->arguments['disable-forms']);
322: }
323: $this->arguments['enable-forms'] = null;
324:
325: return $this;
326: }
327:
328: 329: 330: 331: 332:
333: public function disableImages()
334: {
335: if (array_key_exists('images', $this->arguments)) {
336: unset($this->arguments['images']);
337: }
338: $this->arguments['no-images'] = null;
339:
340: return $this;
341: }
342:
343: 344: 345: 346: 347:
348: public function enableImages()
349: {
350: if (array_key_exists('no-images', $this->arguments)) {
351: unset($this->arguments['no-images']);
352: }
353: $this->arguments['images'] = null;
354:
355: return $this;
356: }
357:
358: 359: 360: 361: 362:
363: public function disableInternalLinks()
364: {
365: if (array_key_exists('enable-internal-links', $this->arguments)) {
366: unset($this->arguments['enable-internal-links']);
367: }
368: $this->arguments['disable-internal-links'] = null;
369:
370: return $this;
371: }
372:
373: 374: 375: 376: 377:
378: public function enableInternalLinks()
379: {
380: if (array_key_exists('disable-internal-links', $this->arguments)) {
381: unset($this->arguments['disable-internal-links']);
382: }
383: $this->arguments['enable-internal-links'] = null;
384:
385: return $this;
386: }
387:
388: 389: 390: 391: 392:
393: public function disableJavascript()
394: {
395: if (array_key_exists('enable-javascript', $this->arguments)) {
396: unset($this->arguments['enable-javascript']);
397: }
398: $this->arguments['disable-javascript'] = null;
399:
400: return $this;
401: }
402:
403: 404: 405: 406: 407:
408: public function enableJavascript()
409: {
410: if (array_key_exists('disable-javascript', $this->arguments)) {
411: unset($this->arguments['disable-javascript']);
412: }
413: $this->arguments['enable-javascript'] = null;
414:
415: return $this;
416: }
417:
418: 419: 420: 421: 422: 423: 424:
425: public function setJavascriptDelay($msec = 200)
426: {
427: $this->arguments['javascript-delay'] = intval($msec);
428:
429: return $this;
430: }
431:
432: 433: 434: 435: 436:
437: public function disablePlugins()
438: {
439: if (array_key_exists('enable-plugins', $this->arguments)) {
440: unset($this->arguments['enable-plugins']);
441: }
442: $this->arguments['disable-plugins'] = null;
443:
444: return $this;
445: }
446:
447: 448: 449: 450: 451:
452: public function enablePlugins()
453: {
454: if (array_key_exists('disable-plugins', $this->arguments)) {
455: unset($this->arguments['disable-plugins']);
456: }
457: $this->arguments['enable-plugins'] = null;
458:
459: return $this;
460: }
461:
462: 463: 464: 465: 466:
467: public function disableTocBackLinks()
468: {
469: if (array_key_exists('enable-toc-back-links', $this->arguments)) {
470: unset($this->arguments['enable-toc-back-links']);
471: }
472: $this->arguments['disable-toc-back-links'] = null;
473:
474: return $this;
475: }
476:
477: 478: 479: 480: 481:
482: public function enableTocBackLinks()
483: {
484: if (array_key_exists('disable-toc-back-links', $this->arguments)) {
485: unset($this->arguments['disable-toc-back-links']);
486: }
487: $this->arguments['enable-toc-back-links'] = null;
488:
489: return $this;
490: }
491:
492: 493: 494: 495: 496:
497: public function disableSmartShrinking()
498: {
499: if (array_key_exists('enable-smart-shrinking', $this->arguments)) {
500: unset($this->arguments['enable-smart-shrinking']);
501: }
502: $this->arguments['disable-smart-shrinking'] = null;
503:
504: return $this;
505: }
506:
507: 508: 509: 510: 511:
512: public function enableSmartShrinking()
513: {
514: if (array_key_exists('disable-smart-shrinking', $this->arguments)) {
515: unset($this->arguments['disable-smart-shrinking']);
516: }
517: $this->arguments['enable-smart-shrinking'] = null;
518:
519: return $this;
520: }
521:
522: 523: 524: 525: 526: 527: 528:
529: public function addAllowedPath($path)
530: {
531: $this->arguments['allow'][] = $path;
532:
533: return $this;
534: }
535:
536: 537: 538: 539: 540: 541: 542:
543: public function addAllowedPaths(array $paths)
544: {
545: foreach ($paths as $path) {
546: $this->arguments['allow'][] = $path;
547: }
548:
549: return $this;
550: }
551:
552: 553: 554: 555: 556:
557: public function disableLocalFileAccess()
558: {
559: if (array_key_exists('enable-local-file-access', $this->arguments)) {
560: unset($this->arguments['enable-local-file-access']);
561: }
562: $this->arguments['disable-local-file-access'] = null;
563:
564: return $this;
565: }
566:
567: 568: 569: 570: 571:
572: public function enableLocalFileAccess()
573: {
574: if (array_key_exists('disable-local-file-access', $this->arguments)) {
575: unset($this->arguments['disable-local-file-access']);
576: }
577: $this->arguments['enable-local-file-access'] = null;
578:
579: return $this;
580: }
581:
582: 583: 584: 585: 586: 587: 588:
589: public function addScript($path)
590: {
591: $this->arguments['run-script'][] = $path;
592:
593: return $this;
594: }
595:
596: 597: 598: 599: 600: 601: 602:
603: public function addScripts(array $paths)
604: {
605: foreach ($paths as $path) {
606: $this->arguments['run-script'][] = $path;
607: }
608:
609: return $this;
610: }
611:
612: 613: 614: 615: 616:
617: public function keepRelativeLinks()
618: {
619: if (array_key_exists('resolve-relative-links', $this->arguments)) {
620: unset($this->arguments['resolve-relative-links']);
621: }
622: $this->arguments['keep-relative-links'] = null;
623:
624: return $this;
625: }
626:
627: 628: 629: 630: 631:
632: public function resolveRelativeLinks()
633: {
634: if (array_key_exists('keep-relative-links', $this->arguments)) {
635: unset($this->arguments['keep-relative-links']);
636: }
637: $this->arguments['resolve-relative-links'] = null;
638:
639: return $this;
640: }
641:
642: 643: 644: 645: 646: 647: 648:
649: public function setLoadErrorHandling($handler)
650: {
651: $this->arguments['load-error-handling'] = $handler;
652:
653: return $this;
654: }
655:
656: 657: 658: 659: 660: 661: 662:
663: public function setLoadMediaErrorHandling($handler)
664: {
665: $this->arguments['load-media-error-handling'] = $handler;
666:
667: return $this;
668: }
669:
670: 671: 672: 673: 674: 675: 676:
677: public function setMinimumFontSize($size)
678: {
679: $this->arguments['minimum-font-size'] = intval($size);
680:
681: return $this;
682: }
683:
684: 685: 686: 687: 688: 689: 690:
691: public function setPageOffset($offset = 0)
692: {
693: $this->arguments['page-offset'] = intval($offset);
694:
695: return $this;
696: }
697:
698: 699: 700: 701: 702:
703: public function enablePrintMediaType()
704: {
705: if (!$this->isQtPatched) {
706: if (array_key_exists('no-print-media-type', $this->arguments)) {
707: unset($this->arguments['no-print-media-type']);
708: }
709: $this->arguments['print-media-type'] = null;
710: } else {
711: trigger_error('Print media arguments are not supported on wkhtmltopdf with unpatched qt.', E_USER_WARNING);
712: }
713:
714: return $this;
715: }
716:
717: 718: 719: 720: 721:
722: public function disablePrintMediaType()
723: {
724: if (!$this->isQtPatched) {
725: if (array_key_exists('print-media-type', $this->arguments)) {
726: unset($this->arguments['print-media-type']);
727: }
728: $this->arguments['no-print-media-type'] = null;
729: } else {
730: trigger_error('Print media arguments are not supported by wkhtmltopdf with unpatched qt.', E_USER_WARNING);
731: }
732:
733: return $this;
734: }
735:
736: 737: 738: 739: 740: 741: 742:
743: public function setViewportSize($size)
744: {
745: $this->arguments['viewport-size'] = $size;
746:
747: return $this;
748: }
749:
750: 751: 752: 753: 754: 755: 756:
757: public function setZoom($zoom = 1.0)
758: {
759: $this->arguments['zoom'] = $zoom;
760:
761: return $this;
762: }
763:
764: 765: 766: 767: 768:
769: public function enableSlowScripts()
770: {
771: if (array_key_exists('stop-slow-scripts', $this->arguments)) {
772: unset($this->arguments['stop-slow-scripts']);
773: }
774: $this->arguments['no-stop-slow-scripts'] = null;
775:
776: return $this;
777: }
778:
779: 780: 781: 782: 783:
784: public function disableSlowScripts()
785: {
786: if (array_key_exists('no-stop-slow-scripts', $this->arguments)) {
787: unset($this->arguments['no-stop-slow-scripts']);
788: }
789: $this->arguments['stop-slow-scripts'] = null;
790:
791: return $this;
792: }
793:
794: 795: 796: 797: 798: 799: 800: 801:
802: public function addHttpPostField($name, $value)
803: {
804: $this->arguments['post'][$name] = $value;
805:
806: return $this;
807: }
808:
809: 810: 811: 812: 813: 814: 815:
816: public function addHttpPostFields(array $fields)
817: {
818: foreach ($fields as $name => $value) {
819: $this->arguments['post'][$name] = $value;
820: }
821:
822: return $this;
823: }
824:
825: 826: 827: 828: 829: 830: 831: 832:
833: public function addHttpPostFile($name, $path)
834: {
835: $this->arguments['post'][$name] = $path;
836:
837: return $this;
838: }
839:
840: 841: 842: 843: 844: 845: 846:
847: public function addHttpPostFiles(array $files)
848: {
849: foreach ($files as $name => $path) {
850: $this->arguments['post'][$name] = $path;
851: }
852:
853: return $this;
854: }
855:
856: 857: 858: 859: 860: 861: 862:
863: public function setUserStyleSheet($url)
864: {
865: $this->arguments['user-style-sheet'] = $url;
866:
867: return $this;
868: }
869:
870: 871: 872: 873: 874: 875: 876:
877: public function setHttpAuthUsername($username)
878: {
879: $this->arguments['username'] = $username;
880:
881: return $this;
882: }
883:
884: 885: 886: 887: 888: 889: 890:
891: public function setHttpAuthPassword($password)
892: {
893: $this->arguments['password'] = $password;
894:
895: return $this;
896: }
897:
898: 899: 900: 901: 902: 903: 904:
905: public function setProxy($proxy)
906: {
907: $this->arguments['proxy'] = $proxy;
908:
909: return $this;
910: }
911:
912: 913: 914: 915: 916: 917: 918:
919: public function waitWindowStatus($windowStatus)
920: {
921: $this->arguments['window-status'] = $windowStatus;
922:
923: return $this;
924: }
925:
926: 927: 928: 929: 930: 931: 932:
933: public function setBypassProxy($value)
934: {
935: $this->arguments['bypass-proxy-for'] = $value;
936:
937: return $this;
938: }
939:
940: 941: 942: 943: 944:
945: public function excludeFromOutline()
946: {
947: if (array_key_exists('include-in-outline', $this->arguments)) {
948: unset($this->arguments['include-in-outline']);
949: }
950: $this->arguments['exclude-from-outline'] = null;
951:
952: return $this;
953: }
954:
955: 956: 957: 958: 959:
960: public function includeInOutline()
961: {
962: if (array_key_exists('exclude-from-outline', $this->arguments)) {
963: unset($this->arguments['exclude-from-outline']);
964: }
965: $this->arguments['include-in-outline'] = null;
966:
967: return $this;
968: }
969: }
970: