Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Yes this is possible, but not out of the box. You will have to add that to the $dompdf object in class-wcpdf-export.php, probably just before the render() call in line 130.
    see: https://stackoverflow.com/questions/12190294/prevent-copying-content-in-a-pdf-that-is-created-with-dompdf for more information.

    This is beyond the scope of this plugin (and support) though!

    Hey @ewout i’ve tried your method, and the PDF gets password protected but it displays a blank pdf without any billing info.
    Here’s the code! (extracted from plugin)

    /**
    		 * Create & render DOMPDF object
    		 */
    		public function generate_pdf( $template_type, $order_ids )	{
    			$paper_size = apply_filters( 'wpo_wcpdf_paper_format', $this->template_settings['paper_size'], $template_type );
    			$paper_orientation = apply_filters( 'wpo_wcpdf_paper_orientation', 'portrait', $template_type);
    
    			do_action( 'wpo_wcpdf_before_pdf', $template_type );
    			if ( !class_exists('DOMPDF') ) {
    				// extra check to avoid clashes with other plugins using DOMPDF
    				// This could have unwanted side-effects when the version that's already
    				// loaded is different, and it could also miss fonts etc, but it's better
    				// than not checking...
    				require_once( WooCommerce_PDF_Invoices::$plugin_path . "lib/dompdf/dompdf_config.inc.php" );
    			}
    
    			$dompdf = new DOMPDF();
    			$dompdf->load_html($this->process_template( $template_type, $order_ids ));
    			$dompdf->render();
    			do_action( 'wpo_wcpdf_after_pdf', $template_type );
    
    			// Set Password
    			$dompdf->get_canvas()->get_cpdf()->setEncryption('userpass', 'ownerpass', array('print'));
    
    			// Try to clean up a bit of memory
    
    			unset($complete_pdf);
    
    			return $dompdf;
    		}
    
    		/**
    		 * Stream PDF
    		 */
    		public function stream_pdf( $template_type, $order_ids, $filename ) {
    
    			$dompdf = $this->generate_pdf( $template_type, $order_ids );
    			$dompdf->stream($filename);

    I know i must initiate the set password function between render and stream calls but the results i get is a blank password protected pdf with only black lines (from template i guess).

    And if you get to develop this into a next version of the plugin, this will be the only plugin with such capability. (believe me i’ve searched everywhere)

    Plugin Contributor Ewout

    (@pomegranate)

    Hi,
    I think you should add the password before the render() call, rather than after it! Let me know if that helps!

    Ewout

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can we password protect the generated Invoice or Packing Slips?’ is closed to new replies.