# Clash of RubyZip and PDF::Writer

**URL:** <https://www.ruby-forum.com/t/clash-of-rubyzip-and-pdf-writer/68692>\
**Category:** Ruby\
**Created:** [September 14, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/clash-of-rubyzip-and-pdf-writer/68692 "2006-09-14T18:06:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [September 14, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/clash-of-rubyzip-and-pdf-writer/68692/1 "2006-09-14T18:06:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [September 14, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/clash-of-rubyzip-and-pdf-writer/68692/2 "2006-09-14T18:13:03Z")

</div>

On Fri, 15 Sep 2006, Duane M. wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

linux or windows?

-a

---

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [September 14, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/clash-of-rubyzip-and-pdf-writer/68692/3 "2006-09-14T18:18:55Z")

</div>

On 9/14/06, Duane M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [September 14, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/clash-of-rubyzip-and-pdf-writer/68692/4 "2006-09-14T18:27:12Z")

</div>

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
