Sha256: 23ee29d355c10b11b6ac547ec7eb58dcc518f8aa28857cdb9f4042562e2a0254

Contents?: true

Size: 1.94 KB

Versions: 16

Compression:

Stored size: 1.94 KB

Contents

# -*- encoding : utf-8 -*-
########################################################
## Thoughts from reading the ISO 32000-1:2008
## this file is part of the CombinePDF library and the code
## is subject to the same license.
########################################################




module CombinePDF

	# Limited Unicode Support (font dependent)!
	#
	# The PDFWriter class is a subclass of Hash and represents a PDF Page object. 
	#
	# Writing on this Page is done using the textbox function.
	#
	# Setting the page dimensions can be either at the new or using the mediabox method. New pages default to size A4, which is: [0, 0, 595.3, 841.9].
	#
	# Once the Page is completed (the last text box was added),
	# we can insert the page to a CombinePDF object.
	#
	# We can either insert the PDFWriter as a new page:
	#   pdf = CombinePDF.new
	#   new_page = CombinePDF.create_page # => PDFWriter object
	#   new_page.textbox "some text"
	#   pdf << new_page
	#   pdf.save "file_with_new_page.pdf"
	#
	# Or we can use the Page_Methods methods to write an overlay (stamp / watermark) over existing pages:
	#   pdf = CombinePDF.new
	#   new_page = PDFWriter.new "some_file.pdf"
	#   pdf.pages.each {|page| page.textbox "Draft", opacity: 0.4 }
	#   pdf.save "stamped_file.pdf"
	class PDFWriter < Hash

		# create a new PDFWriter object.
		#
		# mediabox:: the PDF page size in PDF points. defaults to [0, 0, 612.0, 792.0] (US Letter)
		def initialize(mediabox = [0, 0, 612.0, 792.0])
			# indirect_reference_id, :indirect_generation_number
			@contents = ""
			@base_font_name = "Writer" + SecureRandom.hex(7) + "PDF"
			self[:Type] = :Page
			self[:indirect_reference_id] = 0
			self[:Resources] = {}
			self[:Contents] = { is_reference_only: true , referenced_object: {indirect_reference_id: 0, raw_stream_content: @contents} }
			self[:MediaBox] = mediabox
		end

		# includes the PDF Page_Methods module, including all page methods (textbox etc').
		include Page_Methods

	end
	
end





Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
combine_pdf-0.2.21 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.20 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.17 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.16 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.15 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.14 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.13 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.12 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.11 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.10 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.9 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.8 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.7 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.6 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.5 lib/combine_pdf/basic_writer.rb
combine_pdf-0.2.4 lib/combine_pdf/basic_writer.rb