Sha256: 0d9fdd910705017c824574b682ed82e73c971f92defe42a2cf82e6bbc15c0258

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

require 'nailgun'
module ActsAsFlyingSaucer

	# Xhtml2Pdf
	#
	class Xhtml2Pdf
		def self.write_pdf(options)

			if 	!File.exists?(options[:input_file])
				File.open(options[:input_file], 'w') do |file|
					file << options[:html]
				end
			end
     class_path = ""
			java_dir = File.join(File.expand_path(File.dirname(__FILE__)), "java")
			 Dir.glob("#{java_dir}/jar/*.jar") do |jar|
          class_path << "#{options[:classpath_separator]}#{jar}"
        end
			

			if options[:nailgun]
				command = "#{Nailgun::NgCommand::NGPATH} --nailgun-server #{ActsAsFlyingSaucer::Config.options[:nailgun_host]}  --nailgun-port #{ ActsAsFlyingSaucer::Config.options[:nailgun_port]} Xhtml2Pdf #{options[:input_file]} #{options[:output_file]}"
			else
				command = "#{options[:java_bin]} -Xmx#{options[:max_memory_mb]}m -Djava.awt.headless=true -cp #{class_path} acts_as_flying_saucer.Xhtml2Pdf #{options[:input_file]} #{options[:output_file]}"
			end
			system(command)
		end

		def self.encrypt_pdf(options,output_file_name,password)
			java_dir = File.join(File.expand_path(File.dirname(__FILE__)), "java")
			class_path = "'.#{options[:classpath_separator]}#{java_dir}/jar/acts_as_flying_saucer.jar'"
			if options[:nailgun]
				command = "#{Nailgun::NgCommand::NGPATH}  --nailgun-server #{ActsAsFlyingSaucer::Config.options[:nailgun_host]}  --nailgun-port #{ ActsAsFlyingSaucer::Config.options[:nailgun_port]} encryptPdf #{options[:input_file]} #{options[:output_file]}"
			else
				command = "#{options[:java_bin]} -Xmx#{options[:max_memory_mb]}m -Djava.awt.headless=true -cp #{class_path} acts_as_flying_saucer.encryptPdf #{options[:output_file]} #{output_file_name} #{password}"
			end
			system(command)
		end

	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_flying_saucer-1.0.4 lib/acts_as_flying_saucer/xhtml2pdf.rb