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

eZ debug

Timing: Jan 31 2025 03:30:54
Script start
Timing: Jan 31 2025 03:30:54
Module start 'content'
Timing: Jan 31 2025 03:30:54
Module end 'content'
Timing: Jan 31 2025 03:30:54
Script end

Main resources:

Total runtime0.1958 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0073 587.9297370.2969
Module start 'content' 0.00730.0149 958.22661,013.6406
Module end 'content' 0.02220.1736 1,971.86723,901.5625
Script end 0.1958  5,873.4297 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00462.3675200.0002
Check MTime0.00140.6917200.0001
Mysql Total
Database connection0.00080.398310.0008
Mysqli_queries0.097349.67561410.0007
Looping result0.00130.64001390.0000
Template Total0.173288.410.1732
Template load0.00070.374210.0007
Template processing0.172588.067410.1725
Override
Cache load0.00050.249710.0005
Sytem overhead
Fetch class attribute can translate value0.00201.034410.0020
XML
Image XML parsing0.00030.143010.0003
General
dbfile0.00884.5176200.0004
String conversion0.00000.003030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs