• Hi,

    We are using a continuous label roll for our packing slips. The printer will automatically cut the label at the end of the page. I was wondering, is it possible (please say it is) for the page height to be equal to the end of data on the page.

    So [END PAGE] is right after the last piece of content for the packing slip?

    Hope that made sense.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @petfresh

    Is not very easy to achieve that, because it’s difficult to know the items height effectively. Nevertheless, please add the code snippet below to your functions.php file:

    add_filter( 'wpo_wcpdf_paper_format', 'wcpdf_dynamic_page_size', 10, 3 );
    function wcpdf_dynamic_page_size( $paper_format, $document_type, $document ) {
    	// set width & height in mm
    	$width       = 80;
    	$min_height  = 150;
    	$base_height = 140;
    	$height = $base_height;
    	if ( !empty($order = $document->order )) {
    		foreach( $order->get_items() as $item ) {
    			$product = $item->get_product();
    			if( $product->get_type() == 'simple' ) {
    				$height += 12; // adjust for simple products
    			} else {
    				$height += 50; // adjust for variable products ( includes meta )
    			}
    		}
    		$height = max($min_height, $height);
    	} else {
    		$height = $min_height;
    	}
    
    	//convert mm to points
    	$paper_format = array( 0, 0, ($width/25.4) * 72, ($height/25.4) * 72 );
    	return $paper_format;
    }

    If you never worked with actions/filters, please read this documentation page: How to use filters

    Thread Starter petfresh

    (@petfresh)

    Hi,

    Wanting to make it so that for an item without any meta printed, it should only give an extra 15 of space, and if it does have meta, it should provide 30 of space.

    I changed part of the snippet to this, but I am having trouble detecting if an item has meta. Could you help?

    if ( !empty($order = $document->order )) {
    			foreach( $order->get_items() as $item ) {
    				$product = $item->get_product();
    					if (isset ($item['meta'])) {
    						$height += 30; // adjust for simple products
    					} else {
    						$height += 15; // adjust for simple products
    					}
    			$height = max($min_height, $height);
    	} else {
    		$height = $min_height;
    	}
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Page end when content ends’ is closed to new replies.