Generating Thumbnails from PDF's - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Generating Thumbnails from PDF's (/showthread.php?tid=1941) |
Generating Thumbnails from PDF's - El Forum - 07-06-2007 [eluser]ignite[/eluser] I'm looking to code my first CI app to handle documents that have been published in PDF format. They need to be easily viewable so I'd like to have thumbnails (.jpg files) for easy scanning and selecting the desired PDF. What I'd like to do is upload a directory individual PDF's or one multipage PDF and have it the app process them/it to generate the thumbnails in .jpg format for quick viewing. Does anyone have any thoughts on how to accomplish this within CI? All ideas welcome. Generating Thumbnails from PDF's - El Forum - 07-06-2007 [eluser]sophistry[/eluser] on mac osx i use /usr/bin/sips to convert single page PDFs. imagemagick may be able to do it: http://www.imagemagick.org/Usage/formats/#vector also, FPDI from setasign to split multipage PDFs into single pages. Generating Thumbnails from PDF's - El Forum - 07-06-2007 [eluser]ignite[/eluser] [quote author="sophistry" date="1183767989"]on mac osx i use /usr/bin/sips to convert single page PDFs.[/quote] I'm on a mac but that looks like command line access which I'm not all that familiar with. Could this do batch conversions? [quote author="sophistry" date="1183767989"]imagemagick may be able to do it: http://www.imagemagick.org/Usage/formats/#vector[/quote] Hmmm... i'll have to look at this. [quote author="sophistry" date="1183767989"]also, FPDI from setasign to split multipage PDFs into single pages.[/quote] This looks very interesting since I'd prefer to take a 50-60 page pdf, upload i to the server, parse the pages into their own separate files, with a custom name, then create thumbnails off of those pdf files in .jpg format for displaying as the preview. Does ImageMagick handle quality settings as well? Generating Thumbnails from PDF's - El Forum - 07-06-2007 [eluser]sophistry[/eluser] i haven't actually done PDF conversion with imagemagick so no advice there. as long as you are not in safemode or otherwise constrained, commandline apps can be called using PHP's exec() command (there are others too). e.g., echo exec('ls') // syntax may be slightly wrong :-( try this for sips: Code: $cmd = "/usr/bin/sips -s format png $pdf_file -s formatOptions high -s dpiHeight 72.0 -s dpiWidth 72.0 --out $png_file"; fpdi can extract one page at a time (using template feature) and create a new PDF file. this should get you started. it's not beautiful but it works. if you improve it or expand it post it up here. also, you'll have to modify (or wrap) your FPDF class to accept CI-style array parameter as a constructor argument. with 60 pages, you might start to get memory errors - it may need a buffer flush in the loop where FPDI is instanced over and over. finally, this code fragment was taken out of a controller so it assumes a few class properties that aren't specifically created here... Code: // sorry for the fragment, and the nasty coding style Generating Thumbnails from PDF's - El Forum - 07-06-2007 [eluser]ignite[/eluser] Sophistry, Thanks for pointing me in the right direction, i hope. (given your name) ;-) Sophistry - (def.) "the use of fallacious arguments, esp. with the intention of deceiving." Anyway, do you happen to know anything about Ghostscript and how to use it? I find the docs confusing and am not sure how to get it installed on my host server or whether it requires a server-wide install or if I'm able to install it on just my account. Generating Thumbnails from PDF's - El Forum - 07-06-2007 [eluser]sophistry[/eluser] :cheese: no deception intended. my name's just a friendly warning for the well-read that i may be not as smart as i make myself sound. i know next to nothing about ghostscript. Generating Thumbnails from PDF's - El Forum - 07-07-2007 [eluser]Jim OHalloran[/eluser] Last time I did this I used FPDI to split the PDF into individual pages, then used ImageMagic's convert progrem to convert those to JPEGs. Worked well, but PDF's which use CMYK colours will be converted to JPEGs which most browsers can't render (but Photoshop and most other tools will open the JPEGs fine). The workaround for this was to use the PHP GD functions to resize the JPEG generated by convert, and GD will take care of converting the colours for you. Jim. Generating Thumbnails from PDF's - El Forum - 07-17-2007 [eluser]Lonely Angel[/eluser] I can do a resize to a picture of pdf? Generating Thumbnails from PDF's - El Forum - 07-17-2007 [eluser]esra[/eluser] Many hosts have GhostScript and ImageMagick installed. Ask your host about it. You might find this thread interesting. http://www.webmasterworld.com/forum88/898.htm Generating Thumbnails from PDF's - El Forum - 07-20-2007 [eluser]Lonely Angel[/eluser] thank you esra! |