edit existing pdf

1,152 views
Skip to first unread message

xin

unread,
Mar 9, 2010, 12:56:38 PM3/9/10
to Prawn
Can we use Prawn to edit existing pdf? If so, where can I find an
example?

What I try to do is to get some data from user input and insert these
data into an existing pdf file and send it to browser.

Thanks!

Randy Parker

unread,
Mar 9, 2010, 1:07:51 PM3/9/10
to prawn...@googlegroups.com
On Tue, Mar 9, 2010 at 12:56 PM, xin <zhang...@gmail.com> wrote:
Can we use Prawn to edit existing pdf?
 
Search this forum for "templates"

xin

unread,
Mar 9, 2010, 2:33:24 PM3/9/10
to Prawn
Thanks a lot.

I installed template branch as a plugin to my project. But I got

undefined method `ruby_18' for Prawn::Document::Text::Wrapping:Module

How to fix this?

On Mar 9, 12:07 pm, Randy Parker <randy.j.par...@gmail.com> wrote:

Daniel Nelson

unread,
Mar 9, 2010, 2:37:01 PM3/9/10
to prawn...@googlegroups.com
> Prawn::Document::Text::Wrapping:Module

...is really old. Better update your Prawn.

-Daniel

xin

unread,
Mar 9, 2010, 2:46:14 PM3/9/10
to Prawn
I want to user this branch because I need editing existing pdf feature
it provided. How to make it work?

Daniel Nelson

unread,
Mar 9, 2010, 2:54:56 PM3/9/10
to prawn...@googlegroups.com

The error referring to Prawn::Document::Text::Wrapping is generated by
old code. What version of Prawn are you running? It seems it must be
out of date.

-Daniel

xin

unread,
Mar 9, 2010, 2:58:36 PM3/9/10
to Prawn
The branch name is templates_0_6_3

On Mar 9, 1:54 pm, Daniel Nelson <dnelso...@gmail.com> wrote:

Daniel Nelson

unread,
Mar 9, 2010, 3:03:12 PM3/9/10
to prawn...@googlegroups.com
>> On Tue, Mar 9, 2010 at 1:46 PM, xin <zhangxi...@gmail.com> wrote:
>> > I want to user this branch because I need editing existing pdf feature
>> > it provided. How to make it work?
>>
> The branch name is templates_0_6_3

That's old. Use templates_2010.

-Daniel

xin

unread,
Mar 9, 2010, 3:08:11 PM3/9/10
to Prawn
I tired
script/plugin install git://github.com/sandal/prawn.git -r
templates_2010

but got
fatal: Couldn't find remote ref templates_2010

where is templates_2010?

Daniel Nelson

unread,
Mar 9, 2010, 3:09:07 PM3/9/10
to prawn...@googlegroups.com
> where is templates_2010?

http://github.com/yob/prawn/tree/templates_2010

-Daniel

xin

unread,
Mar 9, 2010, 3:30:10 PM3/9/10
to Prawn
hmm. I still get the error

undefined method `ruby_18' for Prawn::Text:Module

my env:

ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.2.0]
Rails 2.3.5
Mac OS X 10.6.2

Daniel Nelson

