Hello @rokeyfx,
I can provide you another code snippet to set the width to 80mm, but it will require several CSS rules to fit your invoice elements to the right place and size.
My recommendation is to use Premium Templates since this extension includes a customizer that allows you to tailor your PDF documents using product columns, total rows, and custom blocks.
However, here is the code for you:
add_filter( 'wpo_wcpdf_paper_format', function( $paper_format, $document_type) {
// change the values below
$width = 80; //mm!
$height = 115; //mm!
//convert mm to points
$paper_format = array( 0, 0, ($width/25.4) * 72, ($height/25.4) * 72 );
return $paper_format;
}, 10, 2 );
add_filter( 'wpo_wcpdf_before_dompdf_render', function( $_dompdf, $html )
{
$_dompdf_options = $_dompdf->getOptions();
$_dompdf_paper_size = $_dompdf->getPaperSize();
$_dompdf_paper_orientation = $_dompdf->getPaperOrientation();
$GLOBALS['wpo_wcpdf_dompdf_body_height'] = 0;
$_dompdf->setCallbacks(
array(
'myCallbacks' => array(
'event' => 'end_frame',
'f' => function ( $infos ) {
$frame = $infos["frame"];
if ( strtolower( $frame->get_node()->nodeName ) === "body" ) {
$padding_box = $frame->get_padding_box();
$GLOBALS['wpo_wcpdf_dompdf_body_height'] += $padding_box['h'];
}
},
)
)
);
$_dompdf->loadHtml( $html );
$_dompdf->render();
unset( $_dompdf );
if( ! empty( $_dompdf_paper_size ) ) {
$_dompdf_paper_size[3] = $GLOBALS['wpo_wcpdf_dompdf_body_height'] + 150; // if too many space at the bottom, replace this 150 value with a lower one
}
$dompdf = new \Dompdf\Dompdf( $_dompdf_options );
$dompdf->loadHtml( $html );
$dompdf->setPaper( $_dompdf_paper_size, $_dompdf_paper_orientation );
return $dompdf;
}, 10, 2 );