Support » Plugin: Exports and Reports » Is it possible to change css from pdf?

Viewing 1 replies (of 1 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    There’s not a hook to customize that at the moment. It’s pretty complicated unfortunately due to how the TCPDF class works. But if you are willing to dive into those TCPDF customizations, you can use a filter to workaround there.

    
    add_filter( 'exports_and_reports_pdf_content', 'my_custom_pdf_overrides', 10, 3 );
    
    /**
     * Override the PDF handling.
     *
     * @param string      $output Override the HTML of the PDF, default is empty (will build after this filter is called).
     * @param WP_Admin_UI $admin  The admin class to reference.
     * @param TCPDF       $pdf    The PDF class to reference.
     */
    function my_custom_pdf_overrides( $output, $admin, $pdf ) {
    	// set document information
    	$pdf->SetTitle( $admin->items );
    	$pdf->SetAuthor( 'Admin' );
    
    	// set header and footer fonts
    	$pdf->setHeaderFont( array( PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN ) );
    	$pdf->setFooterFont( array( PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA ) );
    
    	// set default monospaced font
    	$pdf->SetDefaultMonospacedFont( PDF_FONT_MONOSPACED );
    
    	// set margins
    	$pdf->SetMargins( 2, PDF_MARGIN_TOP, 2 );
    	$pdf->setHeaderMargin( PDF_MARGIN_HEADER );
    	$pdf->setFooterMargin( PDF_MARGIN_FOOTER );
    
    	// set auto page breaks
    	$pdf->SetAutoPageBreak( true, PDF_MARGIN_BOTTOM );
    
    	// set image scale factor
    	$pdf->setImageScale( PDF_IMAGE_SCALE_RATIO );
    
    	// set font
    	$pdf->SetFont( 'courier', '', 9 );
    }
    

    I’ve included some example customizations, but those are what’s used by the PDF builder class itself, so you can easily tweak them to suit your needs. Feel free to customize further or look up TCPDF (this is version 6.2.13) documentation to further customize or find other methods you can call.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.