开发者

Build a PDF from a template in Ruby on Rails

开发者 https://www.devze.com 2023-03-28 05:45 出处:网络
I would like to create a template in doc, pdf, odt, docx ... document type does not matter. What I want is to get this document, change some values ​​and convert this document to PDF.

I would like to create a template in doc, pdf, odt, docx ... document type does not matter. What I want is to get this document, change some values ​​and convert this document to PDF.

For example:

Take this template:

<Title>
<Date>

Hello <Name>,

<Text>

         <Farewell>

And with this information:

Title: attention
Date: 22/05/2011
Name: NicosKaralis
Text: Lorem ipsum ...
Farewell: See you later

generate this pdf document, using color, background and anything that may have the templat开发者_如何学Goe:

attention
22/05/2011

Hello NicosKaralis,

Lorem ipsum ....

         See you later.

There are any way to do this in Ruby on Rails? preferably using prawn

Thanks in advance

-- EDIT --

1 The owner of the application will create something like this: Original.(odt, doc, pdf)

2 My app database will have a user with this attributes:

title = Welcome to the internet!

name = Jhon Doe

text = Welcome to the internet, i will be your guide

farewell = Hope to see you soon!

3 My app will create a pdf like this: Final.pdf and send it by email

The email part i already have working. I just don`t have the pdf.

P.S.: I now how to create a pdf from scratch, but i dont want that. The point of this application is that you don`t need to be a rails developer to change the pdf that is generated.


I'm not familiar with prawnto, but I'm pretty familiar with prawn. Since version 0.10.1 they've had the ability to import another pdf for use as a "template" per se. If you check the new manual there's a section on templates. If you look at the page titled templates/page_template.rb you'll see some example code. It takes some text and positions it manually, but there may be a way to do some sort of actual substitution.


This may address the first half of the problem. Then use something like wicked_pdf to generate.


There is a really nice screencast from Ryan Bates here explaining the trick with PDF::Writer. I think that's what you want :)

0

精彩评论

暂无评论...
验证码 换一张
取 消