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)