Repository is archived
No commit activity in last 3 years
No release in over 3 years
A Prawn PDF component which adds basic HTML support
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.76

Runtime

~> 2.15
~> 2.2.2
 Project Readme

Prawn Styled Text

gem version gem downloads linters specs

A Prawn PDF component which adds basic HTML support.


Discontinued project

Hey, I started this project some years ago with the goal to create a good HTML to PDF renderer. During this time I tried to refactor it in different ways but in the end I preferred to rewrite it from scratch with a new project: prawn-html. It takes a different approach: no monkey patching, better HTML handling, documents styles, etc. Consider using it in place of prawn-styled-text


Install

  • Add to your Gemfile: gem 'prawn-styled-text' (and execute bundle)
  • Use the method styled_text on a Prawn::Document instance

Examples

require 'prawn-styled-text'
pdf = Prawn::Document.new
pdf.styled_text '<h1 style="text-align: center">Just a test</h1>'
pdf.render_file 'test.pdf'

For more examples see this folder.

Supported tags & attributes

HTML tags:

  • a: link
  • b: bold
  • br: new line
  • del: strike-through
  • div: block element
  • em: italic
  • h1 - h6: headings
  • hr: horizontal line
  • i: italic
  • ins: underline
  • img: image
  • li: list item
  • mark: highlight
  • p: block element
  • s: strike-through
  • small: smaller text
  • span: inline element
  • strong: bold
  • u: underline
  • ul: list

CSS attributes:

  • background: for mark tag, only 6 hex digits format, # is ignored - ex. style="background: #FFCC00"
  • color: only 6 hex digits format, # is ignored - ex. style="color: #FFBB11"
  • font-family: font must be registered, quotes are optional, ex. style="font: Courier"
  • font-size: units are ignored - ex. style="font-size: 20px"
  • font-style: values: :bold, :bold_italic, :italic, :normal; string or comma separated strings - ex. style="font-style: bold, italic"
  • height: for img tag, ex. <img src="test.jpg" style="width: 50%; height: 200"/>
  • href: for a tag, ex. <a href="http://www.google.com/">Google</a>
  • letter-spacing: ex. style="letter-spacing: 1.5"
  • line-height: heading, units are ignored - ex. style="line-height: 10"
  • margin-left: units are ignored - ex. style="margin-left: 15"
  • margin-top: units are ignored - ex. style="margin-top: 20"
  • src: for img tag, ex. <img src="test.jpg"/>
  • text-align: ex. style="text-align: center"
  • width: for img tag, ex. <img src="test.jpg" style="width: 50%; height: 200"/>

Other custom attributes:

  • dash: for hr tag, dash types, integer or comma separated integers, ex. <hr style="dash: 4"/>
  • image-at: for img tag, origin (0, 0) is left bottom, ex. <img src="image.jpg" style="image-at: 100, 600" />
  • image-position: for img tag, ex. <img src="image.jpg" style="image-position: center" />
  • image-scale: for img tag, ex. <img src="image.jpg" style="image-scale: 0.3" />
  • list-symbol: for ul tag, ex. <ul style="list-symbol: -">
  • mode: text mode, values: :clip, :fill, :fill_clip, :fill_stroke, :fill_stroke_clip, :invisible, :stroke, :stroke_clip, ex. <h3 style="mode: stroke">Stroke text</h3>

See Prawn documentation for PDF options details.

Contributors

License

The gem is available as open-source under the terms of the MIT.