Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

receipts

> 后端框架
Open source

Easy receipts and invoices for your Ruby on Rails applications

665 stars0 likes3 views
WebsiteGitHub

About

Easy receipts and invoices for your Ruby on Rails applications

Receipts Gem

Receipts, Invoices, and Statements for your Rails application that works with any payment provider. Receipts uses Prawn to generate the PDFs.

Check out the example PDFs.

Installation

Add this line to your application's Gemfile:

ruby
gem 'receipts'

And then execute:

bash
$ bundle

Or install it yourself as:

bash
$ gem install receipts

Usage

To generate a Receipt, Invoice, or Statement, create an instance and provide content to render:

…

Configuration

You can specify the default font for all PDFs by defining the following in an initializer:

ruby
Receipts.default_font = {
  bold: Rails.root.join('app/assets/fonts/tradegothic/TradeGothic-Bold.ttf'),
  normal: Rails.root.join('app/assets/fonts/tradegothic/TradeGothic.ttf'),
}

Options

You can pass the following options to generate a PDF:

  • recipient - Array of customer details to include. Typically, this is name, address, email, VAT ID, etc.

  • company - Hash of your company details

    • name - Company name

    • address - Company address

    • email - Company support email address

    • phone - Company phone number - Optional

    • logo - Logo to be displayed on the receipt - Optional This can be either a Path, File, StringIO, or URL. Here are a few examples:

      ruby
      logo: Rails.root.join("app/assets/images/logo.png")
      logo: File.expand_path("./logo.png")
      logo: File.open("app/assets/images/logo.png", "rb")
      logo: "https://www.ruby-lang.org/images/[email protected]" # Downloaded with OpenURI
    • display: [] - Customize the company details rendered. By default, renders [:address, :phone, :email] under the company name. Items in the array should be Symbols matching keys in the company hash to be displayed.

  • details - Array of details about the Receipt, Invoice, Statement. Typically, this is receipt numbers, issue date, due date, status, etc.

  • line_items - Array of line items to be displayed in table format.

  • footer - String for a message at the bottom of the PDF.

  • font - Hash of paths to font files - Optional

    ruby
    font: {
      bold: Rails.root.join('app/assets/fonts/tradegothic/TradeGothic-Bold.ttf'),
      normal: Rails.root.join('app/assets/fonts/tradegothic/TradeGothic.ttf'),
    }
  • logo_height - An integer value of how tall the logo should be. Defaults to 16

Here's an example of where each option is displayed.

Line Items Table - Column Widths

You may set an option to configure the line items table's columns width in order to accommodate shortcomings of Prawn's width guessing ability to render header and content reasonably sized. The configuration depends on your line item column count and follows the prawn/table configuration as documented here:

This will size the second column to 400 and the fourth column to 50.

ruby
column_widths: {1 => 400,3 => 50 }

This will set all column widths, considering your table has 4 columns.

ruby
column_widths: [100, 200, 240]

If not set, it will fall back to Prawn's default behavior.

Formatting

details and line_items allow inline formatting with Prawn. This allows you to use HTML tags to format text: ``

See the Prawn docs for more information.

Page Size

You can specify a different page size by passing in the page_size keyword argument:

ruby
receipt = Receipts::Receipt.new page_size: "A4"

Internationalization (I18n)

You can use I18n.t when rendering your receipts to internationalize them.

ruby
line_items: [
  [I18n.t("receipts.date"),           created_at.to_s],
  [I18n.t("receipts.product"), "GoRails"],
  [I18n.t("receipts.transaction"), uuid]
]

Custom PDF Content

You can change the entire PDF content by instantiating an Receipts object without any options.

ruby
receipt = Receipts::Receipt.new # creates an empty PDF

Each Receipts object inherits from Prawn::Document. This allows you to choose what is rendered and include any custom Prawn content you like.

ruby
receipt.text("hello world")

You can also use the Receipts helpers in your custom PDFs at the current cursor position.

ruby
receipt.text("Custom header")
receipt.render_line_items(line_items: [
  ["my line items"]
])
receipt.render_footer("This is a custom footer using the Receipts helper")

Rendering PDFs

To render a PDF in memory, use render. This is recommended for serving PDFs in your Rails controllers.

ruby
receipt.render

To render a PDF to disk, use render_file:

ruby
receipt.render_file "receipt.pdf"

Rendering PDFs in Rails controller actions

Here's an example Rails controller action you can use for serving PDFs. We'll first look up the database record for the Charge we want to render a receipt for.

The Charge model has a receipt method that returns a Receipts::Receipt instance with all the receipt data filled out.

Then we can render to generate the PDF in memory. This produces a String with the raw PDF data in it.

Using send_data from Rails, we can send the PDF contents and provide the browser with a recommended filename, content type and disposition.

ruby
class ChargesController 

Invoices

Invoices follow the exact same set of steps as above. You'll simply want to modify the details to include other information for the Invoice such as the Issue Date, Due Date, etc.

…

Statements

Statements follow the exact same set of steps as above. You'll simply want to modify the details to include other information for the Invoice such as the Issue Date, Start and End Dates, etc.

…

Contributing

  1. Fork it https://github.com/excid3/receipts/fork
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubypdfpdf-receiptrails-applicationreceipt

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架