dimanche 29 janvier 2017

page layout on prawn unable to set inside class

i have searched in prawn about page layout in prawn and it showed this

pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)

pdf.text doesnt print anything

but when i try this i'm getting undefined method

page_layout :landscape

added after super()

this is my whole code

class ProductPdfGenerate < Prawn::Document
    require 'open-uri'
    def initialize(order_items)
        super()
        @document = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
        @order_items = order_items
        @order_items.each_with_index do |oi, i|
            if oi.case.present? && Model.where(magento_model_id: oi.case.model_id).first.present?
                style_image = oi.case.image_preview.url(:custom_image)
                model = Model.where(magento_model_id: oi.case.model_id).first
                # image open(style_image), width: "200".to_f, height: "400".to_f
                image open(style_image), width: "#{model.aspect_ratio_width.to_f/2.54*72}".to_f, height: "#{model.aspect_ratio_height.to_f/2.54*72}".to_f
                text "\n \n \n"
                text "Model: #{model.name}"
                text "Model Category: #{model.category_type}"
                text "Style: #{oi.case.style.try(:name)} "
                text "Order Id: #{oi.order_id}"
            else
                image open("http://ift.tt/2kg54Ti")
            end
        end
    end
end

Aucun commentaire:

Enregistrer un commentaire