GFPDFHelperHelper_PDF

The Gravity PDF GFPDF Helper PDF class.

Defined (1)

The class is defined in the following location(s).

/src/helper/Helper_PDF.php  
  1. class Helper_PDF { 
  2.  
  3. /** 
  4. * Holds our PDF Object 
  5. * @var \mPDF 
  6. * @since 4.0 
  7. */ 
  8. protected $mpdf; 
  9.  
  10. /** 
  11. * Holds our Gravity Form array 
  12. * @var array 
  13. * @since 4.0 
  14. */ 
  15. protected $form; 
  16.  
  17. /** 
  18. * Holds our Gravity Form Entry Details 
  19. * @var array 
  20. * @since 4.0 
  21. */ 
  22. protected $entry; 
  23.  
  24. /** 
  25. * Holds our PDF Settings 
  26. * @var array 
  27. * @since 4.0 
  28. */ 
  29. protected $settings; 
  30.  
  31. /** 
  32. * Controls how the PDF should be output. 
  33. * Whether to display it in the browser, force a download, or save it to disk 
  34. * @var string 
  35. * @since 4.0 
  36. */ 
  37. protected $output = 'DISPLAY'; 
  38.  
  39. /** 
  40. * Holds the predetermined paper size 
  41. * @var string|array 
  42. * @since 4.0 
  43. */ 
  44. protected $paper_size; 
  45.  
  46. /** 
  47. * Holds our paper orientation in mPDF flavour 
  48. * @var string 
  49. * @since 4.0 
  50. */ 
  51. protected $orientation; 
  52.  
  53. /** 
  54. * Holds the full path to the PHP template to load 
  55. * @var string 
  56. * @since 4.0 
  57. */ 
  58. protected $template_path; 
  59.  
  60. /** 
  61. * Holds the PDF filename that should be used 
  62. * @var string 
  63. * @since 4.0 
  64. */ 
  65. protected $filename = 'document.pdf'; 
  66.  
  67. /** 
  68. * Holds the path the PDF should be saved to 
  69. * @var string 
  70. * @since 4.0 
  71. */ 
  72. protected $path; 
  73.  
  74. /** 
  75. * Whether to force the print dialog when the PDF is opened 
  76. * @var boolean 
  77. * @since 4.0 
  78. */ 
  79. protected $print = false; 
  80.  
  81. /** 
  82. * Holds the abstracted Gravity Forms API specific to Gravity PDF 
  83. * @var \GFPDF\Helper\Helper_Form 
  84. * @since 4.0 
  85. */ 
  86. protected $gform; 
  87.  
  88. /** 
  89. * Holds our Helper_Data object 
  90. * which we can autoload with any data needed 
  91. * @var \GFPDF\Helper\Helper_Data 
  92. * @since 4.0 
  93. */ 
  94. protected $data; 
  95.  
  96. /** 
  97. * Holds our Helper_Misc object 
  98. * Makes it easy to access common methods throughout the plugin 
  99. * @var \GFPDF\Helper\Helper_Misc 
  100. * @since 4.0 
  101. */ 
  102. protected $misc; 
  103.  
  104. /** 
  105. * Holds our Helper_Templates object 
  106. * used to ease access to our PDF templates 
  107. * @var \GFPDF\Helper\Helper_Templates 
  108. * @since 4.0 
  109. */ 
  110. protected $templates; 
  111.  
  112. /** 
  113. * Initialise our class 
  114. * @param array $entry The Gravity Form Entry to be processed 
  115. * @param array $settings The Gravity PDF Settings Array 
  116. * @param \GFPDF\Helper\Helper_Abstract_Form $gform 
  117. * @param \GFPDF\Helper\Helper_Data $data 
  118. * @param \GFPDF\Helper\Helper_Misc $misc Our miscellanious methods 
  119. * @param \GFPDF\Helper\Helper_Templates $templates 
  120. * @since 4.0 
  121. */ 
  122. public function __construct( $entry, $settings, Helper_Abstract_Form $gform, Helper_Data $data, Helper_Misc $misc, Helper_Templates $templates ) { 
  123.  
  124. /** Assign our internal variables */ 
  125. $this->entry = $entry; 
  126. $this->settings = $settings; 
  127. $this->gform = $gform; 
  128. $this->data = $data; 
  129. $this->misc = $misc; 
  130. $this->templates = $templates; 
  131. $this->form = $this->gform->get_form( $entry['form_id'] ); 
  132.  
  133. $this->set_path(); 
  134.  
  135. /** 
  136. * A public method to start our PDF creation process 
  137. * @return void 
  138. * @since 4.0 
  139. */ 
  140. public function init() { 
  141. $this->set_paper(); 
  142. $this->begin_pdf(); 
  143. $this->set_creator(); 
  144. $this->set_image_dpi(); 
  145. $this->set_text_direction(); 
  146. $this->set_pdf_format(); 
  147. $this->set_pdf_security(); 
  148. $this->set_display_mode(); 
  149.  
  150. /** 
  151. * Render the HTML to our PDF 
  152. * @param array $args Any arguments that should be passed to the PDF template 
  153. * @param string $html By pass the template file and pass in a HTML string directly to the engine. Optional. 
  154. * @return void 
  155. * @since 4.0 
  156. */ 
  157. public function render_html( $args = [], $html = '' ) { 
  158.  
  159. /** Because this class can load any content we'll only set up our template if no HTML is passed */ 
  160. if ( empty( $html ) ) { 
  161. $this->set_template(); 
  162.  
  163. $form = $this->form; 
  164.  
  165. /** Load in our PHP template */ 
  166. if ( empty( $html ) ) { 
  167. $html = $this->load_html( $args ); 
  168.  
  169. /** Apply our filters */ 
  170. $html = apply_filters( 'gfpdfe_pdf_template', $html, $form['id'], $this->entry['id'], $args['settings'] ); /** Backwards compat */ 
  171. $html = apply_filters( 'gfpdfe_pdf_template_' . $form['id'], $html, $this->entry['id'], $args['settings'] ); /** Backwards compat */ 
  172.  
  173. /** See https://gravitypdf.com/documentation/v4/gfpdf_pdf_html_output/ for more details about these filters */ 
  174. $html = apply_filters( 'gfpdf_pdf_html_output', $html, $form, $this->entry, $args['settings'], $this ); 
  175. $html = apply_filters( 'gfpdf_pdf_html_output_' . $form['id'], $html, $this->gform, $this->entry, $args['settings'], $this ); 
  176.  
  177. /** Check if we should output the HTML to the browser, for debugging */ 
  178. $this->maybe_display_raw_html( $html ); 
  179.  
  180. /** Write the HTML to mPDF */ 
  181. $this->mpdf->WriteHTML( $html ); 
  182.  
  183. /** 
  184. * Create the PDF 
  185. * @return string 
  186. * @since 4.0 
  187. */ 
  188. public function generate() { 
  189.  
  190. /** Process any final settings before outputting */ 
  191. $this->show_print_dialog(); 
  192. $this->set_metadata(); 
  193.  
  194. $form = $this->form; 
  195.  
  196. /** 
  197. * Allow $mpdf object class to be modified 
  198. * See https://gravitypdf.com/documentation/v4/gfpdf_mpdf_class/ for more details about this filter 
  199. */ 
  200. $this->mpdf = apply_filters( 'gfpdf_mpdf_class', $this->mpdf, $form, $this->entry, $this->settings, $this ); 
  201.  
  202. /** deprecated backwards compatibility filters */ 
  203. $this->mpdf = apply_filters( 'gfpdfe_mpdf_class_pre_render', $this->mpdf, $this->entry['form_id'], $this->entry['id'], $this->settings, '', $this->get_filename() ); 
  204. $this->mpdf = apply_filters( 'gfpdfe_pre_render_pdf', $this->mpdf, $this->entry['form_id'], $this->entry['id'], $this->settings, '', $this->get_filename() ); 
  205. $this->mpdf = apply_filters( 'gfpdfe_mpdf_class', $this->mpdf, $this->entry['form_id'], $this->entry['id'], $this->settings, '', $this->get_filename() ); 
  206.  
  207. /** If a developer decides to disable all security protocols we don't want the PDF indexed */ 
  208. if ( ! headers_sent() ) { 
  209. header( 'X-Robots-Tag: noindex, nofollow', true ); 
  210.  
  211. switch ( $this->output ) { 
  212. case 'DISPLAY': 
  213. $this->prevent_caching(); 
  214. $this->mpdf->Output( $this->filename, 'I' ); 
  215. wp_die(); 
  216. break; 
  217.  
  218. case 'DOWNLOAD': 
  219. $this->prevent_caching(); 
  220. $this->mpdf->Output( $this->filename, 'D' ); 
  221. wp_die(); 
  222. break; 
  223.  
  224. case 'SAVE': 
  225. return $this->mpdf->Output( '', 'S' ); 
  226. break; 
  227.  
  228. return false; 
  229.  
  230. /** 
  231. * Save the PDF to our tmp directory 
  232. * @param string $raw_pdf_string The generated PDF to be saved 
  233. * @return string|boolean The full path to the file or false if failed 
  234. * @throws Exception 
  235. * @since 4.0 
  236. */ 
  237. public function save_pdf( $raw_pdf_string ) { 
  238.  
  239. /** create our path */ 
  240. if ( ! is_dir( $this->path ) ) { 
  241. if ( ! wp_mkdir_p( $this->path ) ) { 
  242. throw new Exception( sprintf( 'Could not create directory: %s' ), esc_html( $this->path ) ); 
  243.  
  244. /** save our PDF */ 
  245. if ( ! file_put_contents( $this->path . $this->filename, $raw_pdf_string ) ) { 
  246. throw new Exception( sprintf( 'Could not save PDF: %s', $this->path . $this->filename ) ); 
  247.  
  248. return $this->path . $this->filename; 
  249.  
  250. /** 
  251. * Get the correct path to the PHP template we should load into mPDF 
  252. * @throws Exception 
  253. * @since 4.0 
  254. */ 
  255. public function set_template() { 
  256.  
  257. $template = ( isset( $this->settings['template'] ) ) ? $this->settings['template'] : ''; 
  258.  
  259. /** Allow a user to change the current template if they have the appropriate capabilities */ 
  260. if ( rgget( 'template' ) && is_user_logged_in() && $this->gform->has_capability( 'gravityforms_edit_settings' ) ) { 
  261. $template = rgget( 'template' ); 
  262.  
  263. /** Handle legacy v3 URL structure and strip .php from the end of the template */ 
  264. if ( isset( $_GET['gf_pdf'] ) && isset( $_GET['fid'] ) && isset( $_GET['lid'] ) ) { 
  265. $template = substr( $template, 0, -4 ); 
  266.  
  267. try { 
  268. $this->template_path = $this->templates->get_template_path_by_id( $template ); 
  269. } catch ( Exception $e ) { 
  270. throw $e; 
  271.  
  272. /** Check if there are version requirements */ 
  273. $template_info = $this->templates->get_template_info_by_path( $this->template_path ); 
  274. if ( ! $this->templates->is_template_compatible( $template_info['required_pdf_version'] ) ) { 
  275. throw new Exception( sprintf( esc_html__( 'The PDF Template %s requires Gravity PDF version %s. Upgrade to the latest version.', 'gravity-forms-pdf-extended' ), "<em>$template</em>", "<em>{$template_info['required_pdf_version']}</em>" ) ); 
  276.  
  277. /** 
  278. * Gets the current directory template files are being included from. 
  279. * This is set in the set_template() method 
  280. * @return string 
  281. * @since 4.0 
  282. */ 
  283. public function get_template_path() { 
  284. return $this->template_path; 
  285.  
  286. /** 
  287. * Public endpoint to allow users to control how the generated PDF will be displayed 
  288. * @param string $type Only display, download or save options are valid 
  289. * @throws Exception 
  290. * @since 4.0 
  291. */ 
  292. public function set_output_type( $type ) { 
  293. $valid = [ 'DISPLAY', 'DOWNLOAD', 'SAVE' ]; 
  294.  
  295. if ( ! in_array( strtoupper( $type ), $valid ) ) { 
  296. throw new Exception( sprintf( 'Display type not valid. Use %s', implode( ', ', $valid ) ) ); 
  297.  
  298. $this->output = strtoupper( $type ); 
  299.  
  300.  
  301. /** 
  302. * Get the current PDF output type as per the set_output_type() method. 
  303. * @return string 
  304. * @since 4.0 
  305. */ 
  306. public function get_output_type() { 
  307. return $this->output; 
  308.  
  309. /** 
  310. * Set the PDF meta data, including title, author, creator and subject 
  311. * @since 4.0 
  312. */ 
  313. protected function set_metadata() { 
  314. $this->mpdf->SetTitle( strcode2utf( strip_tags( $this->get_filename() ) ) ); 
  315. $this->mpdf->SetAuthor( strcode2utf( strip_tags( get_bloginfo( 'name' ) ) ) ); 
  316.  
  317. /** 
  318. * Public Method to mark the PDF document creator 
  319. * @param string $text The PDF Creator 
  320. * @since 4.0 
  321. */ 
  322. public function set_creator( $text = '' ) { 
  323. if ( empty( $text ) ) { 
  324. $this->mpdf->SetCreator( 'Gravity PDF v' . PDF_EXTENDED_VERSION . '. https://gravitypdf.com' ); 
  325. } else { 
  326. $this->mpdf->SetCreator( $text ); 
  327.  
  328. /** 
  329. * Public Method to set how the PDF should be displyed when first open 
  330. * @param mixed $mode A string or integer setting the zoom mode 
  331. * @param string $layout The PDF layout format 
  332. * @throws Exception 
  333. * @since 4.0 
  334. */ 
  335. public function set_display_mode( $mode = 'fullpage', $layout = 'continuous' ) { 
  336.  
  337. $valid_mode = [ 'fullpage', 'fullwidth', 'real', 'default' ]; 
  338. $valid_layout = [ 'single', 'continuous', 'two', 'twoleft', 'tworight', 'default' ]; 
  339.  
  340. /** check the mode */ 
  341. if ( ! in_array( strtolower( $mode ), $valid_mode ) ) { 
  342. /** determine if the mode is an integer */ 
  343. if ( ! is_int( $mode ) || $mode <= 10 ) { 
  344. throw new Exception( sprintf( 'Mode must be an number value more than 10 or one of these types: %s', implode( ', ', $valid_mode ) ) ); 
  345.  
  346. /** check the layout */ 
  347. if ( ! in_array( strtolower( $layout ), $valid_layout ) ) { 
  348. throw new Exception( sprintf( 'Layout must be one of these types: %s', implode( ', ', $valid_layout ) ) ); 
  349.  
  350. $this->mpdf->SetDisplayMode( $mode, $layout ); 
  351.  
  352.  
  353. /** 
  354. * Public Method to allow the print dialog to be display when PDF is opened 
  355. * @param boolean $print Whether the PDF should open the print dialog every time the PDF is opened 
  356. * @throws Exception 
  357. * @since 4.0 
  358. */ 
  359. public function set_print_dialog( $print = true ) { 
  360. if ( ! is_bool( $print ) ) { 
  361. throw new Exception( 'Only boolean values true and false can been passed to setPrintDialog().' ); 
  362.  
  363. $this->print = $print; 
  364.  
  365. /** 
  366. * Generic PDF JS Setter function 
  367. * @param string $js The PDF Javascript to execute 
  368. * @since 4.0 
  369. */ 
  370. public function set_JS( $js ) { 
  371. $this->mpdf->SetJS( $js ); 
  372.  
  373. /** 
  374. * Get the current Gravity Form Entry 
  375. * @return string 
  376. * @since 4.0 
  377. */ 
  378. public function get_entry() { 
  379. return $this->entry; 
  380.  
  381. /** 
  382. * Get the current PDF Settings 
  383. * @return string 
  384. * @since 4.0 
  385. */ 
  386. public function get_settings() { 
  387. return $this->settings; 
  388.  
  389. /** 
  390. * Get the current PDF Name 
  391. * @return string 
  392. * @since 4.0 
  393. */ 
  394. public function get_filename() { 
  395. return $this->filename; 
  396.  
  397. /** 
  398. * Generate the PDF filename used 
  399. * @param string $filename The PDF filename you want to use 
  400. * @since 4.0 
  401. */ 
  402. public function set_filename( $filename ) { 
  403. $this->filename = $this->misc->get_file_with_extension( $filename, '.pdf' ); 
  404.  
  405. /** 
  406. * Get the current PDF path 
  407. * @return string 
  408. * @since 4.0 
  409. */ 
  410. public function get_path() { 
  411. return $this->path; 
  412.  
  413. /** 
  414. * Sets the path the PDF should be saved to 
  415. * @param string $path 
  416. * @return void 
  417. * @since 4.0 
  418. */ 
  419. public function set_path( $path = '' ) { 
  420.  
  421. if ( empty( $path ) ) { 
  422. /** build our PDF path location */ 
  423. $path = $this->data->template_tmp_location . $this->entry['form_id'] . $this->entry['id'] . '/'; 
  424. } else { 
  425. /** ensure the path ends with a forward slash */ 
  426. if ( substr( $path, -1 ) !== '/' ) { 
  427. $path .= '/'; 
  428.  
  429. $this->path = $path; 
  430.  
  431. /** 
  432. * Gets the absolute path to the PDF 
  433. * Works with our legacy Tier 2 add-on without adding a filter because we have stuck with the same naming convension 
  434. * @return string The full path and filename of the PDF 
  435. * @since 4.0 
  436. */ 
  437. public function get_full_pdf_path() { 
  438. return $this->get_path() . $this->get_filename(); 
  439.  
  440. /** 
  441. * Initialise our mPDF object 
  442. * @return void 
  443. * @since 4.0 
  444. */ 
  445. protected function begin_pdf() { 
  446. $this->mpdf = new mPDF( '', $this->paper_size, 0, '', 15, 15, 16, 16, 9, 9, $this->orientation ); 
  447.  
  448. /** 
  449. * Allow $mpdf object class to be modified 
  450. * Note: in some circumstances using WriteHTML() during this filter will break headers/footers 
  451. * See https://gravitypdf.com/documentation/v4/gfpdf_mpdf_init_class/ for more details about this filter 
  452. */ 
  453. $this->mpdf = apply_filters( 'gfpdf_mpdf_init_class', $this->mpdf, $this->form, $this->entry, $this->settings, $this ); 
  454.  
  455. /** 
  456. * Set up the paper size and orentation 
  457. * @throws Exception 
  458. * @since 4.0 
  459. */ 
  460. protected function set_paper() { 
  461.  
  462. /** Get the paper size from the settings */ 
  463. $paper_size = ( isset( $this->settings['pdf_size'] ) ) ? strtoupper( $this->settings['pdf_size'] ) : 'A4'; 
  464.  
  465. $valid_paper_size = [ 
  466. '4A0',  
  467. '2A0',  
  468. 'A0',  
  469. 'A1',  
  470. 'A2',  
  471. 'A3',  
  472. 'A4',  
  473. 'A5',  
  474. 'A6',  
  475. 'A7',  
  476. 'A8',  
  477. 'A9',  
  478. 'A10',  
  479. 'B0',  
  480. 'B1',  
  481. 'B2',  
  482. 'B3',  
  483. 'B4',  
  484. 'B5',  
  485. 'B6',  
  486. 'B7',  
  487. 'B8',  
  488. 'B9',  
  489. 'B10',  
  490. 'C0',  
  491. 'C1',  
  492. 'C2',  
  493. 'C3',  
  494. 'C4',  
  495. 'C5',  
  496. 'C6',  
  497. 'C7',  
  498. 'C8',  
  499. 'C9',  
  500. 'C10',  
  501. 'RA0',  
  502. 'RA1',  
  503. 'RA2',  
  504. 'RA3',  
  505. 'RA4',  
  506. 'SRA0',  
  507. 'SRA1',  
  508. 'SRA2',  
  509. 'SRA3',  
  510. 'SRA4',  
  511. 'LETTER',  
  512. 'LEGAL',  
  513. 'LEDGER',  
  514. 'TABLOID',  
  515. 'EXECUTIVE',  
  516. 'FOILIO',  
  517. 'B',  
  518. 'A',  
  519. 'DEMY',  
  520. 'ROYAL',  
  521. 'CUSTOM',  
  522. ]; 
  523.  
  524. if ( ! in_array( $paper_size, $valid_paper_size ) ) { 
  525. throw new Exception( sprintf( 'Paper size not valid. Use %s', implode( ', ', $valid_paper_size ) ) ); 
  526.  
  527. /** set our paper size and orientation based on user selection */ 
  528. if ( $paper_size == 'CUSTOM' ) { 
  529. $this->set_custom_paper_size(); 
  530. $this->set_orientation( true ); 
  531. } else { 
  532. $this->set_paper_size( $paper_size ); 
  533. $this->set_orientation(); 
  534.  
  535. /** 
  536. * Set our paper size using pre-defined values 
  537. * @param string $size The paper size to be set 
  538. * @since 4.0 
  539. */ 
  540. protected function set_paper_size( $size ) { 
  541. $this->paper_size = $size; 
  542.  
  543. /** 
  544. * Set our custom paper size which will be a 2-key array signifying the 
  545. * width and height of the paper stock 
  546. * @throws Exception 
  547. * @since 4.0 
  548. */ 
  549. protected function set_custom_paper_size() { 
  550. $custom_paper_size = ( isset( $this->settings['custom_pdf_size'] ) ) ? $this->settings['custom_pdf_size'] : []; 
  551.  
  552. if ( sizeof( $custom_paper_size ) !== 3 ) { 
  553. throw new Exception( 'Custom paper size not valid. Array should contain three keys: width, height and unit type' ); 
  554.  
  555. $this->paper_size = $this->get_paper_size( $custom_paper_size ); 
  556.  
  557.  
  558. /** 
  559. * Ensure the custom paper size has the correct values 
  560. * @param array $size 
  561. * @return array 
  562. * @since 4.0 
  563. */ 
  564. protected function get_paper_size( $size ) { 
  565. $size[0] = ( $size[2] == 'inches' ) ? (int) $size[0] * 25.4 : (int) $size[0]; 
  566. $size[1] = ( $size[2] == 'inches' ) ? (int) $size[1] * 25.4 : (int) $size[1]; 
  567.  
  568. /** tidy up custom paper size array */ 
  569. unset( $size[2] ); 
  570.  
  571. return $size; 
  572.  
  573. /** 
  574. * Set the page orientation based on the paper size selected 
  575. * @param boolean $custom Whether a predefined paper size was used, or a custom size 
  576. * @return void 
  577. * @since 4.0 
  578. */ 
  579. protected function set_orientation( $custom = false ) { 
  580.  
  581. $orientation = ( isset( $this->settings['orientation'] ) ) ? strtolower( $this->settings['orientation'] ) : 'portrait'; 
  582.  
  583. /** 
  584. * If using a custom paper size (with an array) we'll pass in the L or P. If standard paper size the -L attribute needs to be added to the $paper_size argument. 
  585. * @todo Update mPDF to be more consistent when setting portrait and landscape documentation 
  586. */ 
  587. if ( $custom ) { 
  588. $this->orientation = ( $orientation == 'landscape' ) ? 'L' : 'P'; 
  589. } else { 
  590. $this->orientation = ( $orientation == 'landscape' ) ? '-L' : ''; 
  591. $this->paper_size .= $this->orientation; 
  592.  
  593. /** 
  594. * Load our PHP template file and return the buffered HTML 
  595. * @param array $args Any arguments that should be passed to the PDF template file 
  596. * @return string The buffered HTML to pass into mPDF 
  597. * @since 4.0 
  598. */ 
  599. protected function load_html( $args = [] ) { 
  600. /** for backwards compatibility extract the $args variable */ 
  601. extract( $args, EXTR_SKIP ); /** skip any arguments that would clash - i.e filename, args, output, path, this */ 
  602.  
  603. ob_start(); 
  604. include $this->template_path; 
  605.  
  606. return ob_get_clean(); 
  607.  
  608.  
  609. /** 
  610. * Allow site admins to view the RAW HTML if needed 
  611. * @param string $html The HTML that should be output to the browser 
  612. * @return void 
  613. * @since 4.0 
  614. */ 
  615. protected function maybe_display_raw_html( $html ) { 
  616.  
  617. if ( $this->output !== 'SAVE' && rgget( 'html' ) && $this->gform->has_capability( 'gravityforms_edit_settings' ) ) { 
  618. echo apply_filters( 'gfpdf_pre_html_browser_output', $html, $this->settings, $this->entry, $this->gform, $this ); 
  619. exit; 
  620.  
  621. /** 
  622. * Prompt the print dialog box 
  623. * @return void 
  624. * @since 4.0 
  625. */ 
  626. protected function show_print_dialog() { 
  627. if ( $this->print ) { 
  628. $this->mpdf->setJS( 'this.print();' ); 
  629.  
  630. /** 
  631. * Sets the image DPI in the PDF 
  632. * @return void 
  633. * @since 4.0 
  634. */ 
  635. protected function set_image_dpi() { 
  636. $dpi = ( isset( $this->settings['image_dpi'] ) ) ? (int) $this->settings['image_dpi'] : 96; 
  637.  
  638. $this->mpdf->img_dpi = $dpi; 
  639.  
  640. /** 
  641. * Sets the text direction in the PDF (RTL support) 
  642. * @return void 
  643. * @since 4.0 
  644. */ 
  645. protected function set_text_direction() { 
  646. $rtl = ( isset( $this->settings['rtl'] ) ) ? $this->settings['rtl'] : 'No'; 
  647.  
  648. if ( strtolower( $rtl ) == 'yes' ) { 
  649. $this->mpdf->SetDirectionality( 'rtl' ); 
  650.  
  651. /** 
  652. * Set the correct PDF Format 
  653. * Normal, PDF/A-1b or PDF/X-1a 
  654. * @return void 
  655. * @since 4.0 
  656. */ 
  657. protected function set_pdf_format() { 
  658. switch ( strtolower( $this->settings['format'] ) ) { 
  659. case 'pdfa1b': 
  660. $this->mpdf->PDFA = true; 
  661. $this->mpdf->PDFAauto = true; 
  662. break; 
  663.  
  664. case 'pdfx1a': 
  665. $this->mpdf->PDFX = true; 
  666. $this->mpdf->PDFXauto = true; 
  667. break; 
  668.  
  669. /** 
  670. * Add PDF Security, if able 
  671. * @return void 
  672. * @since 4.0 
  673. */ 
  674. protected function set_pdf_security() { 
  675. /** Security settings cannot be applied to pdfa1b or pdfx1a formats */ 
  676. if ( strtolower( $this->settings['format'] ) == 'standard' && strtolower( $this->settings['security'] == 'Yes' ) ) { 
  677.  
  678. $password = ( isset( $this->settings['password'] ) ) ? $this->gform->process_tags( $this->settings['password'], $this->form, $this->entry ) : ''; 
  679. $privileges = ( isset( $this->settings['privileges'] ) ) ? $this->settings['privileges'] : []; 
  680. $master_password = ( isset( $this->settings['master_password'] ) ) ? $this->gform->process_tags( $this->settings['master_password'], $this->form, $this->entry ) : null; 
  681.  
  682. $this->mpdf->SetProtection( $privileges, $password, $master_password, 128 ); 
  683.  
  684.  
  685. /** 
  686. * Ensure the PDF doesn't get cached 
  687. * @since 4.0 
  688. */ 
  689. protected function prevent_caching() { 
  690. if ( ! defined( 'DONOTCACHEPAGE' ) ) { 
  691. define( 'DONOTCACHEPAGE', true );