PDF Thumbnail in Upload?
PDF Thumbnail in Upload?
I'm using the standard upload function. Images correctly display thumbnails. How do I get a PDF that's uploaded to display a thumbnail. Currently it just displays a small broken file icon.
From the HTML:
{ "className": "dt-right", data: "image",
render: function ( file_id ) {
return file_id ?
'<img src="'+editor.file( 'files', file_id ).web_path+'" class="img-circle" width="40" height="40"/>' :
null;
},
defaultContent: "No image",
title: "image"
}
From the PHP:
Field::inst( 'image' )
->setFormatter( 'Format::ifEmpty', null )
->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/upload/__ID__.__EXTN__' )
->db( 'files', 'id', array(
'filename' => Upload::DB_FILE_NAME,
'filesize' => Upload::DB_FILE_SIZE,
'web_path' => Upload::DB_WEB_PATH,
'system_path' => Upload::DB_SYSTEM_PATH
) )
->validator( function ( $file ) {
return$file['size'] >= 2000000 ?
"Files must be smaller than 2M" :
null;
} )
->allowedExtensions( array( 'png', 'jpg', 'gif', 'pdf' ), "Please upload an image" )
)
Also, I notice that if I use 'filetype' => Upload::DB_EXTN in PHP, I receive a browser error:
DataTables warning: table id=example - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'filetype' in 'field list'?
{this is a repost of a topic originally posted under "General."
This question has an accepted answers - jump to answer
Answers
You'd most likely need to use a pdf renderer on the server-side to convert the pdf to a jpg / png / gif so it can be easily displayed in the browser. While browsers can display pdf's they can't (as far as I am aware) display them as they do images (i.e. inline with the other HTML).
A custom upload action could be used to do that conversion.
Allan
Thanks.
Also, do you have any insight here:
I notice that if I use 'filetype' => Upload::DB_EXTN in PHP, I receive a browser error:
DataTables warning: table id=example - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'filetype' in 'field list'?
Oh yes, sorry I forgot to address that point.
The error means that your database table for the file meta information doesn't have a column by the name of
filetype
. Possibly its a case issue -fileType
for example?Thanks,
Allan
Thanks!