# Extending PDF::Writer

**URL:** <https://www.ruby-forum.com/t/extending-pdf-writer/79763>\
**Category:** Ruby\
**Created:** [December 18, 2006, 8:36pm UTC](https://www.ruby-forum.com/t/extending-pdf-writer/79763 "2006-12-18T20:36:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bill\_walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f07891/32.png) [@bill\_walton](https://www.ruby-forum.com/u/bill_walton)\
**Post date:** [December 18, 2006, 8:36pm UTC](https://www.ruby-forum.com/t/extending-pdf-writer/79763/1 "2006-12-18T20:36:16Z")

</div>

I need to extend PDF::Writer to allow it to include an external XML  
file into the PDF file. It looks pretty straight forward from the PDF  
spec in that it will be seperate component of the file, distinct from  
the PDF document itself. I’ve pulled down the PDF::Writer source and  
am looking through it to see what I need to do on that front. I  
thought I’d ask if anybody 1) has any experience with mods to  
PDF::Writer or 2) has experience with extending other GEMS they’d be  
willing to share to help me avoid problems.

TIA,  
Bill

---

<div class="post-metadata">

**Author:** ![bill\_walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f07891/32.png) [@bill\_walton](https://www.ruby-forum.com/u/bill_walton)\
**Post date:** [December 18, 2006, 8:56pm UTC](https://www.ruby-forum.com/t/extending-pdf-writer/79763/2 "2006-12-18T20:56:18Z")

</div>

On 12/18/06, bill walton [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> …  
> thought I’d ask if anybody 1) has any experience with mods to  
> PDF::Writer or 2) has experience with extending other GEMS they’d be  
> willing to share to help me avoid problems.

I haven’t done anything with PDF::Writer, but I have extended several  
gems  
on my own system. Because of Ruby’s open classes, its easy to add or  
override definitions of existing classes. I’ve used this to “patch” bugs  
in  
gems, or to add new features to them, without affecting the original  
source  
files. For example, if you’re code lives in “make\_my\_pdf.rb”, you can do  
somethign like this:

require ‘pdf\_writer’ # original gem

class PDF::Writer  
… add new methods, override existing ones, etc.  
end

PDF::Wrtier.new # do your work

If I find myself needing to fix a bug within a method, I’ve just pasted  
the  
definition in to my “local” copy and modified it there.

I have also found that most gem maintainers are glad to accept patches  
and  
apply them. If you include some unit tests, your patch is even more  
likely  
to get accepted.

HTH.

Justin

---

<div class="post-metadata">

**Author:** ![bill\_walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f07891/32.png) [@bill\_walton](https://www.ruby-forum.com/u/bill_walton)\
**Post date:** [December 20, 2006, 7:18pm UTC](https://www.ruby-forum.com/t/extending-pdf-writer/79763/3 "2006-12-20T19:18:37Z")

</div>

On 12/18/06, bill walton [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I need to extend PDF::Writer to allow it to include an external XML  
> file into the PDF file. It looks pretty straight forward from the PDF  
> spec in that it will be seperate component of the file, distinct from  
> the PDF document itself. I’ve pulled down the PDF::Writer source and  
> am looking through it to see what I need to do on that front. I  
> thought I’d ask if anybody 1) has any experience with mods to  
> PDF::Writer or 2) has experience with extending other GEMS they’d be  
> willing to share to help me avoid problems.

(1) Didn’t you ask me this directly a couple of weeks ago, and I asked  
you what you for clarification? I don’t recall seeing such  
clarification, but I will admit to being many hundreds of messages  
behind (I’m about 800 “conversations” behind on ruby-talk).

(2) I strongly recommend against trying to _extend_ (e.g.,  
monkeypatch) PDF::Writer. The internals are pretty much guaranteed to  
change in 2007. If you need a new PDF “object”, then you will either  
need to (a) work with me or (b) monkeypatch. (b) has already been  
pointed out as a bad idea.

(3) The best way to extend PDF::Writer is to make a “consumer” of  
PDF::Writer.

-austin
