Clash of RubyZip and PDF::Writer

D

Duane Morin

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?
 
A

ara.t.howard

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?

linux or windows?

-a
 
A

Austin Ziegler

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
 
D

Duane Morin

Austin said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top