barcode generating in ruby on rails

1,090 views
Skip to first unread message

fruti saritha

unread,
Jun 1, 2012, 6:19:03 AM6/1/12
to Barby
Can any one help..how to generate a barcode by using barby gem......i
am getting image file of 7bytes in jpeg , png formats but it was not
opened in any photo viewers...even pdf format also.............

**********LOOKING FOR YOUR VALUABLE REPLAY *********************
THANKS IN ADVANSE

Tore Darell

unread,
Jun 1, 2012, 6:20:15 AM6/1/12
to ruby-...@googlegroups.com
How are you generating it? Code?
> --
> You received this message because you are subscribed to the Google Groups "Barby" group.
> To post to this group, send email to ruby-...@googlegroups.com.
> To unsubscribe from this group, send email to ruby-barby+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ruby-barby?hl=en.
>

Philippe Nenert

unread,
Jun 1, 2012, 6:20:48 AM6/1/12
to ruby-...@googlegroups.com
Where is your code ?
If you want help, give your code !!!
Thanks, Philippe

fruti saritha

unread,
Jun 1, 2012, 6:25:40 AM6/1/12
to Barby

class UsingBarby < ActiveRecord::Base

# Gemfile, run bundle install after adding
gem 'barby'
gem 'chunky_png'

# some code to generate the png file using 3 of 9 barcode style
require 'barby'
require 'barby/barcode/code_128'
require 'barby/outputter/png_outputter'
#require 'barby/outputter/svg_outputter'
#require 'barby/outputter/ascii_outputter'
#require 'barby/outputter/pdfwriter'
#require 'barby/outputter/rmagick_outputter'

barcode = Barby::Code128B.new('saritha')
File.open('exleaz.png', 'w'){|f|

f.write barcode.to_png(:margin => 3, :xdim => 2, :height => 55)
}

end

fruti saritha

unread,
Jun 1, 2012, 6:40:08 AM6/1/12
to Barby

I AM USING WINDOWS7 OS , RUBY 1.8.7 RAILS 2.3.8.
i am getting output in .svg format.
still i require it in jpeg or png format.......
please help for this.....

thanks,saritha

JMcCleery

unread,
Jun 1, 2012, 7:35:39 AM6/1/12
to Barby
I had the same problem on windows. Windows automatically converts cr
control characters into crlf characters unless you use the binary
write option. Use:
File.open('exleaz.png', 'bw'){|f|
Message has been deleted

fruti saritha

unread,
Jun 1, 2012, 9:27:06 AM6/1/12
to Barby

when i was trying with the above mode i.e, bw mode i am getting
illegal access mode error...

can u help me.......

thanks,

Ch.sariths

JMcCleery

unread,
Jun 1, 2012, 9:53:41 AM6/1/12
to Barby
Sorry, I mis-wrote that. I just double-checked my code and it should
be 'wb' not 'bw':
File.open('exleaz.png', 'wb')

fruti saritha

unread,
Jun 2, 2012, 12:47:10 AM6/2/12
to Barby
hey.......I got the output. Thank You so much.

but , how to generate code at the bottom of the image.
Reply all
Reply to author
Forward
0 new messages