Changing the orientation of a PDF from portrait to landscape

If you are using the DataTables layout, it's possible to export your visible entries to a PDF. By default, PDFs are rendered in portrait mode (vertically).

If your View has lots of columns, this portrait mode may not be able to accommodate all the information available, therefore we need to change its orientation to landscape (horizontal).

Here's how:

/**
 * Modify the PDF button configuration for a specific View.
 *
 * @param array $button_config The current button configuration.
 * @param int   $view_id       The ID of the current View.
 * @return array Modified button configuration.
 */
add_filter('gravityview/datatables/button_pdf', function( $button_config, $view_id ) {
	if ( $view_id == 19 ) {
		$button_config['orientation'] = 'landscape';
	}

	return $button_config;
}, 10, 2);

Make sure to replace 19  in the code above with your specific View ID so that only that View will have the PDF in portrait mode.

Learn where to add this code sample:  Where do I add the code samples you share?

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us