# PDF Appender?

**URL:** <https://www.ruby-forum.com/t/pdf-appender/87241>\
**Category:** Ruby\
**Created:** [March 1, 2007, 3:05am UTC](https://www.ruby-forum.com/t/pdf-appender/87241 "2007-03-01T03:05:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 1, 2007, 3:05am UTC](https://www.ruby-forum.com/t/pdf-appender/87241/1 "2007-03-01T03:05:58Z")

</div>

Hey All,

Let’s say I had a .pdf file and a .txt file, and I wanted to append  
the contents of the text to the .pdf. The text doesn’t have to look  
pretty, it just has to be searchable (the pdf has an image of the text  
in the text file).

I looked at PDF::Writer, but I’m not seeing a way to open an  
existing .pdf. Have I missed it, or do I need to use some other  
library or…?

Thanks!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 1, 2007, 3:39am UTC](https://www.ruby-forum.com/t/pdf-appender/87241/2 "2007-03-01T03:39:01Z")

</div>

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

> Let’s say I had a .pdf file and a .txt file, and I wanted to append  
> the contents of the text to the .pdf. The text doesn’t have to look  
> pretty, it just has to be searchable (the pdf has an image of the text  
> in the text file).
> 
> I looked at PDF::Writer, but I’m not seeing a way to open an  
> existing .pdf. Have I missed it, or do I need to use some other  
> library or…?

PDF::Writer cannot do this. There are non-Ruby solutions to do this  
that you’ll have to use.

-austin

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 1, 2007, 4:57am UTC](https://www.ruby-forum.com/t/pdf-appender/87241/3 "2007-03-01T04:57:11Z")

</div>

Hi,

2007/3/1, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Let’s say I had a .pdf file and a .txt file, and I wanted to append  
> the contents of the text to the .pdf. The text doesn’t have to look  
> pretty, it just has to be searchable (the pdf has an image of the text  
> in the text file).
> 
> I looked at PDF::Writer, but I’m not seeing a way to open an  
> existing .pdf. Have I missed it, or do I need to use some other  
> library or…?

You can do the task with Ruby/Poppler, Ruby/Pango and rcairo:

* * *

surface = Cairo::PDFSurface.new(…)  
context = Cairo::Context.new(surface)

document = Poppler::Document.new(…)  
document.each do |page|  
context.render\_poppler\_page(page)  
context.show\_page  
end

text = File.read(…)  
layout = context.create\_pango\_layout  
layout.text = text  
layout.width = … \* Pango::SCALE  
context.show\_pango\_layout(layout)

context.show\_page

## surface.finish

Some sample scripts may help you:  
[CVS Info for project ruby-gnome2](http://ruby-gnome2.cvs.sourceforge.net/ruby-gnome2/ruby-gnome2/poppler/sample/)  
[http://webcvs.cairographics.org/rcairo/samples/](http://webcvs.cairographics.org/rcairo/samples/)

Thanks,

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 1, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/pdf-appender/87241/4 "2007-03-01T15:00:34Z")

</div>

On Feb 28, 7:56 pm, “Kouhei S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > existing .pdf. Have I missed it, or do I need to use some other  
> > context.render\_poppler\_page(page)
> 
> ## surface.finish
> 
> Some sample scripts may help you:  
> [CVS Info for project ruby-gnome2](http://ruby-gnome2.cvs.sourceforge.net/ruby-gnome2/ruby-gnome2/popple)…  
> [http://webcvs.cairographics.org/rcairo/samples/](http://webcvs.cairographics.org/rcairo/samples/)
> 
> ## Thanks,
> 
> kou

Ah, that looks very promising! I shall pursue those. Many thanks!
