Class: Saucerly::Pdf
- Inherits:
-
Object
- Object
- Saucerly::Pdf
- Defined in:
- lib/saucerly.rb
Instance Method Summary collapse
-
#initialize(str) ⇒ Pdf
constructor
A new instance of Pdf.
- #normalize! ⇒ Object
- #to_pdf ⇒ Object
Constructor Details
#initialize(str) ⇒ Pdf
Returns a new instance of Pdf.
24 25 26 |
# File 'lib/saucerly.rb', line 24 def initialize(str) @contents = str end |
Instance Method Details
#normalize! ⇒ Object
28 29 30 31 32 |
# File 'lib/saucerly.rb', line 28 def normalize! @contents.gsub!(".com:/", ".com/") # strip out bad attachment_fu URLs @contents.gsub!(/src=["']+([^:]+?)["']/i, %{src="#{Rails.root}/public/\\1"}) # reroute absolute paths @contents.gsub!(/(src=["']\S+)(\?\d*)?(["'])/i, '\1\3') # remove asset ids end |
#to_pdf ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/saucerly.rb', line 34 def to_pdf normalize! io = StringIO.new str = @contents ITextRenderer.new.instance_eval do set_document_from_string(str) layout create_pdf(io.to_outputstream) end io.string end |