Title: pdf height
Last modified: March 18, 2021

---

# pdf height

 *  Resolved [Rokeybur Rahman](https://wordpress.org/support/users/rokeyfx/)
 * (@rokeyfx)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/pdf-height/)
 * is there any way set pdf height based on content on the pdf. We have link pdf
   to printing setup. if I use width and height it print properly on my 80mm printer.
   
   but it make problem when item is too many on the invoice. I try to set width 
   and disable height filter code but it break the pdf.
 * So let me know is there anyway i can set pdf width 80mm and height auto?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Contributor [Yordan Soares](https://wordpress.org/support/users/yordansoares/)
 * (@yordansoares)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/pdf-height/#post-14203440)
 * Hello [@rokeyfx](https://wordpress.org/support/users/rokeyfx/),
 * Please add this code snippet to your site to set the PDF height of the content:
 *     ```
       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;
       	}
   
       	$dompdf = new \Dompdf\Dompdf( $_dompdf_options );
       	$dompdf->loadHtml( $html );
       	$dompdf->setPaper( $_dompdf_paper_size, $_dompdf_paper_orientation );
   
       	return $dompdf;
       }, 10, 2 );
       ```
   
 * If you haven’t worked with code snippets (actions/filters) or functions.php before,
   read this guide: [How to use filters](https://docs.wpovernight.com/general/how-to-use-filters/)
 * Let me know if it works!
 *  Thread Starter [Rokeybur Rahman](https://wordpress.org/support/users/rokeyfx/)
 * (@rokeyfx)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/pdf-height/#post-14203890)
 * it work with auto height. but now how i set width 80mm fixed?
 *  Plugin Contributor [Yordan Soares](https://wordpress.org/support/users/yordansoares/)
 * (@yordansoares)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/pdf-height/#post-14203967)
 * Hello [@rokeyfx](https://wordpress.org/support/users/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](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-premium-templates/)
   since this extension includes a customizer that allows you to tailor your PDF
   documents using product columns, total rows, and [custom blocks](https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/using-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 );
       ```
   
 *  Thread Starter [Rokeybur Rahman](https://wordpress.org/support/users/rokeyfx/)
 * (@rokeyfx)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/pdf-height/#post-14204031)
 * Thank you.
 *  Thread Starter [Rokeybur Rahman](https://wordpress.org/support/users/rokeyfx/)
 * (@rokeyfx)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/pdf-height/#post-14241479)
 * Hi another request.
    is there anyway disable page break? so it make very long
   pdf.
 *  Plugin Contributor [Yordan Soares](https://wordpress.org/support/users/yordansoares/)
 * (@yordansoares)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/pdf-height/#post-14241732)
 * Hello [@rokeyfx](https://wordpress.org/support/users/rokeyfx/),
 * Use the code that [I left you above](https://wordpress.org/support/topic/pdf-height/#post-14203967)
   to get a unique sheet of 80 mm width per order, special for continuous feed printers.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘pdf height’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-pdf-invoices-packing-slips/assets/icon-256x256.
   png?rev=2189942)
 * [PDF Invoices & Packing Slips for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [Yordan Soares](https://wordpress.org/support/users/yordansoares/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/pdf-height/#post-14241732)
 * Status: resolved