Forums / Developer / New extension: SnapshotPDF

New extension: SnapshotPDF

Author Message

Felix Laate

Friday 20 January 2006 5:32:07 am

Hi all,

I just uploaded a new extension to http://ez.no/community/contribs/template_plugins/snapshotpdf

It is similar to the Snapshot extension, only that this one grab a page of a pdf and returns a jpg.

If anyone has comments, they are apreciated here!

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

Xavier Dutoit

Friday 20 January 2006 1:29:27 pm

Hi,

Would this extension be possible to use to populate an image attribute ?

My idea is to add an attribute image to the class file, and automatically populate it with the snapshot of the first page if the uploaded doc is a pdf.

Does it make sense ?

X+

http://www.sydesy.com

Paul Borgermans

Friday 20 January 2006 2:43:35 pm

Hi Xavier

Nice work from Felix :-)

You could by creating a new datatype and re-use some of the coding from him. The trick is to use the post publish action of your new datatype to look up the file (which is another attribute of the object your new datatype belongs to) and create the snapshot. Also implement the has_content property.

In the view template of such a class, use the has_content property to display the snapshot if its available.

Feasible, but requires some coding I'm sure you will be able to do :-)

Regards

--paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Xavier Dutoit

Saturday 21 January 2006 12:46:48 pm

Hi Paul,

didn't realise you have a blog. Is that new ?

X+

http://www.sydesy.com

Paul Borgermans

Sunday 22 January 2006 4:29:23 am

Hi Xavier,

Yes the blog is rather new ...

Cheers

--paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Petter Arneson

Thursday 26 January 2006 7:52:18 am

Hi!

Nice extension!

I'm trying to make a thumbnail of pdf's using this extension.
Using css to set image size seems like a bad solution, so I had a look at Ghostscript commands to be able to utilize width, height and resolution parameter.

http://www.cs.wisc.edu/~ghost/doc/AFPL/7.04/Use.htm#Parameter_switches

It seems to be parameters like -dDEVICEWIDTHPOINTS=w and -dDEVICEHEIGHTPOINTS=h, but I cant get it to work, the size stays the same.

Template:

<img src="{ezsnapshotpdf($node.object.data_map.file.content.filepath,2,100,150)}" alt=""/>

Extension:

$command = 'gs -dNOPAUSE -dBATCH -dFirstPage=' . $page . ' -dLastPage=' . $page;
$command = $command . ' -dDEVICEWIDTHPOINTS= ' . $width . ' -dDEVICEHEIGHTPOINTS=' . $height;
$command = $command . ' -sDEVICE=jpeg -sOutputFile= ' . $save_file . ' -r72 -c --setpdfwrite ' . $file;

Felix, do you have any tips?

www.vzt.no

Felix Laate

Thursday 26 January 2006 1:01:30 pm

Hi Petter,

I just released a new version (0.2) of the extension that has resizeing abibilties. Hope it is what you needed.

Have a look at: http://ez.no/community/contribs/template_plugins/snapshotpdf

Cheers and beers

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

Petter Arneson

Friday 27 January 2006 2:49:27 am

Excellent!!

Just what I needed, good work.

I want to show the thumbnail in a line view, with a link to full view.
It seems I have to trick it a bit to get the thumbnail filename, and the page has to be refreshed to show the thumbnail picture.

This is what I got in the lineview template:

	{section show=eq($node.object.data_map.file.content.mime_type_part,'pdf')}
		<div class="attribute-short">
			<p><b>Ezsnapshotpdf Thumbnail</b></p>
			{def $fullpath = ezsnapshotpdf($node.object.data_map.file.content.filepath,1,$height,$width)}
			{def $split = $fullpath|explode('.')}
			{def $thumbpath = concat($split.0,'.',$split.1,'-',$height,'x',$width,'.',$split.2)}
			<img src="{$thumbpath}" alt=""/>
		</div>	
		<div class="attribute-short">
			  <a href={ezsnapshotpdf($node.object.data_map.file.content.filepath,1)}>See PDF full view</a>
		</div>
	{/section}

www.vzt.no

Felix Laate

Saturday 28 January 2006 4:49:09 am

Hi Petter,

if it's ok with you, I'll add your code snippet as an example of usage to the readme-file.

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com