prawn

Generating a PDF With Images from Base64 with Prawn

依然范特西╮ 提交于 2019-12-05 07:11:55
I am trying to save multiple pngs in one pdf. I'm receiving the PNGs from an API Call to the Endicia Label Server, which is giving me a Base64 Encoded Image as response. Based on this Question: How to convert base64 string to PNG using Prawn without saving on server in Rails def batch_order_labels @orders = Spree::Order.ready_to_ship.limit(1) dt = Date.current.strftime("%d %b %Y ") title = "Labels - #{dt} - #{@orders.count} Orders" Prawn::Document.generate("#{title}.pdf") do |pdf| @orders.each do |order| label = order.generate_label if order.international? @image = label.response_body.scan(/

Prawn doesn't seem to push layout down when using repeat(:all)

不想你离开。 提交于 2019-12-05 01:01:06
问题 I am generating a document with data that flows onto each subsequent page, each page has a standard header. However, when I use repeat(:all) to put the header on each page, I find that on every page but the first page, the next content is not being moved down by the size of the header banner I have put on the page. My code for generating the banner: class SmartsoftPdf < Prawn::Document BOX_MARGIN = 30 RHYTHM = 10 INNER_MARGIN = 30 # Colors # BLACK = "000000" LIGHT_GRAY = "F2F2F2" GRAY =

Start new page automatically when using stacked bounding boxes in Prawn

五迷三道 提交于 2019-12-04 13:00:25
I want to simulate the behaviour of a table in Prawn, but can't use table because of the limitation of things I can draw inside cells. So I am using bounding boxes in order to create contexts for the elements inside each row. The problem I'm having has to do with the rows. I'm trying this: require 'prawn' Prawn::Document.generate("test.pdf") do move_down 50 bounding_box [0, cursor], width: bounds.width do 20.times do |i| stroke_bounds && start_new_page if (i+1) % 11 == 0 bounding_box [0, cursor], width: bounds.width, height: 50 do fill_color "cccccc" fill_rectangle [0, bounds.height], bounds

Any font for generating pdf that will handle Chinese, Cyrillic… ?

橙三吉。 提交于 2019-12-04 06:10:40
I'm creating generator of pdf documents in Ruby on Rails with Prawn gem and I came up with issue that when I have Chinese, Japanese and Cyrillic chars they are displayed incorrectly. I googled out that it's because "when I'm generating font I need to specify, what font should pdf text be rendered with" . Now this isn't the issue, but the fact that my documents will include all different possible chars that gTLD supports . Question 1: Do you know any font for generating pdf documents that will include as many as possible chars (Asian, Europe, Symbols, ...)? Ideally all chars that gTLD supports.

Prawn gem: How to create the .pdf from an *existing* file (.xls)

与世无争的帅哥 提交于 2019-12-04 06:06:19
问题 Can anybody show me (maybe copy/paste a simple code example) how to create the .pdf file from an existing (.xls) file, using the Prawn gem? (Basically, I'd need the command that "opens" the existing file.) (I'm asking because the Prawn documentation (http://prawn.majesticseacreature.com/docs/) seems to be gone since quite a while - it's not even usable via Google cache...) Thanks a lot for any help with this! Tom 回答1: I'd suggest that you break the problem down. Can you read xls with Ruby?

Ruby - How to use different fonts in Prawn?

霸气de小男生 提交于 2019-12-04 05:51:43
I have a small Ruby program where I'm printing some text out to a PDF using Prawn, but a small portion of the text is non-English characters. (Some of that text is Chinese, some is Greek, etc.). When I run my program, I of course get an error saying Your document includes text that's not compatible with the Windows-1252 character set. (Prawn::Errors::IncompatibleStringEncoding) If you need full UTF-8 support, use TTF fonts instead of PDF's built-in fonts . I know that I need to use a TTF font, but how do I even go about that? Do I need to install it from online? If so, where would I save it to

Background images using prawn on all pages

帅比萌擦擦* 提交于 2019-12-04 05:33:27
I have this code in the view prawn_document(:page_size=> "A4", :top_margin => 80, :bottom_margin => 40, :background => "public/uploads/1.png") do |pdf| creation_date = Time.now.strftime('%d-%m-%Y') posts = @posts.each do |post| pdf.pad(10) do pdf.text post.title pdf.text post.text end end pdf.page_count.times do |i| pdf.go_to_page(i + 1) pdf.draw_text "Creation Date : " + creation_date, :at => [200, 780] pdf.draw_text "Page : #{i + 1} / #{pdf.page_count}", :at => [450, -3] end end This gives me the following output: and this As you can see in the first image, the image is not centered. On the

Watermark in existing PDF in Ruby

不打扰是莪最后的温柔 提交于 2019-12-03 16:52:16
问题 I would like to add a dynamically generated text. Is there a way to watermark an existing PDF in Ruby? 回答1: This will do it: PDF::Reader to count the number of pages in the file. Prawn to create a new PDF document using each page of the input pdf as a template. require 'prawn' require 'pdf-reader' input_filename = 'input.pdf' output_filename = 'output.pdf' page_count = PDF::Reader.new(input_filename).page_count Prawn::Document.generate(output_filename, :skip_page_creation => true) do |pdf|

rails gem prawn, image and anchor

偶尔善良 提交于 2019-12-03 13:11:42
Can you tell me how to insert image which will be a link to for example page 20? I know how to make with normal text: text "<link anchor='page20'>Go to page 20</link>", :inline_format=>true and then on page 20 I have add_dest('page20', dest_fit(page.dictionary)) but how to do this with image ? Prawn does not support this functionality. In fact, even if you placed a formatted_text_box over an image and fill it with white space, it still will not work. An anchor has to include text to work. If you don't mind having text over your image, then that might be a solution. Prawn's own readme states:

Add image in pdf using Prawn

微笑、不失礼 提交于 2019-12-03 12:17:56
I've a problem for adding images into a PDF using Prawn as pdf generator. I'm trying to add image using the following code: def header text "something" image "#{Prawn::DATADIR}/images/logo_small.png" end But app replies to me with the following error: uninitialized constant Prawn::DATADIR Where is the mistake? P.S. My app is running on Rails 3.1 & Ruby 1.9.2. Prawn::DATADIR is new, it has been introduced recently about 2 or 3 months ago. Previously one would have used Prawn::BASEDIR/data instead. If you are using the current 0.12.0 version of the gem, you should stick with Prawn::BASEDIR/data