Sha256: b47aa4c1122537a3d0bd922ede3086b30d379aeb4d9775eb24d49498bc7a5531

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

module Asposepdfjava
  module AddText
    def initialize()
    	# The path to the documents directory.
        data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
                
        # Instantiate Document object
        doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + 'input1.pdf')

        # get particular page
        pdf_page = doc.getPages().get_Item(1)
        
        # create text fragment
        text_fragment = Rjb::import('com.aspose.pdf.TextFragment').new("main text")
        text_fragment.setPosition(Rjb::import('com.aspose.pdf.Position').new(100, 600))

        
        font_repository = Rjb::import('com.aspose.pdf.FontRepository')
        color = Rjb::import('com.aspose.pdf.Color')

        # set text properties
        text_fragment.getTextState().setFont(font_repository.findFont("Verdana"))
        text_fragment.getTextState().setFontSize(14)
        #text_fragment.getTextState().setForegroundColor(color.BLUE)
        #text_fragment.getTextState().setBackgroundColor(color.GRAY)

        # create TextBuilder object
        text_builder = Rjb::import('com.aspose.pdf.TextBuilder').new(pdf_page)
        
        # append the text fragment to the PDF page
        text_builder.appendText(text_fragment)
        
        # Save PDF file
        doc.save(data_dir + "Text_Added.pdf")

        puts "Text added successfully"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
asposepdfjava-0.0.2 lib/asposepdfjava/Text/addtext.rb
asposepdfjava-0.0.1 lib/asposepdfjava/Text/addtext.rb