itext-jruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ ruby '1.9.3', engine: 'jruby', engine_version: '1.7.4'
4
+
5
+ group :development do
6
+ gem "shoulda"
7
+ gem "rdoc"
8
+ gem "bundler"
9
+ gem "jeweler"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.0)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.13-java)
12
+ builder (3.2.2)
13
+ faraday (0.8.8)
14
+ multipart-post (~> 1.2.0)
15
+ git (1.2.6)
16
+ github_api (0.10.1)
17
+ addressable
18
+ faraday (~> 0.8.1)
19
+ hashie (>= 1.2)
20
+ multi_json (~> 1.4)
21
+ nokogiri (~> 1.5.2)
22
+ oauth2
23
+ hashie (2.0.5)
24
+ highline (1.6.19)
25
+ httpauth (0.2.0)
26
+ i18n (0.6.5)
27
+ jeweler (1.8.7)
28
+ builder
29
+ bundler (~> 1.0)
30
+ git (>= 1.2.5)
31
+ github_api (= 0.10.1)
32
+ highline (>= 1.6.15)
33
+ nokogiri (= 1.5.10)
34
+ rake
35
+ rdoc
36
+ json (1.8.0-java)
37
+ jwt (0.1.8)
38
+ multi_json (>= 1.5)
39
+ minitest (4.7.5)
40
+ multi_json (1.7.9)
41
+ multi_xml (0.5.5)
42
+ multipart-post (1.2.0)
43
+ nokogiri (1.5.10-java)
44
+ oauth2 (0.9.2)
45
+ faraday (~> 0.8)
46
+ httpauth (~> 0.2)
47
+ jwt (~> 0.1.4)
48
+ multi_json (~> 1.0)
49
+ multi_xml (~> 0.5)
50
+ rack (~> 1.2)
51
+ rack (1.5.2)
52
+ rake (10.1.0)
53
+ rdoc (4.0.1)
54
+ json (~> 1.4)
55
+ shoulda (3.5.0)
56
+ shoulda-context (~> 1.0, >= 1.0.1)
57
+ shoulda-matchers (>= 1.4.1, < 3.0)
58
+ shoulda-context (1.1.5)
59
+ shoulda-matchers (2.3.0)
60
+ activesupport (>= 3.0.0)
61
+ thread_safe (0.1.2-java)
62
+ atomic
63
+ tzinfo (0.3.37)
64
+
65
+ PLATFORMS
66
+ java
67
+
68
+ DEPENDENCIES
69
+ bundler
70
+ jeweler
71
+ rdoc
72
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Ernest Bursa
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,35 @@
1
+ = itext-jruby
2
+
3
+ IText Pdf generation static java build packed to gem with some additional Ruby methods.
4
+
5
+ == Usage
6
+
7
+ === Instalation
8
+ require 'itext-jruby'
9
+
10
+ == Example
11
+ @source_pdf = File.expand_path('pdf_demo.pdf')
12
+ @sample_image = File.expand_path('ja.jpg')
13
+ @output_pdf = File.expand_path('out.pdf')
14
+
15
+ @pdf_document = Itext.new(path: @path)
16
+ @pdf_document.add_attachment @pathb
17
+ @pdf_document.save(@out)
18
+
19
+ Find more examples in test directory.
20
+
21
+
22
+ == Contributing to itext-jruby
23
+
24
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
25
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
26
+ * Fork the project.
27
+ * Start a feature/bugfix branch.
28
+ * Commit and push until you are happy with your contribution.
29
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
30
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
31
+
32
+ == Copyright
33
+
34
+ Copyright (c) 2013 Ernest Bursa. See LICENSE.txt for
35
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "itext-jruby"
18
+ gem.homepage = "http://github.com/swistaczek/itext-jruby"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{jRuby}
21
+ gem.description = %Q{IText}
22
+ gem.email = "ernest@bzdury.pl"
23
+ gem.authors = ["Ernest Bursa"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "itext #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+ module Itext::Attachments
3
+
4
+ def initialize(*args, &block)
5
+ @hooks ||= []
6
+ @hooks.push ->{ process_attachments }
7
+ end
8
+
9
+ def self.included(base)
10
+ base.extend(ClassMethods)
11
+ attr_reader :attachments
12
+
13
+ # base.class_eval do
14
+ # original_method = instance_method(:initialize)
15
+ # define_method(:initialize) do |*args, &block|
16
+ # original_method.bind(self).call(*args, &block)
17
+ # @hooks.push ->{ process_attachments }
18
+ # end
19
+ # end
20
+ end
21
+
22
+ def add_attachments(attachments)
23
+ @attachments ||= []
24
+ attachments = [attachments] unless attachments.is_a?(Array)
25
+ attachments.each do |attachment|
26
+ if File.exists?(attachment)
27
+ @attachments << attachment
28
+ end
29
+ end
30
+ @attachments
31
+ end
32
+
33
+ alias :add_attachment :add_attachments
34
+
35
+ def remove_attachments(attachments)
36
+ @attachments ||= []
37
+ attachments = [attachments] unless attachments.is_a?(Array)
38
+ attachments.each do |attachment|
39
+ if File.exists?(attachment)
40
+ @attachments.delete(attachment)
41
+ end
42
+ end
43
+ @attachments
44
+ end
45
+
46
+ alias :remove_attachment :remove_attachments
47
+
48
+ def process_attachments
49
+ @writer = @stamper.getWriter.to_java(Java::ComLowagieTextPdf::PdfWriter)
50
+
51
+ @attachments.each do |attachment_path|
52
+ attachment_name = Pathname.new(attachment_path).basename.to_s.to_java_string
53
+ attachment_spec = Java::ComLowagieTextPdf::PdfFileSpecification.fileEmbedded @writer,
54
+ attachment_path.to_java_string,
55
+ attachment_name,
56
+ nil
57
+ attachment_spec.addDescription attachment_name, false.to_java(:boolean)
58
+ @stamper.addFileAttachment attachment_name, attachment_spec
59
+ end
60
+
61
+ # @writer.close
62
+ end
63
+
64
+ protected :process_attachments
65
+
66
+ module ClassMethods
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ require 'java'
3
+ Dir[File.expand_path(File.join(File.dirname(__FILE__), "../libexec/jar/*.jar"))].each { |jar| require jar }
4
+
5
+ import java.io.ByteArrayOutputStream
6
+ import com.lowagie.text.html.WebColors
7
+ import com.lowagie.text.Document
8
+ import com.lowagie.text.Paragraph
9
+ import com.lowagie.text.Phrase
10
+ import com.lowagie.text.PageSize
11
+ import com.lowagie.text.Chunk
12
+ import com.lowagie.text.pdf.PdfPCell
13
+ import com.lowagie.text.pdf.PdfPTable
14
+ import com.lowagie.text.BadElementException
15
+ import com.lowagie.text.DocumentException
16
+ import com.lowagie.text.Image
17
+ import com.lowagie.text.pdf.PdfFileSpecification
18
+ import com.lowagie.text.pdf.PdfReader
19
+ import com.lowagie.text.pdf.PdfSignatureAppearance
20
+ import com.lowagie.text.pdf.PdfStamper
21
+ import com.lowagie.text.pdf.PdfWriter
22
+ import java.io.FileOutputStream
23
+
24
+ require 'itext'
data/lib/itext.rb ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ require 'pathname'
3
+
4
+ class Itext
5
+ require 'itext/attachments'
6
+
7
+ include Attachments
8
+
9
+ # Create new Itext document instance
10
+ # Required params:
11
+ # path: Pass absolute path to pdf file
12
+ def initialize(*args, &block)
13
+ super
14
+
15
+ opts = args[0] if args.is_a?(Array)
16
+ @path = opts[:path]
17
+
18
+ raise ArgumentError.new('Missing :path') if @path.nil?
19
+ raise ArgumentError.new('Please provide absolute path') unless Pathname.new(@path).absolute?
20
+ end
21
+
22
+ def save(save_to = nil)
23
+ save_to ||= @path
24
+ raise ArgumentError.new('Specified file does not exists') unless File.exists?(@path)
25
+
26
+ @reader = Java::ComLowagieTextPdf::PdfReader.new(@path.to_java(:string))
27
+ @buffer = Java::JavaIo::FileOutputStream.new save_to
28
+ @stamper = Java::ComLowagieTextPdf::PdfStamper.new @reader, @buffer
29
+
30
+ # Run all attached hooks
31
+ @hooks.each { |hook| hook.call }
32
+
33
+ @stamper.close
34
+
35
+ # Return output path
36
+ save_to
37
+ end
38
+
39
+ protected
40
+
41
+ def hooks
42
+ @hooks || []
43
+ end
44
+
45
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'itext-jruby'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ class TestItextJruby < Test::Unit::TestCase
5
+ should "create pdf file" do
6
+ @document = Java::ComLowagieText::Document.new(Java::ComLowagieText::PageSize::A4, 20, 20, 20, 20)
7
+ @file = Java::JavaIo::FileOutputStream.new "pdf_demo.pdf"
8
+
9
+ para = Java::ComLowagieText::Paragraph.new "Brought to you by JRuby using itext-jruby ext"
10
+
11
+ table = Java::ComLowagieTextPdf::PdfPTable.new 3
12
+ table.setWidthPercentage 100
13
+ table.setHeaderRows 2
14
+ table.setFooterRows 1
15
+
16
+ cell = Java::ComLowagieTextPdf::PdfPCell.new Java::ComLowagieText::Phrase.new("Cell with colspan = 3")
17
+ cell.setColspan 3
18
+ cell.setBackgroundColor Java::ComLowagieTextHtml::WebColors.getRGBColor("#A00000")
19
+ table.addCell cell
20
+
21
+ (1..300).each do |i|
22
+ cell = Java::ComLowagieTextPdf::PdfPCell.new Java::ComLowagieText::Phrase.new("Cell #{i}")
23
+ cell.setBackgroundColor Java::ComLowagieTextHtml::WebColors.getRGBColor("#66c3dd")
24
+ table.addCell cell
25
+ end
26
+
27
+ @writer = Java::ComLowagieTextPdf::PdfWriter.get_instance @document, @file
28
+
29
+ @document.open
30
+ @document.add para
31
+ @document.add Java::ComLowagieText::Chunk::NEWLINE
32
+ @document.add table
33
+ @document.close
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itext-jruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Ernest Bursa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ none: false
28
+ prerelease: false
29
+ type: :development
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ prerelease: false
45
+ type: :development
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ none: false
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ none: false
60
+ prerelease: false
61
+ type: :development
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ none: false
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ none: false
76
+ prerelease: false
77
+ type: :development
78
+ description: IText
79
+ email: ernest@bzdury.pl
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files:
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ files:
86
+ - .document
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ - Rakefile
92
+ - VERSION
93
+ - lib/itext-jruby.rb
94
+ - lib/itext.rb
95
+ - lib/itext/attachments.rb
96
+ - libexec/jar/bcmail-jdk14-138.jar
97
+ - libexec/jar/bcprov-jdk14-138.jar
98
+ - libexec/jar/bctsp-jdk14-138.jar
99
+ - libexec/jar/crimson.jar
100
+ - libexec/jar/dom4j-1.6.1.jar
101
+ - libexec/jar/iText-rtf.jar
102
+ - libexec/jar/iText-rups.jar
103
+ - libexec/jar/iText.jar
104
+ - libexec/jar/iTextAsian.jar
105
+ - libexec/jar/iTextAsianCmaps.jar
106
+ - libexec/jar/itext-hyph-xml.jar
107
+ - libexec/jar/jcommon.jar
108
+ - libexec/jar/jfreechart.jar
109
+ - libexec/jar/junit-4.4.jar
110
+ - libexec/jar/pdf-renderer.jar
111
+ - libexec/jar/servlet.jar
112
+ - test/helper.rb
113
+ - test/test_itext-jruby.rb
114
+ homepage: http://github.com/swistaczek/itext-jruby
115
+ licenses:
116
+ - MIT
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ segments:
127
+ - 0
128
+ hash: 2
129
+ none: false
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ none: false
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 1.8.24
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: jRuby
142
+ test_files: []