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?
On 9/14/06, Duane M. [email protected] 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 Z. 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