i am not able to add the image in PDF,

s shivratan gupta 2 years 11 months ago
1 1 0

Hi,
i am using the PDF writer to generate the PDF on click of link,
i want to add the image in the PDF file (like any logo)...but i am not ablew to do it...

Below is the sample code ..
Please any one have idea about it ..so help me.

Thanks

require 'rho/rhocontroller'
require 'pdf/writer.rb'
require 'thread'
require 'pdf/open-uri'
require 'pdf/simpletable.rb'

class QuotationController Rho::RhoController
===================================================================================================
   def make_pdf
        # prepare DPF file on local file system in User folder
        #
        # for generate PDF we use open source pure Ruby library PDF-Writer
        # Homepage::  http://rubyforge.org/projects/ruby-pdf/
        # Copyright:: 2003-2005, Austin Ziegler
        #
        # PDF-Writer also require few additional Ruby libs:
        #   color
        #   transaction-simple
        #   thread
        #
        # You can see their Ruby code in rodes platform extension folder:
        #  [Rhodes root]/lib/extensions
        #
        # for include that libs to your application you should add next extsnions to your application extension list in your application build.yml :
        # "pdf-writer", "thread"
        #

         pdf = PDF::Writer.new
       ### i have used all the three method for adding imgae in pdf   
      pdf.image "#{Rho::RhoApplication.get_base_app_path()}public/images/loading_1.JPEG", :resize => 0.75
    
      pdf.add_image("#{Rho::RhoApplication.get_base_app_path()}public/images/Jellyfish.jpg", 0,0)
     
      pdf.add_image_from_file("#{Rho::RhoApplication.get_base_app_path()}public/images/Jellyfish.jpg",  100,100)
    
    
        file_location = File.join('/sdcard/','demo.pdf')
        pdf.save_as(file_location)
        System.open_url(file_location)
        redirect :action => :index
  end

Please register or login to post a reply

1 Replies

J Jon Tara

What happens when you try it?

Note that Ruby threads will not work on Android! Since you load thread, I assume pdf-writer uses Ruby threads.

CONTACT
Can’t find what you’re looking for?