[SOLVED] Creating Thumbnails for PDF

How to create a thumbnail of the first page of a PDF document in frontend, as it is done in media browserin backend?

Did I miss the correct viewhelper or a setting with them?

Hi Erich,

What did you try so far?

You can read the source code for rendering of the media browser and copy/paste from there to your needs :slight_smile:

https://github.com/neos/media-browser/blob/master/

I was looking at it and came to assetProxy which seems to be a backend way to go. So I was wondering if there is a frontend way to do the same.

So finaly I got a solution. I created a viewhelper that is able to get the url of the media-browser thumbnails of the PDF. I know, that is not the correct way to do it, but it works:

    public function render(): string
{
    /** @var AssetProxyInterface $assetProxy */
    $asset = $this->arguments['asset'];
    $width= $this->arguments['width'];
    $height= $this->arguments['height'];

    if ($width === null || $height === null) {
        $width = 250;
        $height = 250;
    }

    $thumbnailUri = $asset->getAssetProxy()->getThumbnailUri();
    $this->tag->addAttributes([
        'width' => $width,
        'height' => $height,
        'src' => $thumbnailUri
    ]);

    return $this->tag->render();
}

Couldn’t you use the thumbnail view helper in the Media package? Looks like it does the same as yours, but with more features.

And the ImageUri Fusionobject also accepts any kind of asset afaik.

OMG!!!

Yes, the media package now works as expected.

I was hunting the wrong victim. According to my settings which I corrected in PDF thumbnails in media-browser get wrong colors I always got the PDF Document Type Icon instead of an image of the first page. But I didn’t recognize it, because of data imported from other servers …

Now everything is fine. Thx @sebobo for the hint.

(Can anyone mark this as solved?)

1 Like