Skip Navigation

[Resolved] Help with Displaying PDF preview thumbnails code

This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Author
Posts
#1141338
testpdf.jpg
testpdf code.jpg

Hi

I am trying to get the display pdf thumbnail code to work as per this post. This was oroiginally written by Noman
https://toolset.com/forums/topic/how-to-display-thumbnails-of-of-pdfs-uploaded-to-the-types-document-field/

Below is a screenshot of my content template - the post pody for reference just show the url of the document, plus the urls of the thumbnails I see generated on the server.

the grey box below show the output from the 4 following shortcodes

[getpublicationpdfimg]
[getpublicationpdfimg size="large"]
[getpublicationpdfimg size="medium"]
[getpublicationpdfimg size="small"]

I slightly amended the str_relace() to the below which is more in line with the url generated for the thumbnail

$image_url = str_replace(".pdf", "-pdf.jpg", types_render_field( "key-document-eng")); // publication_document = your field name

This is the only change I have done to the code

See screenshot attached hidden link (it is password protected)

I am trying to display a thumbnail which links to the actual file. The php code seems to generate an https://toolset.com/forums/topic/displaying-preview-images-of-uploaded-pdf/ Thanks

#1141973

Hi,

Thanks for the details,

Q1) So I am trying to tweak the php to achive just a thumbnail which links to the url.
You can change the PHP codes from:

$image_url = str_replace(".pdf", "-pdf.jpg", types_render_field( "key-document-eng")); // publication_document = your field name

To:

$image_url = str_replace(".pdf", "-pdf.jpg", types_render_field( "key-document-eng", array('output'=> 'raw'))); // publication_document = your field name

More help:
https://toolset.com/documentation/customizing-sites-using-php/functions/#file
output:
'raw' | 'normal'(default)

Q2) Secondly I noticed on screenshot the shortcodes for different sizes output the same html
I suggest you modify that custom shortcode, output only the image URL, then setup the HTML codes as what you want, for example:
Change this line from:

return '<img src='.$image_src.' class="pubdoc-pdf-image">';

To:

return $image_src;

Then setup your HTML codes manually like this:

<a href="{!{types field='key-document-eng' output='raw'}!}{!{/types}!}"><img src="{!{getpublicationpdfimg}!}"></a>
#1144494

Hi
Sorry for the delay and thanks for the response
This seems to work fine.

Something I forgot to ask would be how to extend this to also also display title and description - from the metadata of the file

Thanks

New threads created by Luo Yang and linked to this one are listed below:

https://toolset.com/forums/topic/display-title-and-description-from-the-metadata-of-the-pdf-file/

#1144793

I assume the original question of this thread is resolved, for the new question, please check the new thread:
https://toolset.com/forums/topic/display-title-and-description-from-the-metadata-of-the-pdf-file/

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.