app/models/report_pdf.rb
def build_report
    set_default_font

    if watermark
      create_stamp("stamp") do
        fill_color "cc0000"
        text_box watermark,
          :size   => 2.cm,
          :width  => bounds.width,
          :height => bounds.height,
          :align  => :center,
          :valign => :center,
          :at     => [0, bounds.height],
          :rotate => -45,
          :rotate_around => :center
      end

      repeat(:all) do
        stamp("stamp")
      end
    end

    #bounding_box [80.mm, bounds.absolute_top - 10.mm], width: 100.mm, height: 35.mm do
    bounding_box [0, bounds.absolute_top - 10.mm], width: 80.mm, height: 35.mm do
      #stroke_bounds
      text template.title, size: 10, style: :bold
      text template.subtitle, align: :left, size: 10
      text template.short_title, align: :left, size: 8.pt, style: :italic

      move_down font.height * 0.5

      text template.slogan, size: 8.pt, aligh: :left
    end


    text_box template.owners, at: [80.mm, bounds.absolute_top - 10.mm],
      width: 65.mm, height: 35.mm, align: :right, size: 12

    # Logo
    bounding_box [145.mm, bounds.absolute_top - 10.mm], width: 25.mm, height: 25.mm do
      if template.logo.present?
        #image Rails.root.join('app', 'assets', 'images', 'logo.png'),
        image template.logo.path, width: 25.mm, align: :center, valign: :top
      end
    end

    move_down font.height * 0.5

    text template.contact_infos, align: :center, size: 9.pt

    stroke_horizontal_rule

    # Return address
    bounding_box [0, bounds.absolute_top - 45.mm], width: 80.mm do
      text template.return_address, align: :center, size: 8.pt
      line_width 0.5.pt
      stroke_horizontal_rule
    end

    bounding_box [0, bounds.absolute_top - (45.mm + 18.mm)], width: 80.mm, height: 27.mm do
      text recipient.full_address.join("\n"),
        align: :left,
        size: 10.pt
    end

    bounding_box [100.mm, bounds.absolute_top - 50.mm], width: 75.mm, height: 40.mm do
      text %{Befundender Arzt:}, style: :bold, size: 10.pt
      text report.physician_name, size: 10.pt

      move_down font.height

      text %{Patient:}, style: :bold, size: 10.pt
      text report.patient_name, size: 10.pt

      move_down font.height

      text %{Datum:}, style: :bold, size: 10.pt
      #text %{12. Mai 2015}, size: 10.pt
      text report.report_date, size: 10.pt
    end

    move_down 8.5.mm

    # TODO: Der restliche text sollte auch in eine Bounding box, oder?

    text report.subject, style: :bold, size: 11.pt

    move_down font.height * 2

    text recipient.salutation, size: 11.pt

    move_down font.height

    text "vielen Dank für die Überweisung Ihres Patienten #{report.patient_name}.", size: 11.pt

    move_down font.height

    %i(anamnesis procedure clinic findings evaluation).each do |method|
      if @report.send(method).present?
        text Report.human_attribute_name(method) + ':', style: :bold, size: 11.pt
        text @report.send(method), size: 11.pt
        move_down font.height
      end
    end

    move_down font.height

    text %{Mit freundlichen Grüßen}, size: 11.pt

    if report.include_signature?
      report.signings.each_with_index do |signing,index|
        move_down font.height
        if signing.signature_path.present?
          image signing.signature_path, height: 2*font.height
        end
        text signing.full_name, size: 11.pt
        text signing.suffix, size: 11.pt
      end
    end

    number_pages "Seite <page> von <total> - #{report.patient_name}",
      {
        start_count_at: 2,
        page_filter: lambda{ |pg| pg != 1 },
        at: [0, 0],
        align: :center,
        size: 10,
      }
  end
