pdf2img-paperclip-processor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/lib/pdf2img-paperclip-processor.rb +33 -0
- data/lib/pdf2img-paperclip-processor/version.rb +7 -0
- data/pdf2img-paperclip-processor.gemspec +24 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cdf8bca4c89d6f35537bf73f00a6d8647f755762
|
4
|
+
data.tar.gz: 9e16ddd8560804acb874dca92b9c9762a01ee4eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a33d7707d723e89c775db0bab9cd8ab386580e7eb4c682732d3f871219d6803c8a659e91f98a18907cdd452507667725aad7dc5d588aefdd6978353a7910a07c
|
7
|
+
data.tar.gz: 09ad7153b9f1e29036aeec905e1754e8652f2b581915e1d184d2b4adea29e578607d6cac2d2369aaa6188beaca82f547aaa18851c6cdaeb6475460b838a4f395
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Ruby on Rails 4 Paperclip pdf to img Processor #
|
2
|
+
|
3
|
+
This gem is a simple Paperclip processor which uses rmagick/ImageMagik to convert uploaded pdf files to a image file. This processor supports multiple pages
|
4
|
+
|
5
|
+
## Requirements ##
|
6
|
+
|
7
|
+
* [Paperclip][0] ~> 5.0.0
|
8
|
+
* [rmagick][2] 2.16.0
|
9
|
+
|
10
|
+
## Installation ##
|
11
|
+
|
12
|
+
This gem is written and tested on Ruby on Rails 4 only. However, this could work on other versions as well provided that paperclip and rmagick is working.
|
13
|
+
|
14
|
+
In order to install it, add
|
15
|
+
|
16
|
+
gem 'pdf2img-paperclip-processor'
|
17
|
+
|
18
|
+
to your Gemfile and run
|
19
|
+
|
20
|
+
bundle install
|
21
|
+
|
22
|
+
in your console. Bundler should take care of all the rest.
|
23
|
+
|
24
|
+
or else, you can just download the file and copy it to paperclip processors folder of your project.
|
25
|
+
## rmagick Instalation ##
|
26
|
+
|
27
|
+
Install [rmagick][2] from source or using your favorite package manager.
|
28
|
+
|
29
|
+
Various Linux distributions should use similar methods with their respected package managers.
|
30
|
+
|
31
|
+
## Using Processor ##
|
32
|
+
|
33
|
+
Use it as you would any other Paperclip processor. In your model:
|
34
|
+
|
35
|
+
class Document < ActiveRecord::Base
|
36
|
+
|
37
|
+
has_attached_file :pdf,
|
38
|
+
:styles => { :final_doc => {:format => "png"}},
|
39
|
+
:processors => [:pdf2img]
|
40
|
+
|
41
|
+
|
42
|
+
which will convert your pdf document into a png, and keep both files (.png and .pdf) on the server
|
43
|
+
|
44
|
+
## Release info ##
|
45
|
+
|
46
|
+
Be warned, this gem is released as early beta version. If you are using it you are doing so on your own responsibility.
|
47
|
+
|
48
|
+
Have fun with it and drop me a note if you like it.
|
49
|
+
|
50
|
+
[0]: https://github.com/thoughtbot/paperclip
|
51
|
+
[2]: https://github.com/rmagick/rmagick
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "paperclip"
|
2
|
+
require 'rmagick'
|
3
|
+
|
4
|
+
module Paperclip
|
5
|
+
class Pdf2img < Processor
|
6
|
+
|
7
|
+
|
8
|
+
def initialize file, options = {}, attachment = nil
|
9
|
+
super
|
10
|
+
@file = file
|
11
|
+
@params = options[:params]
|
12
|
+
@format = options[:format]
|
13
|
+
@current_format = File.extname(@file.path)
|
14
|
+
@basename = File.basename(@file.path, @current_format)
|
15
|
+
end
|
16
|
+
|
17
|
+
def make
|
18
|
+
# Rails.logger.info("#{@file.path}")
|
19
|
+
return_file = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
|
20
|
+
if @file.content_type == "application/pdf"
|
21
|
+
images = Magick::ImageList.new(@file.path)
|
22
|
+
appended_img = images.append(true)
|
23
|
+
appended_img.write(return_file.path)
|
24
|
+
# Rails.logger.info("RETURN FILE: #{return_file.path}")
|
25
|
+
else
|
26
|
+
img = Magick::Image.read(@file.path).first
|
27
|
+
img.write(return_file.path)
|
28
|
+
end
|
29
|
+
return return_file
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "pdf2img-paperclip-processor/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "pdf2img-paperclip-processor"
|
7
|
+
s.version = Pdf2img::Paperclip::Processor::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.author = "Sujeev Vidanapathirana"
|
10
|
+
s.email = "sujeev@gmail.com"
|
11
|
+
s.homepage = "https://github.com/sujeev/pdf2img-paperclip-processor"
|
12
|
+
s.summary = %q{Converts uploaded pdf to img}
|
13
|
+
s.description = %q{This gem is a simple Paperclip processor which uses rmagick to convert uploaded pdf files to a image file. This processor supports multiple pages}
|
14
|
+
|
15
|
+
s.homepage = 'https://github.com/sujeev/Pdf2img'
|
16
|
+
# s.rubyforge_project = "pdf2img-paperclip-processor"
|
17
|
+
|
18
|
+
# s.add_dependency "paperclip", "~> 5.0.0"
|
19
|
+
s.add_runtime_dependency 'paperclip', '~> 5.1', '>= 5.1.0'
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pdf2img-paperclip-processor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sujeev Vidanapathirana
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: paperclip
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.1.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.1.0
|
33
|
+
description: This gem is a simple Paperclip processor which uses rmagick to convert
|
34
|
+
uploaded pdf files to a image file. This processor supports multiple pages
|
35
|
+
email: sujeev@gmail.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- ".gitignore"
|
41
|
+
- Gemfile
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- lib/pdf2img-paperclip-processor.rb
|
45
|
+
- lib/pdf2img-paperclip-processor/version.rb
|
46
|
+
- pdf2img-paperclip-processor.gemspec
|
47
|
+
homepage: https://github.com/sujeev/Pdf2img
|
48
|
+
licenses: []
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.5.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Converts uploaded pdf to img
|
70
|
+
test_files: []
|