Skip to content

Instantly share code, notes, and snippets.

@mikezter
Created February 22, 2010 17:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikezter/311258 to your computer and use it in GitHub Desktop.
Save mikezter/311258 to your computer and use it in GitHub Desktop.
Briefblatt nach DIN 676 - Formblatt B
require 'prawn/measurement_extensions.rb'
class StandardBriefB < Prawn::Document
def initialize(*args)
super(
:page_size => 'A4',
:page_layout => :portrait,
:margin => [107.4.mm, 8.1.mm, 30.mm, 24.1.mm]
)
options = args.last.is_a?(Hash) ? args.last : {}
font_size(11)
@schriftart = options[:font] || File.join(File.dirname(__FILE__), 'DejaVuSerif.ttf')
@datum = options[:datum] || Date.today
font(@schriftart)
@stroke_bounds = false
end
def briefkopf
canvas do
bounding_box([0,bounds.height], :width => 210.mm, :height => 45.mm) do
yield if block_given?
stroke_bounds if @stroke_bounds
end
end
end
# 20mm vom linken Rand, 45mm vom oberen Rand, 85mm breit, 5mm hoch
def absenderzeile(*absender)
absender = absender.to_a.first.to_s
canvas do
bounding_box([20.mm, bounds.top - 45.5.mm], :width => 85.mm, :height => 5.mm) do
stroke_bounds if @stroke_bounds
font_size(3.mm) do
text absender
end
stroke do
line_width 0.1.mm
horizontal_rule
end
end
end
end
# 20mm vom linken Rand, 50mm vom oberen Rand, 85mm breit, 40mm hoch
def adressfeld
canvas do
bounding_box([20.mm, bounds.top - 50.mm], :width => 85.mm, :height => 40.mm) do
stroke_bounds if @stroke_bounds
yield if block_given?
end
end
end
# wird aufgerufen, nachdem das Dokument fertiggestellt ist und über dem informationsblock eingefügt
# 85mm vom linken Rand, 8.1mm vom rechten Rand, 10mm hoch, 96.9mm breit
def page_info
canvas do
page_count.times do |i|
go_to_page(i+1)
bounding_box([105.mm, bounds.top - 45.mm], :width => (105 - 8.1).mm, :height => 10.mm) do
stroke_bounds if @stroke_bounds
table(
[
['Seite', "#{page_number} / #{page_count}"]
],
:width => 60.mm,
:position => (105 - 8.1 - 60).mm,
:align => {0 => :left, 1 => :right},
:border_width => 0,
:font_size => 2.mm
)
end
end
end
end
# 85mm vom linken Rand, 8.1mm vom rechten Rand, 35mm hoch (10mm für Seitennummerierung freilassen), 96.9mm breit
def informationsblock
canvas do
bounding_box([105.mm, bounds.top - 55.mm], :width => (105 - 8.1).mm, :height => 35.mm) do
stroke_bounds if @stroke_bounds
yield if block_given?
end
end
end
def betreffvermerk(*betreff)
betreff = betreff.to_a.first.to_s
canvas do
bounding_box([24.1.mm, bounds.top - 97.4.mm], :width => (210-8.1-24.1).mm, :height => 10.mm) do
stroke_bounds if @stroke_bounds
font(@schriftart, :style => :bold) do
text(betreff)
end
end
end
end
def brieffuss
canvas do
bounding_box([24.1.mm, bounds.bottom + 25.1.mm], :width => (210 - 24.1 - 8.1).mm, :height => 25.mm) do
stroke do
line_width 0.1.mm
horizontal_rule
end
yield if block_given?
stroke_bounds if @stroke_bounds
end
end
end
def falzmarken
canvas do
stroke do
line_width 0.1.mm
horizontal_line(bounds.left, bounds.left + 5.mm, :at => (bounds.top - 105.mm))
horizontal_line(bounds.left, bounds.left + 5.mm, :at => (bounds.top - 210.mm))
end
end
end
def body
yield if block_given?
end
def render(*args)
repeat(:all) do
stroke_bounds if @stroke_bounds
briefkopf
absenderzeile
adressfeld
informationsblock
falzmarken
brieffuss
betreffvermerk
end
body
page_info
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment