shairontoledo / rghost

RGhost is a document creation and conversion API. It uses the Ghostscript framework for the format conversion, utilizes EPS templates and is optimized to work with larger documents. Support(PDF,PS,GIF,TIF,PNG,JPG,etc)
http://rghost.rubyforge.org
MIT License
187 stars 46 forks source link

Generate RGhost bar code inline (stream) #32

Closed jmarquesCC closed 11 years ago

jmarquesCC commented 11 years ago

I'm using RGhost-Rails to generate bar codes on a pdf file (with wicked-pdf).

I've the following code (in Ruby on Rails 3)

 <% doc=RGhost::Document.new :paper => [7,2]%>
 <% doc.barcode_code39('1234567', :text => {:size => 10, :offset => [0,-10], :enable => [:text, :check, :checkintext] }) %>
 <% r= doc.render :png, :resolution => 100, :debug => true, :filename => "./public/pdf/rghost_barcode.png"  %>

This code works fine but i want to generate my image inline (without worrying with the filename and filepath). Something like (i guess):

<% doc=RGhost::Document.new :paper => [7,2]%>
<% doc.barcode_code39('1234567', :text => {:size => 10, :offset => [0,-10], :enable => [:text, :check, :checkintext] }) %>

<img src="<%= RGhost inline functionality/ r= doc.render_stream :png??? %>" width="16" height="335" alt="asd">

In this way, i wouldn't have to worry about deleting the (generated) code bar files after showing the pdf.

There is any way to do this?

shairontoledo commented 11 years ago

You can do this using the url to your controller and invoking the code from your controller(without ERB), something like:

private

def barcodes doc=RGhost::Document.new :paper => [7,2] doc.barcode_code39('1234567', :text => {:size => 10, :offset => [0,-10], :enable => [:text, :check, :checkintext] }) send_data(doc.render_stream(:png), :type => "image/png", :disposition => 'inline') end

jmarquesCC commented 11 years ago

Hi,

I already had tried that solution... the problem is: the send_data function will sends the given binary data to the browser (so the browser will rendered the page as PNG (in this case)). :/