There’s a filter you can use, but nothing directly on a per PDF basis.
$atts = apply_filters( 'embed_pdf_viewer_pdf_attributes', $atts );
The $atts is an array with $atts['height'] and $atts['width'] whose values are set as pixels.
Thread Starter
Guido
(@guido07111975)
Hi Andy,
Thanks, have added this simple code snippet in my theme functions file:
// add custom height and width
function my_callback() {
$atts['height'] = '1000';
$atts['width'] = '1200';
return $atts;
}
add_filter( 'embed_pdf_viewer_pdf_attributes', 'my_callback', 11 );
Guido
You should pass the $atts parameter into the function also.
function my_callback( $atts ) {
Thread Starter
Guido
(@guido07111975)
Thanks Andy,
It does work without, but I’m not a hardcore coder so still have much to learn. Can you please explain why I need to add that?
Guido
In WordPress, filter hooks always pass at least one parameter. This is the parameter or value that the user changes. If you know the format and expected contents of the return value then it’s not a problem.
In this case, only returning the values for width and height and not the value for ‘title’, will result in a unset value for title.
Perhaps a better way to explain this is when a filter passes an array, change the values you want and return the entire array.
Thread Starter
Guido
(@guido07111975)
Understood, thanks for the clarification!
For other users with the same width issue: in my case the viewer had a certain width because of the Content Width that was set in file functions of my theme.
Guido