Skip to content

Vertical alignment in PDF tables is broken #127

@rsynnest

Description

@rsynnest

Valign does not work. :top ends up centered, :center ends up at the bottom, and :bottom ends up at the bottom correctly.

The original valign code was added in prawn:5cddc78a

I've written a small script that can be used to quickly test/iterate, for anyone out there who wants to try a fix. I am not a Ruby dev and there are no build instructions for this repo so I just slapped this together:

Build Environment

Project files:

main.rb
./prawn-table/    <----- clone of this repo

To rebuild the Gem with your changes, and rebuild the PDF:

cd ./prawn-table
rm prawn-table-*.gem && gem build prawn-table.gemspec
cd -
ruby main.rb

Contents of main.rb:

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'prawn'
  gem 'prawn-table', :path => './prawn-table'
end


Prawn::Document.generate('result.pdf') do

data = [ ["TOP", "", ""], ]
table data, :cell_style => { :valign => :top}
move_down 20

data = [ ["CENTER", "", ""], ]
table data, :cell_style => { :valign => :center}
move_down 20

data = [ ["BOTTOM", "", ""], ]
table data, :cell_style => { :valign => :bottom}
move_down 20


end

Results

The current codebase results in the following:
image

Simply commenting out prawn/table/cell/text.rb line 69 gives a better result in my opinion:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions