# Creating a PDF on the fly

**URL:** <https://www.ruby-forum.com/t/creating-a-pdf-on-the-fly/86988>\
**Category:** Rails\
**Created:** [February 27, 2007, 12:04pm UTC](https://www.ruby-forum.com/t/creating-a-pdf-on-the-fly/86988 "2007-02-27T12:04:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dohmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/439d5e/32.png) [@dohmer](https://www.ruby-forum.com/u/dohmer)\
**Post date:** [February 27, 2007, 12:04pm UTC](https://www.ruby-forum.com/t/creating-a-pdf-on-the-fly/86988/1 "2007-02-27T12:04:31Z")

</div>

A friend and I are just in the process of trying to create PDFs on the  
fly. This isn’t in itself too hard, but we have some repeating images  
that are being put in over and over again. It’s increasing file size  
too much unfortunately.

Does anyone know the best way to ensure file size is kept to a minimum  
for this scenario? We know about linking to a URI, but the problem with  
that is that if the PDF gets sent elsewhere, we have to send the linked  
images with it.

Any help would be appreciated.

Thanks

## Paul

PJ Net Solutions Ltd  
0871 223 5370  
[http://www.pjnetsolutions.com](http://www.pjnetsolutions.com)  
Registered Number : 4131671 - Registered in England and Wales  
Registered address : 35 Ballards Lane, London, N3 1XW  
Office address : 17 Mortain Drive, Berkhamsted, HP4 1JZ

---

<div class="post-metadata">

**Author:** ![dohmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/439d5e/32.png) [@dohmer](https://www.ruby-forum.com/u/dohmer)\
**Post date:** [February 27, 2007, 3:01pm UTC](https://www.ruby-forum.com/t/creating-a-pdf-on-the-fly/86988/2 "2007-02-27T15:01:54Z")

</div>

On 2/27/07, Paul J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> A friend and I are just in the process of trying to create PDFs on the  
> fly. This isn’t in itself too hard, but we have some repeating images  
> that are being put in over and over again. It’s increasing file size  
> too much unfortunately.

If you’re using PDF::Writer, then it’s trivial to reuse images that  
are repeating. You just have to do it right (and the demo  
chunkbacon.rb shows how).

If you’re not using PDF::Writer, then you need to be more specific  
about your problem.

## -austin

Austin Z. \* removed\_email\_address@domain.invalid \* [http://www.halostatue.ca/](http://www.halostatue.ca/)  
\* removed\_email\_address@domain.invalid \* [You are in a maze of twisty little passages, all alike. // halo • statue](http://www.halostatue.ca/feed/)  
\* removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dohmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/439d5e/32.png) [@dohmer](https://www.ruby-forum.com/u/dohmer)\
**Post date:** [February 27, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/creating-a-pdf-on-the-fly/86988/3 "2007-02-27T16:57:17Z")

</div>

On Tue, 2007-02-27 at 09:00 -0500, Austin Z. wrote:

> On 2/27/07, Paul J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > A friend and I are just in the process of trying to create PDFs on the  
> > fly. This isn’t in itself too hard, but we have some repeating images  
> > that are being put in over and over again. It’s increasing file size  
> > too much unfortunately.
> 
> If you’re using PDF::Writer, then it’s trivial to reuse images that  
> are repeating. You just have to do it right (and the demo  
> chunkbacon.rb shows how).

That’s helpful thanks. I hadn’t found the “demo” section because I was  
looking for “examples” 🙂 I have actually looked at the gem code to  
figure out how to load the image only once. Figured it out now, so  
thanks. Really helpful.

## Paul

PJ Net Solutions Ltd  
0871 223 5370  
[http://www.pjnetsolutions.com](http://www.pjnetsolutions.com)  
Registered Number : 4131671 - Registered in England and Wales  
Registered address : 35 Ballards Lane, London, N3 1XW  
Office address : 17 Mortain Drive, Berkhamsted, HP4 1JZ
