pdf-burst 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ # PDF::Burst Changelog
2
+
3
+ ## 0.2.0 (2010-06-30)
4
+
5
+ Adds thumbnail generation using 'convert' from ImageMagick. Check out the README file for more information.
6
+
7
+ Renamed options:
8
+
9
+ * :output_path => :output
10
+ * :output_filename => :filename
@@ -0,0 +1,46 @@
1
+ # PDF::Burst
2
+
3
+ ## What?
4
+
5
+ PDF::Burst is a gem that lets you split a PDF document with several pages into single page files.
6
+
7
+
8
+ ## Why?
9
+
10
+ We needed this functionality for the development of [Lehtilompakko](http://lehtilompakko.fi/), and did not want any Java app to do the job.
11
+
12
+
13
+ ## How?
14
+
15
+ Simple! Once you install the 'pdf-burst' gem, all you need is:
16
+
17
+ require 'pdf-burst'
18
+ PDF::Burst.new("/path/to/my/document.pdf").run!
19
+
20
+ By default, the PDF files will be output to your current working directory. But that's not what you want, is it?
21
+
22
+ PDF::Burst.new("document.pdf", :output => "/tmp").run!
23
+
24
+ Better, huh?
25
+
26
+ Another default is the page name. They'll all be nicely named like "page_1.pdf", "page_2.pdf". We let you change that too:
27
+
28
+ PDF::Burst.new("document.pdf", :filename => "doc.%04d").run!
29
+
30
+ Would output them like this: "doc.0001.pdf", "doc.0002.pdf", etc.
31
+
32
+ If you want thumbnails to be generated for each page, just use the thumbnail option with the thumbnail size.
33
+
34
+ PDF::Burst.new("document.pdf", :thumbnail => "128x128").run!
35
+
36
+ This requires ImageMagick to be installed, as it uses the 'convert' command.
37
+
38
+
39
+ ## Special thanks
40
+
41
+ Thanks to [Hopeinen Norsu](http://hopeinennorsu.fi/) for letting us release this as open-source.
42
+
43
+
44
+ ## License
45
+
46
+ Check the LICENSE file. It's the MIT license.
@@ -2,14 +2,16 @@ module PDF
2
2
  class Burst
3
3
  def initialize(pdf_path, options={})
4
4
  @pdf_path = pdf_path
5
- @output_path = options[:output_path] || "."
6
- @page_name = options[:output_filename] || "page_%d"
5
+ @output_path = options[:output] || "."
6
+ @page_name = options[:filename] || "page_%d"
7
+ @thumbnail_size = options[:thumbnail]
7
8
  end
8
9
 
9
10
  def run!
10
11
  page_count.times do |i|
11
12
  page_number = i + 1
12
13
  system burst_command(page_number)
14
+ system thumbnail_command(page_number) if generate_thumbnail?
13
15
  end
14
16
  end
15
17
 
@@ -17,6 +19,10 @@ module PDF
17
19
  `#{page_count_command}`.to_i
18
20
  end
19
21
 
22
+ def generate_thumbnail?
23
+ !!@thumbnail_size
24
+ end
25
+
20
26
  private
21
27
 
22
28
  def page_count_command
@@ -27,12 +33,16 @@ module PDF
27
33
  "gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dFirstPage=#{page_number} -dAutoFilterColorImages=false -dAutoFilterGrayImage=false -dColorImageFilter=/FlateEncode -dLastPage=#{page_number} -sOutputFile='#{output_file_path(page_number)}' '#{@pdf_path}'"
28
34
  end
29
35
 
30
- def page_filename(page_number)
31
- @page_name % page_number + ".pdf"
36
+ def thumbnail_command(page_number)
37
+ "convert -resize #{@thumbnail_size} #{output_file_path(page_number)} #{output_file_path(page_number, 'png')}"
38
+ end
39
+
40
+ def page_filename(page_number, extension="pdf")
41
+ @page_name % page_number + ".#{extension}"
32
42
  end
33
43
 
34
- def output_file_path(page_number)
35
- File.expand_path("#{@output_path}/#{page_filename(page_number)}")
44
+ def output_file_path(page_number, extension="pdf")
45
+ File.expand_path("#{@output_path}/#{page_filename(page_number, extension)}")
36
46
  end
37
47
  end
38
48
  end
@@ -1,5 +1,5 @@
1
1
  module PDF
2
2
  class Burst
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf-burst
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joao Carlos
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-01 00:00:00 +03:00
18
+ date: 2010-06-30 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: "Creates a PDF for each page from a PDF with multiple pages. Uses Ghostscript for the actual bursting. You'll need the following commands available on your system: gs (Ghostscript), pdfinfo (Poppler) and grep."
22
+ description: "Creates a PDF for each page from a PDF with multiple pages. Uses Ghostscript for the actual bursting. You'll need the following commands available on your system: gs (Ghostscript), pdfinfo (Poppler), grep and convert (ImageMagick) if you want thumbnails."
23
23
  email:
24
24
  - mail@joao-carlos.com
25
25
  executables:
@@ -29,11 +29,13 @@ extensions: []
29
29
  extra_rdoc_files: []
30
30
 
31
31
  files:
32
- - lib/pdf/burst/version.rb
33
- - lib/pdf/burst.rb
34
32
  - lib/pdf-burst.rb
33
+ - lib/pdf/burst.rb
34
+ - lib/pdf/burst/version.rb
35
35
  - bin/pdf-burst
36
36
  - LICENSE
37
+ - CHANGELOG.md
38
+ - README.md
37
39
  has_rdoc: true
38
40
  homepage: http://github.com/kiskolabs/pdf-burst
39
41
  licenses: []