Rajeev Kannav Sharma

Posts About

Prawn ruby pdf creation basics introduction

04 Jun 2016

Prawn

Prawn is a pure Ruby PDF generation library that provides a lot of great functionality while trying to remain simple and reasonably performant.

Sample Usage

create/Initialize new document without having first page created :-

prawn_pdf = Prawn::Document.new(skip_page_creation: true)

adding new page with giving dimension :-

prawn_pdf.start_new_page(size: [width,height])

adding a bounding box having a image into it :-

prawn_pdf.bounding_box([0, 0], :width => width, :height => height) do
prawn_pdf.image "image_location", at: [0, 0]
end

adding a text annotation with content :-

prawn_pdf.text_annotation([a,b,c,d], annotation_content)

adding a links-anchor and registering destination :-

prawn_pdf.text_box "<link anchor='anchor-#{anchor-identifier}'>THIS</link>",
                   inline_format: true, width: width, height: height

prawn_pdf.add_dest("anchor-#{anchor-identifier}", prawn_pdf.dest_fit(prawn_pdf.page))

And if you get stuck… Ask Here

email me rajeevsharma86@gmail.com

Tweet to me at @rajeevkannav.