shairontoledo / rghost

RGhost is a document creation and conversion API. It uses the Ghostscript framework for the format conversion, utilizes EPS templates and is optimized to work with larger documents. Support(PDF,PS,GIF,TIF,PNG,JPG,etc)
http://rghost.rubyforge.org
MIT License
187 stars 46 forks source link

Ensamble PDF from an image list #42

Closed josal closed 11 years ago

josal commented 11 years ago

Hi,

I've been using rghost for some weeks and it works great, thanks for the gem.

I need to create a PDF file from some images. Could I call a method to do it in batch or I have to create every page programatically including the proper image where it corresponds (at the beginning of the page)?

Thanks in advance for your help.

shairontoledo commented 11 years ago

Hi,

You could use rghost calling each image in the beginning of the page. But, for such behaviour I'd suggest to use convert command from imagemagick toolkit, it will be easy and faster, for instance:

 convert image1.jpeg image2.jpeg  imageN.jpeg output.pdf
josal commented 11 years ago

Thanks for the answer,

I'll try the convert command, however, I've been using rmagick from ruby and it consumes a huge amount of memory (in heroku it throws R14 errors for medium-size files!).

I'll come back to you with the results. Thanks again

josal commented 11 years ago

I've just done the test, and R14 errors are still there. It seems the process is greater than 512MB in memory.

Maybe could I do it progresivelly, not once in a time?

Thanks again for your comments

shairontoledo commented 11 years ago

Are you using command line or rmagick to get it done? By command line, it's the best way, you could use it by syste() or surround the command by pop3.

josal commented 11 years ago

I've used the system() method with your convert command. With rmagic it gave me the errors I told you.

What is this pop3?

shairontoledo commented 11 years ago

I meant popen3.

josal commented 11 years ago

Ok, I will try to wrap the call with popen3. However, it seems the process gets until 1,5GB in memory (it's what heroku says), so the problem is not related to rmagick (I thought), because with the convert command line ghostscript system call it gets a similar amount of memory for a not very big 14-images pdf file (really!!!, R14 errors gives me this information).

I have to try rghost, pdf::writer or prawn in order to open each page and insert there each image...

Do I have other options?

shairontoledo commented 11 years ago

Have you ever tried -limit (aka '-cache') to set the max of memory?

http://www.imagemagick.org/script/command-line-options.php#limit

josal commented 11 years ago

I thought yesterday you had given to me the final solution. Many thanks man.

This is the command I'm using in ruby:

system("convert -limit memory 32MiB -limit map 64MiB #{jpg_list.join(" ")} #{final_file.pdf}")

It gives only R14 errors with certain big jpg_lists (40, 100 images), but for others thay have dissappeared.

I these cases, it gets all the available memory (if I hire a 512 MB worker, it gets the whole space, if I hire a 1024 MB worker, tha same thing) - so, it seems like the limit is not been considered.

How can I know the memory limits which have been set in the process?

josal commented 11 years ago

If I specify -limit memory 0 -limit area 0, no R14 error appears. So, I think I found the solution at last.

Thanks for your answers and suggestions.

Kind regards.