[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Clash of RubyZip and PDF::Writer

Duane Morin

9/14/2006 4:08:00 PM

I'm using PDF::Writer to generate files by the hundreds. My spec
requires that I batch them up into zip files. I thought this would be a
piece of cake, but I appear to have run into a clash. From what I can
read in the documentation, PDF::Writer only has the "save_as" option
available to me, which takes a file name and writes a file out to disk.
However, ZipFile expects me to open up a new file inside it and then
write contents to it. I think that means I have to write out the pdf,
then open it back up and stream its contents into the zipfile object?
That seems like it will be pretty inefficient. Am I missing something -
is there a better way to tie these two libs together?

--
Posted via http://www.ruby-....

3 Answers

Ara.T.Howard

9/14/2006 4:14:00 PM

0

Austin Ziegler

9/14/2006 4:18:00 PM

0

On 9/14/06, Duane Morin <dmorin@gmail.com> wrote:
> I'm using PDF::Writer to generate files by the hundreds. My spec
> requires that I batch them up into zip files. I thought this would be a
> piece of cake, but I appear to have run into a clash. From what I can
> read in the documentation, PDF::Writer only has the "save_as" option
> available to me, which takes a file name and writes a file out to disk.
> However, ZipFile expects me to open up a new file inside it and then
> write contents to it. I think that means I have to write out the pdf,
> then open it back up and stream its contents into the zipfile object?
> That seems like it will be pretty inefficient. Am I missing something -
> is there a better way to tie these two libs together?

You're missing something. The implementation of #save_as is:

def save_as(name)
File.open(name, "wb") { |f| f.write self.render }
end

Render is a public method. It isn't documented (surprisingly) on
PDF::Writer, but it does exist.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

Duane Morin

9/14/2006 4:28:00 PM

0

Austin Ziegler wrote:
> You're missing something. The implementation of #save_as is:
>
> def save_as(name)
> File.open(name, "wb") { |f| f.write self.render }
> end

Perfect!

> Render is a public method. It isn't documented (surprisingly) on
> PDF::Writer, but it does exist.

Thanks for throwing that in, now I don't feel so n00b :)

D

>
> -austin


--
Posted via http://www.ruby-....