unread,
Mar 9, 2010, 3:47:00 PM3/9/10
to prawn...@googlegroups.com
> hmm. I still get the error
>
> undefined method `ruby_18' for Prawn::Text:Module
>
> my env:
>
> ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.2.0]
> Rails 2.3.5
> Mac OS X 10.6.2

What version of Prawn?

-Daniel

xin

unread,
Mar 9, 2010, 3:53:15 PM3/9/10
to Prawn
$prawn -v
-bash: prawn: command not found

It doesn't matter if I add the following line to environment.rb or
not.

config.load_paths << "#{RAILS_ROOT}/vendor/plugins/prawn/lib"

Gregory Brown

unread,
Mar 9, 2010, 3:58:08 PM3/9/10
to prawn...@googlegroups.com
On 3/9/10 3:53 PM, xin wrote:
> $prawn -v
> -bash: prawn: command not found

Alright, here's where I have to jump in and be the bad guy. Daniel,
you've been remarkably patient here, but this user is wasting your time.

Xin, you have no idea what you're doing, and you're using a library that
you really need to have some fundamental understanding of things like
git, ruby source, and general open source projects unless you want to
stick to the documented and supported released gems.

Either read up on the necessary stack of things you need to know before
running experimental versions of our code, or wait until Prawn 1.0 which
will have template support. That will be some time in the next 6 months.

-greg

xin

unread,
Mar 9, 2010, 4:04:58 PM3/9/10
to Prawn
Sorry I wast your time. But I am new to rails and can you point me a
good doc to explain things?

On Mar 9, 2:58 pm, Gregory Brown <gregory_br...@letterboxes.org>
wrote:

Gregory Brown

unread,
Mar 9, 2010, 4:13:20 PM3/9/10
to prawn...@googlegroups.com
On 3/9/10 4:04 PM, xin wrote:
> Sorry I wast your time. But I am new to rails and can you point me a
> good doc to explain things?

This has nothing to do with Rails, at all. But welcome to Ruby, the
language that Rails is built in.

I'm actually not sure where to point you for specific instructions, but
you might want to start with the basics and go from there.

You'll basically want to learn git through and through, and then, be
able to read Ruby source code.

There are some good git tutorials at:

http://learn.github.com/

To be able to read Ruby source, you pretty much need to learn the
language basics and then practice a lot. Pull open Prawn's source in
your editor and try to track down the problems yourself. Figure out how
it works.

Rubylearning.com might be a good resource for beginners:
http://rubylearning.com/

Maybe my book will also help you, most of it is free now:
http://blog.rubybestpractices.com/posts/gregory/021-rbp-ch7.html

But the thing that we are really ill-fitted to do here on this list is
teach people open source practices, Ruby, and git. When you have a
Prawn question that you feel pretty sure is actually about Prawn and not
configuring your system, let us know.

Until then, good luck with learning. I know it is a big struggle, but
it is important to ask the right people at the right times. Should you
need help learning Ruby, the folks on the RubyTalk mailing list would
likely be happy to help answer beginners questions. Same goes for
RubyOnRails Talk for Rails questions.

-greg

xin

unread,
Mar 9, 2010, 9:25:54 PM3/9/10
to Prawn
ok, i finally get this installed and it works fine with example. But I
want to double check the prawn version. How can I check the version of
prawn installed?


On Mar 9, 3:13 pm, Gregory Brown <gregory_br...@letterboxes.org>
wrote:

Gregory Brown

unread,
Mar 9, 2010, 9:30:31 PM3/9/10
to prawn...@googlegroups.com
On 3/9/10 9:25 PM, xin wrote:
> ok, i finally get this installed and it works fine with example. But I
> want to double check the prawn version. How can I check the version of
> prawn installed?

If you are using yob's templates branch, it has no version, because it
is has not been merged into the official codebase. But templates_2010
is effectively a snapshot of the Prawn 0.7 codebase, so following those
release notes should get you some mileage.

-greg

xin

unread,
Mar 9, 2010, 11:14:30 PM3/9/10
to Prawn
ok, maybe a dumb question.

i tried this example

class HelloController < ApplicationController
def index

filename = "path to existing pdf file"
pdf = Prawn::Document.new(:template => filename, :page_size
=>"A5")
pdf.render_file "template.pdf"
output = pdf.render

respond_to do |format|
format.pdf do
send_data output, :filename => "hello.pdf",
:type => "application/pdf"
end
end
end
end

no matter how many pages of my existing pdf file, i always get one
empty pdf page. it seems not encrypt/decrypt problem. what am i
missing here?

On Mar 9, 8:30 pm, Gregory Brown <gregory_br...@letterboxes.org>
wrote:

Gregory Brown

unread,
Mar 9, 2010, 11:16:38 PM3/9/10
to prawn...@googlegroups.com
On 3/9/10 11:14 PM, xin wrote:

> no matter how many pages of my existing pdf file, i always get one
> empty pdf page. it seems not encrypt/decrypt problem. what am i
> missing here?

You should read our Rails guide:

http://wiki.github.com/sandal/prawn/using-prawn-in-rails

joelkeepup

unread,
Mar 10, 2010, 8:21:35 AM3/10/10
to Prawn
see below for a couple suggestions, I would first start with the
hexagon example that James ships with the template version, use his
pdf and write something over it. If it works then you know your
environment is good, if it doesn't then its an setup problem. If it
works and your example doesn't work then maybe its a problem reading
you pdf, see if the text you write shows up, that will help also
narrow it down.

On Mar 9, 11:14 pm, xin <zhangxi...@gmail.com> wrote:
> ok, maybe a dumb question.
>
> i tried this example
>
> class HelloController < ApplicationController
>      def index
>
>       filename = "path to existing pdf file"
>       pdf = Prawn::Document.new(:template => filename, :page_size
> =>"A5")

I dont think you need this line, not sure if it hurts, but you dont
need:

>       pdf.render_file "template.pdf"

Try adding:

pdf.text_box 'Does this show up in pdf doc', :at => [100,663], :height
=> 12

xin

unread,
Mar 10, 2010, 10:39:03 AM3/10/10
to Prawn
Thank you joelkeepup.

It turns out my pdf file problem.

Another dumb question. How to edit exiting pdf field? If field name is
'deptname' in my pdf, how to edit the value of field 'deptname'?

Gregory Brown

unread,
Mar 10, 2010, 10:48:33 AM3/10/10
to prawn...@googlegroups.com
On 3/10/10 10:39 AM, xin wrote:
> Thank you joelkeepup.
>
> It turns out my pdf file problem.
>
> Another dumb question. How to edit exiting pdf field? If field name is
> 'deptname' in my pdf, how to edit the value of field 'deptname'?

You don't with Prawn, at least not yet. James had started on this at
one point, but never got beyond the early stages.

But you might try pdftk:
http://www.accesspdf.com/pdftk/

joelkeepup

unread,
Mar 10, 2010, 3:15:03 PM3/10/10
to Prawn

On Mar 10, 10:48 am, Gregory Brown <gregory_br...@letterboxes.org>
wrote:


> On 3/10/10 10:39 AM, xin wrote:
>
> > Thank you joelkeepup.
>
> > It turns out my pdf file problem.
>
> > Another dumb question. How to edit exiting pdf field? If field name is
> > 'deptname' in my pdf, how to edit the value of field 'deptname'?
>

As Greg said you cant really yet, but you may be able to use :


pdf.text_box 'Does this show up in pdf doc', :at => [100,663], :height
=> 12

to overlay text on the form, I haven tried it with a real form, just
pdf files with underscores in them. I use skim (open source pdf reader
for osx) to get the coordinates (download skim and click the select
tool and click the spot on the form, this will give you the
coordinates.) of where to place the text_box.

Reply all
Reply to author
Forward
0 new messages