2 Replies Latest reply on Sep 8, 2015 9:06 PM by shivratan gupta

    i am not able to add the image in PDF,

    shivratan gupta

      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