Miscellaneous ⇒ Server Chat ⇒ Run pdf2swf in shared host evnivronment ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum IndexServer Chat

Run pdf2swf in shared host evnivronment Reply to topic


I've managed to add a Flash "Page Flip" PDF reader to Pro_News, of the visible turning-the-page type. All done in the template without any changes to Pro_News which is pretty cool.

Essentially these work by converting a PDF "book" into a series of Flash .swf files, 1 per page. pdf2swf from SWFtools is basically the only available FOSS app that I can find which will do this. Problem is that pdf2swf is not installed on most shared host services.

Anyone come up against the this type of problem, and have any ideas about how to proceed? Is there a way to install within my account for just my own use? (My host employs Centos-5.5 x86_64.)

I understand that hosts don't want to install apps which could be misused, but find it ironic that one way around the unavailability of pdf2swf is to use Imagick to convert a PDF "book" to .jpg files, and use those in the page flipper. But I am really afraid that that will hog the resources way too much on say a a 200 page "book." OTOH pdf2swf is pretty efficient and quick, plus it has ability to do it piecemeal, and has timeout limiters built in.

All thoughts gratefully received.

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


If compilers are enabled for users you can ./configure and make but you cannot make install. No other way around.

You can simply warn your users about the requirement and setup your module to check if such software is available in the current server.

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.7 / PHP 7.3 / head


Thanks for the response, and info, Nano.

NanoCaiordo wrote
... and setup your module to check if such software is available in the current server.


What do you reckon is the best to do that check, given that exec() may be disallowed too?

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


That could be another requirement, even because if exec is disabled all other similar functions will be disabled as well, but you can simply avoid all this with an admin configuration option, eg: "enable flash pdf page flip [ ]".

Make sure to save fatal errors to a log file or display an error message explaining what did went wrong, admin should also be warned to deselect the configuration option until all requirements are met.

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.7 / PHP 7.3 / head


Point taken.

As mentioned it is all in a template. So I think I'll make 2 versions: Runtime and Complete - with only the latter also having the conversion process in it.

As the conversion process is only 1 time (per PDF) it already logs to screen, and echo's all to log file - as a lot more can go wrong than just not executing pdf2swf.

I remain in awe as to how much power you guys have put into the template system. Even if it is almost unknown and unknowable unless/until you start reading other templates to see what they did and how.

Thanks for the guidance! not worthy

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


layingback wrote
As mentioned it is all in a template. So I think I'll make 2 versions: Runtime and Complete - with only the latter also having the conversion process in it.
Ok so if I understand correctly you were only using something very similar to
<!-- INCLUDE pro_news/pageslip.html -->

If so, it's easy to get php files to communicate with html templates.
<?php /* first of all we set the handle here */ $TPL->set_handle('index'); /* init the variable */ $TPL->assign_var('B_PDF2SWF_SUPPORT', false); /* You need to call the binary anyway, while you are there capture the return of the call. The $ret value will be pdf2swf return value or an error caused by exec() being disabled */ if ($ret = exec('/example/bin/pdf2swf --maxtime 5 --set param=value ... file.pdf -o file.swf')) { $TPL->assign_var('B_PDF2SWF_SUPPORT', true); /* B_ for boolean(s) */ } else { cpg_error(); } /* hey we got down here, we are still alive */ $TPL->assign_var('B_PDF2SWF_SUPPORT', true); /* finalize and display the handle */ $TPL->display('index'); ?>
Your index.html should look like
<!-- IF B_PDF2SWF_SUPPORT --> <!-- INCLUDE pro_news/pageslip.html --> <!-- ENDIF -->

as a lot more can go wrong than just not executing pdf2swf

This is why you should use a php file to do all the checks to ensure a smooth running, don't leave the template doing it all for you, specially if you are running php code inside the html file. I don't know how you implemented so I'm just trying to get things straight here.

Hey I "just" thought about ImageMagick, it converts pdf to jpg and you can feed flash with images, plus you can still cache converted files and reuse them later without doing any more conversions.
Imagegagick is widely available and the binary already exists for Unix, Mac OS X, iPhone and Windows, no need to compile, easier to convince few server's sysadmin where ImageMagick is not yet installed.

Hope it helps!

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.7 / PHP 7.3 / head


I am using the embedded php code that you suggest, or at least something very similar. (I had figured out from reading reDesign code that I could set template variables in embedded php.)

The other things which could go wrong that I was referring to, were related to pdf2swf errors - which is why I already have a log file (of its output).

Is there an issue with using embedded php code? Or calling exec from it, that I should be aware of?

ImageMagick could be an option. I need to test, as the resulting jpg's are reportedly less able to handle the zoom factors involved without displaying the "jaggies". But need to see for myself how bad it is. Maybe fine as a fallback method.

But I'm sure that IM will take more resources than pdf2swf, but hey ...

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


If you are using template tags to run php you are ok, but is always preferred to run such php code into php files.

If you running live php, editing the template class, with <?php ?> then in servers where html files are parsed by the webserver and processed as php files you could simply call the file directly with your browser and execute the php code.
In servers where register globals is enabled you could also pass parameters.

ImageMagick: pdf -> png -> flash?

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.7 / PHP 7.3 / head

Last edited by NanoCaiordo on Tue Mar 01, 2011 10:16 am; edited 1 time in total


Above post edited.

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.7 / PHP 7.3 / head


I have php code in templates, and register_globals off. In all cases besides this pdf2swf case, I'm accessing template variables, storing info in template variables (to trigger conditional HTML display), and doing some math. Basically re-purposing the existing content, eg. Pro_News by default displays a set of images from coppermine within an article as a series of images using HTML only. A php-assisted template can however take that same data and display as a Featured Content Slider or similar special display format without encumbering Pro_News with the extra code.

Am I OK in that case? Even if someone did find a way to execute externally, the only data available is the data already available in an HMTL-only template.

This pdf2swf one is basically the same if run as a user - just a re-purposed pdf which is already available for download in the HTML-only version of the template.

Where it gets 'clever' is building the page-flip swf file structure if it is the first time. But this is only if user is Admin. Can I trust the template variable set in theme.php (reDesign3) that indicates can admin? (If not I guess I would create a separate Admin-only version of the template and modify Pro_News to serve it to logged in Admins.)

[ I have one other very specialised template which uses php quite a bit - I think it's still OK, but I'll need to go away and study it again as it tracks $'s ... ]

On ImageMagick, I coded it up but it was as I suspected, taking tens of seconds vs. fractions of a second using pdf2swf. Converting to raster format was what was taking the time, plus the resulting jaggies when zoomed defeated the whole purpose and intent. I like the way you think, but even if pdf -> png -> flash worked, I still have the slow times, plus ... the only code I can find to efficiently convert png to swf is part of the same swftools set as pdf2swf! Rolling Eyes

Wonder if there is a way to process the pdf on another server with pdf2swf on it ...

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


imagemagick.org/Usage/...postscript
use gs instead of convert?

gs -sDEVICE=jpeg -o output.jpg -dJPEGQ=80 (try 100, no compression, to increase speed and lower resource usage) -r200x200 (default is A4 72dpi, you want to zoom in so triple it) -gWidthxHeight (in px, as above make sure it's big enough) input.pdf

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
none available


Using -dJPEGQ=100 you could remove -r (defaults to A4) but leave -g big enough. It's all about twaeking.

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.7 / PHP 7.3 / head

All times are UTC


Jump to: