prawnpdf / prawn-table

Provides support for tables in Prawn
Other
205 stars 98 forks source link

Not able to put Barcode inside the table, getting UnrecognizedTableContent error #108

Closed psaravanan-vss closed 2 years ago

psaravanan-vss commented 6 years ago

Any solution for this?

psaravanan-vss commented 6 years ago

Solution: In Prawn, table allowing to insert image, so I converted the Barcode to image and placed that image in table. Using below gem I generated base64 image content and temporarily stored in /tmp directory (since we have give absolute image path) and placed inside the Table. gem 'chunky_png'

  barcode_string = 'barcode_string'.to_s
  barcode = Barby::Code128B.new(barcode_string)
  blob = Barby::PngOutputter.new(barcode).to_png #Raw PNG data
  File.open('tmp/barcode.png', 'wb'){|f| f.write blob }
  File.open("tmp/barcode1.png", 'wb'){|f| f.write barcode.to_png } # Temporarily store in tmp directory to print into pdf

data = [ {image: "#{Rails.root.to_s}/tmp/barcode1.png", image_width: 120, image_height: 40, position: :center} ]
Volosh1n commented 4 years ago

@psaravanan-vss , thank you so much!

petergoldstein commented 2 years ago

@pointlessone I think this can be closed or converted into a discussion at your discretion.