[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

PDF Appender?

rpardee@gmail.com

3/1/2007 2:03:00 AM

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!

3 Answers

Austin Ziegler

3/1/2007 2:38:00 AM

0

On 2/28/07, rpardee@gmail.com <rpardee@gmail.com> 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
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

Kouhei Sutou

3/1/2007 3:56:00 AM

0

Hi,

2007/3/1, rpardee@gmail.com <rpardee@gmail.com>:

> 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:
http://ruby-gnome2.cvs.sourceforge.net/ruby-gnome2/ruby-gnome2/poppl...
http://webcvs.cairographics.org/rcair...


Thanks,
--
kou

rpardee@gmail.com

3/1/2007 1:59:00 PM

0

On Feb 28, 7:56 pm, "Kouhei Sutou" <k...@cozmixng.org> wrote:
> Hi,
>
> 2007/3/1, rpar...@gmail.com <rpar...@gmail.com>:
>
> > 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:
> http://ruby-gnome2.cvs.sourceforge.net/ruby-gnome2/ruby-gno......
> http://webcvs.cairographics.org/rcair...
>
> Thanks,
> --
> kou

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