Forum: Ruby PDF Appender?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2007-03-01 04:05
(Received via mailing list)
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!
Austin Z. (Guest)
on 2007-03-01 04:39
(Received via mailing list)
On 2/28/07, removed_email_address@domain.invalid 
<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
Kouhei S. (Guest)
on 2007-03-01 05:57
(Received via mailing list)
Hi,

2007/3/1, removed_email_address@domain.invalid 
<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:
  http://ruby-gnome2.cvs.sourceforge.net/ruby-gnome2...
  http://webcvs.cairographics.org/rcairo/samples/


Thanks,
(Guest)
on 2007-03-01 16:00
(Received via mailing list)
On Feb 28, 7:56 pm, "Kouhei S." <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:
>  http://ruby-gnome2.cvs.sourceforge.net/ruby-gnome2......
>  http://webcvs.cairographics.org/rcairo/samples/
>
> Thanks,
> --
> kou

Ah, that looks very promising!  I shall pursue those.  Many thanks!
This topic is locked and can not be replied to.