Upload - Display Thumbnail of PDF

Upload - Display Thumbnail of PDF

hamlet1964hamlet1964 Posts: 43Questions: 8Answers: 1

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" )
        )

Replies

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    edited July 2018

    Duplicate of this thread (or rather, this one is the dup and I missed this one initially!).

    Allan

This discussion has been closed.