-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
67 lines (48 loc) · 2.66 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
PdfConverter
============
PdfConverter makes converting PDF files to image formats simple. It supports different backend processors (currently ImageMagick and netpbm). Netpbm support is a 2 step process but it's faster than ImageMagick.
PdfConverter works on attachment based models. It was designed to work with attachment_fu, but it can be used with any model that has a method that returns the full path to the PDF file. See the examples below.
Options can be passed to the command line of the backend processors. For ImageMagick, a string can be passed in as a hash value to :processor_options. For netpbm, an array of 2 strings must be passed in, since it's a 2 step process. The first element of the array will be used for pdftoppm then the 2nd will be passed into the pnmto<format> stage.
PdfConverter supports any image format that the backend processor supports. Simply call convert_to_<format> on an instance of your model.
Setup the model:
class DummyFile < ActiveRecord::Base
has_attachment :storage => :file_system
converts_pdf
end
To convert the pdf file to some other format:
d = DummyFile.find(:first)
d.convert_to_png
d.convert_to_jpeg
Software Requirements
=====================
Your software requirements depends on which backend processor that you choose to use. For imagemagick, ImageMagick must be installed and the 'convert' binary must be in your path. For netpbm, Xpdf and netpbm must be installed (pdftoppm and pnmto<format> must exist in your path).
Examples
========
To use the plugin with the default imagemagick processor and attachment_fu, just add converts_pdf to the model class:
class DummyFile < ActiveRecord::Base
has_attachment :storage => :file_system
converts_pdf
end
Not using attachment_fu? You can specify the method used to retrieve the full path to the PDF filename to convert:
class DummyFile < ActiveRecord::Base
converts_pdf :filename_method => :your_method_to_get_full_path_to_file
end
With a different backend processor:
class DummyFile < ActiveRecord::Base
has_attachment :storage => :file_system
converts_pdf :processor => 'netpbm'
end
Passing in command line options to the backend processor:
class DummyFile < ActiveRecord::Base
has_attachment :storage => :file_system
converts_pdf :processor_options => '-density 150'
end
Advanced Examples
=================
Passing in command line options to the backend processor (for 2 step processors like netpbm):
(The first element of the array is passed to pdftoppm)
class DummyFile < ActiveRecord::Base
has_attachment :storage => :file_system
converts_pdf :processor => 'netpbm', :processor_options => ['-q', '-v']
end
Copyright (c) 2008 Jason Stewart, released under the MIT license