# TODO: Split report generation into smaller pieces!
Split report generation into smaller pieces!
Split report generation into smaller pieces!
def build_report
    set_default_font
    if watermark
      create_stamp("stamp") do
        fill_color "cc0000"
        text_box watermark,
          :size   => 2.cm,
          :width  => bounds.width,
          :height => bounds.height,
          :align  => :center,
          :valign => :center,
          :at     => [0, bounds.height],
          :rotate => -45,
          :rotate_around => :center
      end
      repeat(:all) do
        stamp("stamp")
      end
    end
    bounding_box [0, bounds.absolute_top - 10.mm], width: 80.mm, height: 35.mm do
      text template.title, size: 10, style: :bold
      text template.subtitle, align: :left, size: 10
      text template.short_title, align: :left, size: 8.pt, style: :italic
      move_down font.height * 0.5
      text template.slogan, size: 8.pt, aligh: :left
    end
    text_box template.owners, at: [80.mm, bounds.absolute_top - 10.mm],
      width: 65.mm, height: 35.mm, align: :right, size: 12
    bounding_box [145.mm, bounds.absolute_top - 10.mm], width: 25.mm, height: 25.mm do
      if template.logo.present?
        image template.logo.path, width: 25.mm, align: :center, valign: :top
      end
    end
    move_down font.height * 0.5
    text template.contact_infos, align: :center, size: 9.pt
    stroke_horizontal_rule
    bounding_box [0, bounds.absolute_top - 45.mm], width: 80.mm do
      text template.return_address, align: :center, size: 8.pt
      line_width 0.5.pt
      stroke_horizontal_rule
    end
    bounding_box [0, bounds.absolute_top - (45.mm + 18.mm)], width: 80.mm, height: 27.mm do
      text recipient.full_address.join("\n"),
        align: :left,
        size: 10.pt
    end
    bounding_box [100.mm, bounds.absolute_top - 50.mm], width: 75.mm, height: 40.mm do
      text %{Befundender Arzt:}, style: :bold, size: 10.pt
      text report.physician_name, size: 10.pt
      move_down font.height
      text %{Patient:}, style: :bold, size: 10.pt
      text report.patient_name, size: 10.pt
      move_down font.height
      text %{Datum:}, style: :bold, size: 10.pt
      text report.report_date, size: 10.pt
    end
    move_down 8.5.mm
    text report.subject, style: :bold, size: 11.pt
    move_down font.height * 2
    text recipient.salutation, size: 11.pt
    move_down font.height
    text "vielen Dank für die Überweisung Ihres Patienten #{report.patient_name}.", size: 11.pt
    move_down font.height
    %i(anamnesis procedure clinic findings evaluation).each do |method|
      if @report.send(method).present?
        text Report.human_attribute_name(method) + ':', style: :bold, size: 11.pt
        text @report.send(method), size: 11.pt
        move_down font.height
      end
    end
    move_down font.height
    text %{Mit freundlichen Grüßen}, size: 11.pt
    if report.include_signature?
      report.signings.each_with_index do |signing,index|
        move_down font.height
        if signing.signature_path.present?
          image signing.signature_path, height: 2*font.height
        end
        text signing.full_name, size: 11.pt
        text signing.suffix, size: 11.pt
      end
    end
    number_pages "Seite <page> von <total> - #{report.patient_name}",
      {
        start_count_at: 2,
        page_filter: lambda{ |pg| pg != 1 },
        at: [0, 0],
        align: :center,
        size: 10,
      }
  end
def build_report set_default_font if watermark create_stamp ( "stamp" ) do fill_color "cc0000" text_box watermark , :size => 2 . cm , :width => bounds . width , :height => bounds . height , :align => :center , :valign => :center , :at => [ 0 , bounds . height ] , :rotate => - 45 , :rotate_around => :center end repeat ( :all ) do stamp ( "stamp" ) end end bounding_box [ 0 , bounds . absolute_top - 10 . mm ] , width : 80 . mm , height : 35 . mm do text template . title , size : 10 , style : :bold text template . subtitle , align : :left , size : 10 text template . short_title , align : :left , size : 8 . pt , style : :italic move_down font . height * 0.5 text template . slogan , size : 8 . pt , aligh : :left end text_box template . owners , at : [ 80 . mm , bounds . absolute_top - 10 . mm ] , width : 65 . mm , height : 35 . mm , align : :right , size : 12 bounding_box [ 145 . mm , bounds . absolute_top - 10 . mm ] , width : 25 . mm , height : 25 . mm do if template . logo . present? image template . logo . path , width : 25 . mm , align : :center , valign : :top end end move_down font . height * 0.5 text template . contact_infos , align : :center , size : 9 . pt stroke_horizontal_rule bounding_box [ 0 , bounds . absolute_top - 45 . mm ] , width : 80 . mm do text template . return_address , align : :center , size : 8 . pt line_width 0.5 . pt stroke_horizontal_rule end bounding_box [ 0 , bounds . absolute_top - ( 45 . mm + 18 . mm ) ] , width : 80 . mm , height : 27 . mm do text recipient . full_address . join ( "\n" ) , align : :left , size : 10 . pt end bounding_box [ 100 . mm , bounds . absolute_top - 50 . mm ] , width : 75 . mm , height : 40 . mm do text %{Befundender Arzt:} , style : :bold , size : 10 . pt text report . physician_name , size : 10 . pt move_down font . height text %{Patient:} , style : :bold , size : 10 . pt text report . patient_name , size : 10 . pt move_down font . height text %{Datum:} , style : :bold , size : 10 . pt text report . report_date , size : 10 . pt end move_down 8.5 . mm text report . subject , style : :bold , size : 11 . pt move_down font . height * 2 text recipient . salutation , size : 11 . pt move_down font . height text "vielen Dank für die Überweisung Ihres Patienten #{report.patient_name}.",  s ze:  1 .p t move_down font . height %i( anamnesis procedure clinic findings evaluation ) . each do | method | if @report . send ( method ) . present? text Report . human_attribute_name ( method ) + ':' , style : :bold , size : 11 . pt text @report . send ( method ) , size : 11 . pt move_down font . height end end move_down font . height text %{Mit freundlichen Grüßen},  s ze:  1 .p t if report . include_signature? report . signings . each_with_index do | signing , index | move_down font . height if signing . signature_path . present? image signing . signature_path , height : 2 * font . height end text signing . full_name , size : 11 . pt text signing . suffix , size : 11 . pt end end number_pages "Seite <page> von <total> - #{report.patient_name}" , { start_count_at : 2 , page_filter : lambda { | pg | pg != 1 } , at : [ 0 , 0 ] , align : :center , size : 10 , } end
TODO: Split report generation into smaller pieces!
TODO : Split report generation into smaller pieces!
#bounding_box [80.mm, bounds.absolute_top - 10.mm], width: 100.mm, height: 35.mm do #stroke_bounds # Logo #image Rails.root.join('app', 'assets', 'images', 'logo.png'), # Return address #text %{12. Mai 2015}, size: 10.pt # TODO: Der restliche text sollte auch in eine Bounding box, oder?