Preview of pdf files

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
User avatar
Posts: 166
Joined: Sun 15. Feb 2004, 13:39
Location: Rutschwil, Switzerland

Preview of pdf files

Post by habi » Fri 19. Feb 2010, 16:31

for my own need I've just a small hack to generate and display a jpg thumbnail of my uploaded pdf-files.

But ImageMagick has to be installed und in config.php the corresponding path has to be set
for saving my own hacks on updating phpwcms, I put the custom files at the moment in "template/config/". Then I have in most cases just an include statement in one of the core files. And the location of this include could be documented in the custom file.
create a new file named "checkthumb.php" and put this in "template/config/"
copy the following code in the new file:

Code: Select all

	edit file: 		include/inc_tmpl/files.private.editfile.tmpl.php
	edit type: 		insert
	edit location:	line 159
	edit code: 		include_once(PHPWCMS_ROOT.'/template/config/checkthumb.php');
	edit comment:	before line containing $ja = 1;

		if ($phpwcms['imagick_path'] != '') {	// check if ImageMagick is set
			$thumbMaxHeight	= 80;				// set the thumb height instead of using the thumb height in config.php
			$currentPath	= PHPWCMS_ROOT.'/filearchive/';
			$currentFile	= $row["f_hash"] . '.' . $row["f_ext"];
			if ($row["f_ext"] == 'pdf') {		// check if current file is of type pdf
				if (!file_exists($currentPath . $row["f_hash"] . '.jpg')) { 		// check if thumb already exists
					// no thumb yet so create one
					$im	= new imagick($currentPath . $currentFile . '[0]');
					$im->writeImage('filearchive/' . $row["f_hash"] . '.jpg');

				$file_thumb_small = '<img src="filearchive/' . $row["f_hash"] . '.jpg"/>';
				$othumb = true;
in "include/inc_tmpl/files.private.editfile.tmpl.php" insert at line 159 (before the line "$ja = 1;") the following code:

Code: Select all

in filecenter when you click the edit button of a uploaded pdf file, the code checks if a thumb exists, if not, it creates one.

later I can now create a custom DOWNLOAD-RT and use this thumb in my pdf downloads.

use it at your own risk. it just fits my own needs.

the result is looking like this (the filename is the same as the pdf - not the real filename - the hash used in phpwcms):

Posts: 34
Joined: Fri 18. Feb 2005, 17:10
Location: Balzers / Liechtenstein

Re: Preview of pdf files

Post by Monz@ » Fri 11. Mar 2011, 11:58

Hello Habi

Your preview functions perfect, but now, me as a non-hardcore-coder is it quite difficult to implement the generated pic in the existing RT, or would it be better to just create a new one? Do you have allready done a solution for that?

Thanks a lot for your inputs!


Post Reply