Class: Pdf::Label::StorageLocationItem
- Inherits:
-
BaseService
- Object
- BaseService
- Pdf::Label::StorageLocationItem
- Defined in:
- app/services/pdf/label/storage_location_item.rb
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
10 11 12 |
# File 'app/services/pdf/label/storage_location_item.rb', line 10 def renderer @renderer end |
Class Method Details
.call(*args, **kwargs, &block) ⇒ Object
6 7 8 |
# File 'app/services/pdf/label/storage_location_item.rb', line 6 def self.call(*args, **kwargs, &block) new.call(*args, **kwargs, &block) end |
Instance Method Details
#call(items: nil, storage_locations: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/services/pdf/label/storage_location_item.rb', line 12 def call(items: nil, storage_locations: nil) Pdf::Loader.load! require 'down' raise 'Specify items or storage_locations' if items.nil? && storage_locations.nil? composer = HexaPDF::Composer.new(skip_page_creation: false, page_size: [0, 0, 288, 166.5], page_orientation: :landscape, margin: 10) dejavu = composer.document.fonts.add('data/fonts/DejaVuSans.ttf') composer.document.config['font.fallback'] = [dejavu] composer.document.config['font.on_invalid_glyph'] = lambda do |codepoint, _glyph| [dejavu.decode_codepoint(codepoint)] end items ||= Item.joins(store_items: :storage_locations).includes(:primary_image).merge(storage_locations) image_downloads = download_images(items) items.each do |item| image = image_downloads[item.primary_image_id] add_item_page(composer, item, image) end pdf_io = StringIO.new composer.write(pdf_io, optimize: true) pdf_io.rewind pdf_data = pdf_io.read Result.new(pdf: pdf_data, file_name: 'storage_locations_items.pdf') end |