Integrations

# Rails

render pdf:, send_pdf, previews like ActionMailer's, a font generator — and no Rails dependency in the gem.

## Controllers and configuration

From the README.

```ruby

```

## send_pdf

Without the renderer.

`Stationery::Rails#send_pdf(document, filename:, disposition: "inline", type: "application/pdf")` is what `render pdf:` calls. Outside the Railtie (or with `config.stationery.renderer = false`, keeping wicked_pdf's `render pdf:`), include it yourself:

```ruby
class InvoicesController < ApplicationController
  include Stationery::Rails

  def show = send_pdf(InvoicePdf.new(@invoice), filename: "invoice-#{@invoice.number}.pdf")
end
```

## Previews

One public method per sample document.

## Font generator

stationery:fonts.

```shell
bin/rails generate stationery:fonts noto_sans liberation_serif
```

Installs the packs into `vendor/fonts/<pack>/` — the directory the Railtie adds to `Stationery.font_paths` — so `font_family "Noto Sans"` needs no paths. Commit the files; nothing is downloaded at runtime. See [Fonts](https://stationery.zoolutions.llc/docs/fonts#font-packs).

## Mailers, jobs and ActiveStorage

to_pdf returns bytes — use them anywhere.

`to_pdf` returns the PDF as a binary String, so the same document class serves mailers, background jobs and storage:

```ruby
class InvoiceMailer < ApplicationMailer
  def issued(invoice)
    attachments["invoice-#{invoice.number}.pdf"] = InvoicePdf.new(invoice).to_pdf
    mail to: invoice.customer.email, subject: "Invoice #{invoice.number}"
  end
end

class ArchiveInvoiceJob < ApplicationJob
  def perform(invoice)
    invoice.pdf.attach(io: StringIO.new(InvoicePdf.new(invoice).to_pdf),
                       filename: "invoice-#{invoice.number}.pdf", content_type: "application/pdf")
  end
end
```

Pass `strict: true` in jobs that must never store a PDF with layout problems.