Ruby FPDF on Ruby on Rails
3 comments Latest by sg Mon, 21 Aug 2006 08:57:06 GMT
I have been tinkering with Ruby FPDF for a client all night. I found the examples for it to lack in some real-world examples, so I have taken the example from the RubyOnRails wiki and added a bit more to it. I have added things like an image, links and made a generic letter template. (just an example). I didn’t get into the header/footer functions yet, may do that later.
If you are not sure how to use Ruby FPDF, check out the FPDF documentation.
Just download Ruby FPDF and unpack the archive in your libs directory.
To get Railst to load fpdf, I added this to environment.rb:
ADDITIONAL_LOAD_PATHS.concat %w(
app
app/models
[..snip...]
lib/fpdf
).map { |dir| "#{RAILS_ROOT}/#{dir}" }.select { |dir| File.directory?(dir) }
require 'fpdf'
When I browse to this controller/method, I got this PDF to generate with this code.
def pdf
send_data gen_pdf, :filename => "robbyonrails-fpdf-test.pdf", :type => "application/pdf"
end
private
def gen_pdf
d = Date.today
pdf=FPDF.new
pdf.AddPage
pdf.SetFont('Arial')
pdf.SetFontSize(10)
pdf.Image('/home/matchboy/logo2.jpg',10,8,86,0,'JPG')
pdf.Cell(0,6, "PLANET ARGON", 0,1,'R')
pdf.Cell(0,6, "2802 NE 57th Ave",0,1,'R')
pdf.Cell(0,6, "Portland, OR 97213",0,0,'R')
pdf.Ln
pdf.Ln
pdf.Write(5, "Jane Doe
123 ABC Street
Gilroy, CA 95020
#{d.month}/#{d.mday}/#{d.year}
Dear Jane Doe,
I just wanted to say...
Epsum factorial non deposit quid pro quo hic escorol. Olypian quarrels et gorilla congolium sic ad nauseum. Souvlaki ignitus carborundum e pluribus unum. Defacto lingo est igpay atinlay. Marquee selectus non provisio incongruous feline nolo contendre. Gratuitous octopus niacin, sodium glutimate. Quote meon an estimate et non interruptus stadium. Sic tempus fugit esperanto hiccup estrogen. Glorious
Cheers,
Robby Russell
")
pdf.Ln
pdf.Cell(0,6, "PLANET ARGON", 0,1,'L',0,'http://www.planetargon.com/')
pdf.Output
end
Once again, the output. (click to view PDF)
It’s nothing special, but it’s just an example of how you can add a bit more than ‘Hello World’ to the top of a PDF. I’m still working on figuring out all the x/y stuff. Maybe I will post a better tutorial in the future with headers and footers.
Until then… have fun!
Consolidate Student Loans
Wow, you really have a comment spam problem.
buy propecia
buy cheap levitra
Men’s Health
Propecia
Viagra
Levitra
Cialis
Stimula for Men
Women’s Health
Ortho Tri-Cyclen
Ortho Evra Patch
Nordette 28
Triphasil
Estradiol
Diflucan
Alesse
Vaniqa
Yasmin
Stimula for Women
Sexual Health
Valtrex
Aldara
Condylox
Acyclovir
Famvir
Denavir
Zovirax
Pain Relief
Celebrex
Ultram
Tramadol
Fioricet
Vioxx
Imitrex
Ultracet
Mobic
Bextra
Weight Loss
Phentermine
Ionamin
Meridia
bontril
Didrex
Adipex
Xenical
Phendimetrazine
Tenuate
Dietylproprion
Muscle Relaxants
Cyclobenzaprine
Zanaflex
Carisoprodol
Skelaxin
Flexeril
Soma
Allerge Relief
Allegra
Zyrtec
Flonase
Nasacort
Nasonex
Patanol
Clarinex
Anti-Depressants
Paxil
Zoloft
Wellbutrin
Prozac
Effexor
Celexa
Stop Smoking
Zyban
Anxiety
Buspar
Buspirone
Sleeping Aids
Sonata
Ambien
Stomach
Prilosec
Protonix
Nexium
Aciphex
Antiviral/Herpes
Aldara
Famvir
Acyclovir
Valtrex
Denavir
Skin Care
Benzaclin
Renova
Retin-A
Metrogel
Gastrointestinal
Nexium
Prevacid
Men’s Health
finance and legal advicePropecia
Viagra
Levitra
Cialis
Stimula for Men
Women’s Health
Ortho Tri-Cyclen
Ortho Evra Patch
Nordette 28
Triphasil
Estradiol
Diflucan
Alesse
Vaniqa
Yasmin
Stimula for Women
Sexual Health
Valtrex
Aldara
Condylox
Acyclovir
Famvir
Denavir
Zovirax
Pain Relief
Celebrex
Ultram
Tramadol
Fioricet
Vioxx
Imitrex
Ultracet
Mobic
Bextra
Weight Loss
Phentermine
Ionamin
Meridia
bontril
Didrex
Adipex
Xenical
Phendimetrazine
Tenuate
Dietylproprion
Muscle Relaxants
Cyclobenzaprine
Zanaflex
Carisoprodol
Skelaxin
Flexeril
Soma
Allerge Relief
Allegra
Zyrtec
Flonase
Nasacort
Nasonex
Patanol
Clarinex
Anti-Depressants
Paxil
Zoloft
Wellbutrin
Prozac
Effexor
Celexa
Stop Smoking
Zyban
Anxiety
Buspar
Buspirone
Sleeping Aids
Sonata
Ambien
Stomach
Prilosec
Protonix
Nexium
Aciphex
Antiviral/Herpes
Aldara
Famvir
Acyclovir
Valtrex
Denavir
Skin Care
Benzaclin
Renova
Retin-A
Metrogel
Gastrointestinal
Nexium
Prevacid
Loan
Credit Card
Long Term Mortgage
Lender
Line of Credit
Debt Reduction
Home Equity Loan
Credit Reports
Payday Loans
Poor Credit History
Student Loans
Loan Schedule
Offshore Bank Account
Secured Loans
Consolidate Student Loans
Private Mortgages
Debt Consolidation
Reduce Credit Card Debt
Interest Only Mortgages
Mortgage Buyer
Credit Counseling
Second Mortgages
Credit Card Gateway
Coin Bank
Money Order
Credit Check
Online Banking
Safe Deposit Box
Prepaid Credit Cards
Money Laundering
Credit Card Balance Transfer
Checkbook
Cash Advance
Investment Banking
Piggy Banks
Escrow
Checking Account Group Insurance
Employee Leasing
Hazard Insurance
Income Tax
Insurance Agent
Lease
Insurance Claim
Tax Attorney
Employment Agencies
Term Life Insurance
Liability Insurance
Loyalty Programs
Injury Attorney
Homeowners Insurance
Flat Tax
Insurance Premium
Property Tax
Unemployment Insurance
Social Security
Estate Taxes
Life Insurance
Insurance Broker
Mortgage Insurance
Tax Shelter
Disability Insurance
Tax Loophole
Loyalty Programs
Minimum Wage
Worker’s Compensation
Security Guard
Joint Tax Return
Leaseback
Inheritance Tax
Statute of Limitations
Tax Haven
Tax Liens Work
Currency Trading
Investment Clubs
Like Kind Exchange
Financial Planner
Dollar Cost Averaging
Structured Settlements
Home Refinancing
Dogs of the Dow
Budgeting
Money Market Account
1031 Exchange
Day Trading
Stock Options
Penny Stocks
Viatical Settlements
Down Payment
Balloon Payment
Joint Account
Penny Stock Fraud
Mutual Fund
Investment Property
Estate Planning
Liquidation
Selling Home
Finance Charge
Hedge Fund
Index Fund
ERP, Enterprise Resource Planning
Corporation
Commercial Property
eBusiness
Merchant Account
B2B
Write a Business Plan
Marketing
Human Resources
Butterfly Strategy
Product Placement
Document Management
Answering Services
Home Based Business
Virtual Office
Multi Level Marketing
Neuromarketing
Call Center
Direct Marketing
Covered Calls
Drop Shipping
modern portfolio theory
Focus Groups
Courier Service
Closing Costs
Purchasing Power Parity
Invoice
Mezzanine Financing
Hydrogen Economy
Office Temperature
Career Counseling
January Effect
Temporary Office Space
Effective Resume
Pay As You Go Cell Phone Plan
Letter of Intent
Market Research
Advertising Agencies
Junk Bond
Outdoor Advertising
Labor Relations
Intellectual Property
Municipal Bond
Best Colors for Advertising
Telemarketing
Design Patent Utility Patent
Media Buy
Newspapers Work
Press Releases
Horticulture Jobs
Trademark
Bill Organizers
Gold Standard
Mass Production
Amortization
Liability
White Papers
Copyright Trademark Patent
Direct Mail
Scuba Diving Jobs
Historical Price of Gold
Media Kit
Land Contract
Bail Bonds
Patent Pending
Factoring
Telecommuting
Fraud
Escrow
IRA
LEAPs
ATM
REIT
Bullion
Futures
FDIC
Arbitrage
Insolvency
MACD
HIPAA
LLC
Lien
Barter
Probate
Indemnity
Fannie Mae
Lump Sum
1099 Form
FICO Score
Krugerrand
Appraisal
Options Priced
Living Trust
IRA Rollover
Insider Trading
Options Spreads
Interest Rate
Collection Agency
Black-Scholes Model
Straddles Strangles
Deductible
List Price
Finder’s Fee
Notary Public
Pink Sheets
Asset Allocation
Binding Arbitration
Lagging Indicator
VIX
High Net Worth Individual
CPA
LIBOR
SBA
Merger
Sam’s Club
UPC Symbol
Customized Pens
Corporate Housing
Promissory Note
Custom Mouse Pads
Consignment Shops
Race to the Bottom
Defamation of Character
Confidentiality Clause
Covenant not to Compete
Non Disclosure Agreement
Unilateral Economic Sanctions
DJIA
CRM
Slander and Libel
Military Expenditures
KPIs
Kaizen
Payroll
Six Sigma
Inventory
Lead Time
Mediation
Outsourcing
Lemon Law
Good Lawyer
Contractor
LIFO and FIFO
Money Sorter
Entrepreneur
Indemnification
Leveraged Buyout
Auctioneer Schools
Conflict of Interest
Articles of Incorporation
GDP