documents_with_footer_to_pdf 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9ef90d1e3aa78916390c2f089e7855e6474fcc8ac1f10893299edb327cbbea1e
4
+ data.tar.gz: d3959bc4882aa3a5c22051192611c844e9be756414354e83b9344d402c3e98c1
5
+ SHA512:
6
+ metadata.gz: '049fe4f75a121a7e6c27e9570399e3eb65f980b2713d7dabfad80b1805f7dfdbfc93217fbbd4bc70ffba99a551bbf0bb937c29f8033b4639387450545baba7f0'
7
+ data.tar.gz: b0127c2223da281d920ef64bca0c8161ba5eea40d6889e8cb7a058f7828bd870f60cbf95c68d653b6fc0011b106da330536c9e4e3467a23ad55e23d684c29f01
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /test/*/
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-06-21
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hello@13plus4.com . All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in documents_with_footer_to_pdf.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.7"
11
+
12
+
13
+ gem 'local_path_builder', "~> 0.1.1"
14
+ gem 'fileutils'
15
+ gem 'combine_pdf', "~> 1.0.21"
16
+ gem 'prawn', "~> 2.4.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ documents_with_footer_to_pdf (0.1.2)
5
+ combine_pdf (~> 1.0.21)
6
+ fileutils
7
+ local_path_builder (~> 0.1.1)
8
+ prawn (~> 2.4.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ ast (2.4.2)
14
+ combine_pdf (1.0.21)
15
+ ruby-rc4 (>= 0.1.5)
16
+ fileutils (1.5.0)
17
+ local_path_builder (0.1.1)
18
+ fileutils (~> 1.5.0)
19
+ parallel (1.20.1)
20
+ parser (3.0.1.1)
21
+ ast (~> 2.4.1)
22
+ pdf-core (0.9.0)
23
+ prawn (2.4.0)
24
+ pdf-core (~> 0.9.0)
25
+ ttfunk (~> 1.7)
26
+ rainbow (3.0.0)
27
+ rake (13.0.3)
28
+ regexp_parser (2.1.1)
29
+ rexml (3.2.5)
30
+ rubocop (1.17.0)
31
+ parallel (~> 1.10)
32
+ parser (>= 3.0.0.0)
33
+ rainbow (>= 2.2.2, < 4.0)
34
+ regexp_parser (>= 1.8, < 3.0)
35
+ rexml
36
+ rubocop-ast (>= 1.7.0, < 2.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 3.0)
39
+ rubocop-ast (1.7.0)
40
+ parser (>= 3.0.1.1)
41
+ ruby-progressbar (1.11.0)
42
+ ruby-rc4 (0.1.5)
43
+ ttfunk (1.7.0)
44
+ unicode-display_width (2.0.0)
45
+
46
+ PLATFORMS
47
+ x86_64-darwin-20
48
+
49
+ DEPENDENCIES
50
+ combine_pdf (~> 1.0.21)
51
+ documents_with_footer_to_pdf!
52
+ fileutils
53
+ local_path_builder (~> 0.1.1)
54
+ prawn (~> 2.4.0)
55
+ rake (~> 13.0)
56
+ rubocop (~> 1.7)
57
+
58
+ BUNDLED WITH
59
+ 2.2.19
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 a6b8
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,304 @@
1
+ <a href="#table-of-contents">
2
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/documents-with-footer-to-pdf.svg" height="55px" name="Documents with Footer to Pdf for Ruby" alt="# Documents with Footer to .pdf for Ruby">
3
+ </a>
4
+
5
+ Add a footer to each document and create a single .pdf file all in one command.
6
+ <br>
7
+ <br>
8
+ <br>
9
+ <a href="#table-of-contents">
10
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/examples.svg" height="55px" name="examples" alt="Examples">
11
+ </a>
12
+
13
+ ### Example 1
14
+
15
+ **Filename**:
16
+ ```5--HEADING--Subheadline.png```
17
+
18
+ ```ruby
19
+ {
20
+ footer__table__left__top__text: '<<--ENUMERATOR_INTEGER-->>. <<--HEADLINE-->>',
21
+ footer__table__left__bottom__text: '<<--TIMESTAMP-->>',
22
+ footer__table__center__top__text: '',
23
+ footer__table__center__bottom__text: '',
24
+ footer__table__right__top__text: '<<--PAGE_CURRENT-->>',
25
+ footer__table__right__bottom__text: '',
26
+ }
27
+ ```
28
+
29
+ **Output**
30
+
31
+ <img src="https://github.com/a6b8/a6b8/blob/main/docs/documents-with-footer-to-pdf/readme/examples/a.jpg?raw=true">
32
+
33
+
34
+ ### Example 2
35
+
36
+ **Filename**:
37
+ ```5--HEADING--Subheadline.png```
38
+
39
+ ```ruby
40
+ {
41
+ footer__table__left__top__text: '<<--ENUMERATOR_ROMAN-->>. <<--HEADLINE-->>',
42
+ footer__table__left__bottom__text: '<<--SUBHEADING-->>',
43
+ footer__table__center__top__text: 'Application',
44
+ footer__table__center__bottom__text: 'John Doe',
45
+ footer__table__right__top__text: '<<--TIMESTAMP-->>',
46
+ footer__table__right__bottom__text: '<<--PAGE_CURRENT-->> of <<--PAGE_TOTAL-->>',
47
+ selectors__timestamp__strf: '%A, %e %B %Y'
48
+ }
49
+ ```
50
+ **Output**
51
+
52
+ <img src="https://github.com/a6b8/a6b8/blob/main/docs/documents-with-footer-to-pdf/readme/examples/b.jpg?raw=true">
53
+
54
+
55
+ ### Example 3
56
+
57
+ **Filename**:
58
+ ```5--HEADING--Subheadline.png```
59
+
60
+ ```ruby
61
+ {
62
+ footer__table__left__top__text: '<<--TIMESTAMP-->>',
63
+ footer__table__left__bottom__text: '',
64
+ footer__table__center__top__text: '<<--ENUMERATOR_CHAR-->> <<--HEADLINE-->>',
65
+ footer__table__center__bottom__text: '',
66
+ footer__table__right__top__text: '<<--PAGE_CURRENT-->>',
67
+ footer__table__right__bottom__text: '',
68
+ }
69
+ ```
70
+
71
+ <img src="https://github.com/a6b8/a6b8/blob/main/docs/documents-with-footer-to-pdf/readme/examples/c.jpg?raw=true">
72
+
73
+ <br>
74
+ <br>
75
+ <a href="#table-of-contents">
76
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/table-of-contents.svg" height="55px" name="table-of-contents" alt="Table of Contents">
77
+ </a>
78
+ <br>
79
+
80
+ 1. [Quickstart](#quickstart)<br>
81
+ 2. [Parameters](#parameters)<br>
82
+ 3. [Options](#options)<br>
83
+ 4. [Selectors](#selectors)<br>
84
+ 5. [Contributing](#contributing)<br>
85
+ 6. [Limitations](#limitations)<br>
86
+ 7. [Credits](#credits)<br>
87
+ 8. [License](#license)<br>
88
+ 9. [Code of Conduct](#code-of-conduct)<br>
89
+ 10. [Support my Work](#support-my-work)<br>
90
+
91
+ <br>
92
+ <br>
93
+ <a href="#table-of-contents">
94
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/quickstart.svg" height="55px" name="quickstart" alt="Quickstart">
95
+ </a>
96
+
97
+ ```ruby
98
+ require 'documents_with_footer_to_pdf'
99
+
100
+
101
+ your_folder = './1-test/'
102
+
103
+ DocumentsWithFooterToPdf.generate(
104
+ your_folder,
105
+ :short,
106
+ {}
107
+ )
108
+ ```
109
+ <br>
110
+ <br>
111
+ <a href="#table-of-contents">
112
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/setup.svg" height="55px" name="setup" alt="Setup">
113
+ </a>
114
+
115
+ Add this line to your application's Gemfile:
116
+
117
+ ```ruby
118
+ gem 'documents_with_footer_to_pdf'
119
+ ```
120
+
121
+ And then execute:
122
+
123
+ $ bundle install
124
+
125
+ Or install it yourself as:
126
+
127
+ $ gem install documents_with_footer_to_pdf
128
+
129
+
130
+ On Rubygems:
131
+ - Gem: https://rubygems.org/gems/test
132
+ - Profile: https://rubygems.org/profiles/a6b8
133
+
134
+ <br>
135
+ <br>
136
+ <a href="#table-of-contents">
137
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/methods.svg" height="55px" name="methods" alt="Methods">
138
+ </a>
139
+
140
+ ### .get_options()
141
+ ```ruby
142
+ require 'documents_with_footer_to_pdf'
143
+
144
+ hash = DocumentsWithFooterToPdf.get_options()
145
+ # => { path:
146
+ ```
147
+
148
+
149
+ ### .generate()
150
+ ```ruby
151
+ require 'documents_with_footer_to_pdf'
152
+
153
+ hash = DocumentsWithFooterToPdf.generate(
154
+ folder,
155
+ console_mode,
156
+ options
157
+ )
158
+ ```
159
+
160
+ **Input**
161
+ | **Type** | **Required** | **Description** | **Example** | **Description** |
162
+ |------:|:------|:------|:------|:------|
163
+ | **headline** | ```String``` | Yes | "./test/" | Define path to folder |
164
+ | **console mode** | ```Symbol``` | Yes | ```:hash``` | Set test console output mode. Use ```:silent```, ```:short```, or ```:detail``` |
165
+ | **options** | ```'Hash'``` | No | ```{}``` | Change defaut options, please refer: <a href="#options">Options</a> for more info |
166
+
167
+ **Return**<br>
168
+ Boolean
169
+ <br>
170
+ <br>
171
+ <br>
172
+ <a href="#table-of-contents">
173
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/options.svg" height="55px" name="options" alt="Options">
174
+ </a>
175
+
176
+ ### Path
177
+ | Nr | Name | Key | Default | Type | Description |
178
+ | :-- | :-- | :-- | :-- | :-- | :-- |
179
+ | A.1. | Children Tmp Name |:path__children__tmp__name | `"tmp-{{SALT}}"` | String | Change temporary folder name, {{SALT}} will replaced with current unix timestamp |
180
+ | A.2. | Children Pdf_combined Name |:path__children__pdf_combined__name | `"0-result-{{SALT}}"` | String | Change result folder name, {{SALT}} will replaced with current unix timestamp |
181
+
182
+
183
+ ### Footer
184
+ | Nr | Name | Key | Default | Type | Description |
185
+ | :-- | :-- | :-- | :-- | :-- | :-- |
186
+ | B.1. | Position Top |:footer__position__top | `[0, 20]` | Array | Set footer position top. |
187
+ | B.2. | Position Bottom |:footer__position__bottom | `[0, 10]` | Array | Set footer position bottom. |
188
+ | B.3. | Table Left Top Text |:footer__table__left__top__text | `"<<--FILENAME-->>"` | String | Set text in field left-top |
189
+ | B.4. | Table Left Bottom Text |:footer__table__left__bottom__text | `""` | String | String | Set text in field left-bottom |
190
+ | B.5. | Table Center Top Text |:footer__table__center__top__text | `""` | String | String | Set text in field center-top |
191
+ | B.6. | Table Center Bottom Text |:footer__table__center__bottom__text | `""` | String | String | Set text in field center-bottom |
192
+ | B.7. | Table Right Top Text |:footer__table__right__top__text | `"<<--TIMESTAMP-->>"` | String | String | Set text in field right-top |
193
+ | B.8. | Table Right Bottom Text |:footer__table__right__bottom__text | `"<<--PAGE_CURRENT-->> from <<--PAGE_TOTAL-->>"` | String | String | Set text in field right-bottom |
194
+
195
+
196
+ ### Selectors
197
+ | Nr | Name | Key | Default | Type | Description |
198
+ | :-- | :-- | :-- | :-- | :-- | :-- |
199
+ | C.1. | Timestamp Gsub |:selectors__timestamp__gsub | `"<<--TIMESTAMP-->>"` | String | Change marker for timestamp. |
200
+ | C.2. | Timestamp Strf |:selectors__timestamp__strf | `"%d.%m.%Y"` | String | Change format of date and time |
201
+ | C.3. | Page_current Gsub |:selectors__page_current__gsub | `"<<--PAGE_CURRENT-->>"` | String | Change marker for current page. |
202
+ | C.4. | Page_total Gsub |:selectors__page_total__gsub | `"<<--PAGE_TOTAL-->>"` | String | Change marker for total page size |
203
+ | C.5. | Enumerator_original Gsub |:selectors__enumerator_original__gsub | `"<<--ENUMERATOR_ORIGINAL-->>"` | String | Change marker for original enumeration |
204
+ | C.6. | Enumerator_integer Gsub |:selectors__enumerator_integer__gsub | `"<<--ENUMERATOR_INTEGER-->>"` | String | Change marker for integer enumeration |
205
+ | C.7. | Enumerator_char Gsub |:selectors__enumerator_char__gsub | `"<<--ENUMERATOR_CHAR-->>"` | String | Change marker for char enumeration |
206
+ | C.8. | Enumerator_roman Gsub |:selectors__enumerator_roman__gsub | `"<<--ENUMERATOR_ROMAN-->>"` | String | Change marker for roman letters enumeration |
207
+ | C.9. | Filename Gsub |:selectors__filename__gsub | `"<<--FILENAME-->>"` | String | Change marker for filename |
208
+ | C.10. | Path Gsub |:selectors__path__gsub | `"<<--PATH-->>"` | String | Change marker for full path |
209
+ | C.11. | Heading Gsub |:selectors__heading__gsub | `"<<--HEADLINE-->>"` | String | Change marker for headline |
210
+ | C.12. | Subheading Gsub |:selectors__subheading__gsub | `"<<--SUBHEADING-->>"` | String | Change marker for sub headline |
211
+
212
+ More Information on ```strf``` format: https://apidock.com/ruby/DateTime/strftime
213
+
214
+ ### Params
215
+ | Nr | Name | Key | Default | Type | Description |
216
+ | :-- | :-- | :-- | :-- | :-- | :-- |
217
+ | D.1. | Footer Font_size |:params__footer__font_size | `9` | Integer | Set footer font size |
218
+ | D.2. | Document Width |:params__document__width | `500` | Integer | Set document width |
219
+ | D.3. | Image Density |:params__image__density | `300` | Integer | Set image density |
220
+ | D.4. | Search Subfolders |:params__search__subfolders | `false` | Boolean | Set if subfolders should be included in search |
221
+ | D.5. | Search Suffixs |:params__search__suffixs | `["jpg", "png", "pdf"]` | Array | Types of suffixes which are included (Supported jpg, png, pdf) |
222
+ | D.6. | Console Length |:params__console__length | `50` | Integer | Change length of console output |
223
+ </a>
224
+ <br>
225
+ <br>
226
+ <a href="#table-of-contents">
227
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/selectors.svg" height="55px" name="selectors" alt="Selectors">
228
+ </a>
229
+
230
+ Filename: ```C--HEADING--Subheadline.png```
231
+
232
+ > Use double hyphens '--' as limiter
233
+
234
+ | Selector | Example | Description |
235
+ | :--- | :--- | :--- |
236
+ | ```"<<--TIMESTAMP-->>"``` | 24.05.2021 | Show current Timestamp, to change for format use option: :selectors__timestamp__strf |
237
+ | ```"<<--PAGE_CURRENT-->>"``` | ```1``` | Show current Page |
238
+ | ```"<<--PAGE_TOTAL-->>"``` | ```3``` | Show total Page size |
239
+ | ```"<<--ENUMERATOR_ORIGINAL-->>"``` | ```"C"``` | Show original Enumerator |
240
+ | ```"<<--ENUMERATOR_INTEGER-->>"``` | ```3``` | Show Enumerator as Integer |
241
+ | ```"<<--ENUMERATOR_CHAR-->>"``` | ```"C"``` | Show Enumerator as Char |
242
+ | ```"<<--ENUMERATOR_ROMAN-->>"``` | ```"III"``` | Show Enumerator in Roman Letters |
243
+ | ```"<<--FILENAME-->>"``` | ```"C--HEADING--Subheadline.png"``` | Show filename |
244
+ | ```"<<--PATH-->>"``` | ```"../C--HEADING--Subheadline"``` | Show file path|
245
+ | ```"<<--HEADLINE-->>"``` | ```"HEADING"``` | Show Headline |
246
+ | ```"<<--SUBHEADING-->>"``` | ```"Subheading"``` | Show Subheading |
247
+
248
+ <br>
249
+ <br>
250
+ <a href="#table-of-contents">
251
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/contributing.svg" height="55px" name="contributing" alt="Contributing">
252
+ </a>
253
+
254
+ Bug reports and pull requests are welcome on GitHub at https://github.com/a6b8/documents-with-footer-to-pdf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/a6b8/documents-with-footer-to-pdf/blob/master/CODE_OF_CONDUCT.md).
255
+ <br>
256
+ <br>
257
+ <br>
258
+ <a href="#table-of-contents">
259
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/limitations.svg" height="55px" name="limitations" alt="Limitations">
260
+ </a>
261
+ - Made for local usage
262
+ - Some pdf fonts are not supported.
263
+ <br>
264
+ <br>
265
+
266
+ <a href="#table-of-contents">
267
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/credits.svg" height="55px" name="credits" alt="Credits">
268
+ </a>
269
+
270
+ This gem depend on following gems:
271
+ - **local_path_builder** <br>
272
+ https://github.com/a6b8/local-path-builder-for-ruby <br>
273
+ - **FileUtils** <br>
274
+ https://ruby-doc.org/stdlib-2.4.1/libdoc/fileutils/rdoc/FileUtils.html <br>
275
+ - **combine_pdf** <br>
276
+ https://github.com/boazsegev/combine_pdf <br>
277
+ - **prawn** <br>
278
+ https://github.com/prawnpdf/prawn <br>
279
+ - **image magick** <br>
280
+ https://imagemagick.org/script/convert.php
281
+ <br>
282
+ <br>
283
+
284
+ <a href="#table-of-contents">
285
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/license.svg" height="55px" name="license" alt="License">
286
+ </a>
287
+
288
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
289
+ <br>
290
+ <br>
291
+ <br>
292
+ <a href="#table-of-contents">
293
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/code-of-conduct.svg" height="55px" name="code-of-conduct" alt="Code of Conduct">
294
+ </a>
295
+
296
+ Everyone interacting in the documents-with-footer-to-pdf project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/a6b8/documents-with-footer-to-pdf/blob/master/CODE_OF_CONDUCT.md).
297
+ <br>
298
+ <br>
299
+ <br>
300
+ <a href="#table-of-contents">
301
+ <img href="#table-of-contents" src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/documents-with-footer-to-pdf/readme/headlines/support-my-work.svg" height="55px" name="support-my-work" alt="Support my Work">
302
+ </a>
303
+
304
+ Donate by [https://www.paypal.com](https://www.paypal.com/donate?hosted_button_id=XKYLQ9FBGC4RG)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "documents_with_footer_to_pdf"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/documents_with_footer_to_pdf/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "documents_with_footer_to_pdf"
7
+ spec.version = DocumentsWithFooterToPdf::VERSION
8
+ spec.authors = ["a6b8"]
9
+ spec.email = ["hello@13plus4.com"]
10
+
11
+ spec.summary = "Add a footer to each document and create a single .pdf file"
12
+ spec.description = "Add a footer to each document and create a single .pdf file all in one command."
13
+ spec.homepage = "https://github.com/a6b8/documents-with-footer-to-pdf"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.4.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/a6b8/documents-with-footer-to-pdf"
21
+ spec.metadata["changelog_uri"] = "https://raw.githubusercontent.com/a6b8/documents-with-footer-to-pdf/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ spec.add_dependency 'local_path_builder', "~> 0.1.1"
36
+ spec.add_dependency 'fileutils', "~> 1.5.0"
37
+ spec.add_dependency 'combine_pdf', "~> 1.0.21"
38
+ spec.add_dependency 'prawn', "~> 2.4.0"
39
+
40
+ # For more information and examples about making a new gem, checkout our
41
+ # guide at: https://bundler.io/guides/creating_gem.html
42
+ end
@@ -0,0 +1,560 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "documents_with_footer_to_pdf/version"
4
+ require 'local_path_builder'
5
+ require 'FileUtils'
6
+ require 'combine_pdf'
7
+ require 'prawn'
8
+ Prawn::Fonts::AFM.hide_m17n_warning = true
9
+
10
+ module DocumentsWithFooterToPdf
11
+ class Error < StandardError; end
12
+ # Your code goes here...
13
+
14
+ def self.get_options()
15
+ return {
16
+ path: {
17
+ root: nil,
18
+ name: '',
19
+ children: {
20
+ tmp: {
21
+ name: 'tmp-{{SALT}}',
22
+ children: {
23
+ jpg: {
24
+ name: '0-jpg'
25
+ },
26
+ pdf_single: {
27
+ name: '1-pdf-single--w-footer'
28
+ }
29
+ }
30
+ },
31
+ pdf_combined: {
32
+ name: '0-result-{{SALT}}',
33
+ files: {
34
+ result: {
35
+ name: '0-result-{{SALT}}.pdf'
36
+ }
37
+ }
38
+ }
39
+ }
40
+ },
41
+ footer: {
42
+ position: {
43
+ top: [ 0, 20 ],
44
+ bottom: [ 0, 10 ]
45
+ },
46
+ table: {
47
+ left: {
48
+ top: {
49
+ text: '<<--FILENAME-->>'
50
+ },
51
+ bottom: {
52
+ text: ''
53
+ }
54
+ },
55
+ center: {
56
+ top: {
57
+ text: ''
58
+ },
59
+ bottom: {
60
+ text: ''
61
+ }
62
+ },
63
+ right: {
64
+ top: {
65
+ text: '<<--TIMESTAMP-->>'
66
+ },
67
+ bottom: {
68
+ text: '<<--PAGE_CURRENT-->> from <<--PAGE_TOTAL-->>'
69
+ }
70
+ }
71
+ }
72
+ },
73
+ selectors: {
74
+ timestamp: {
75
+ gsub: '<<--TIMESTAMP-->>',
76
+ key: :timestamp,
77
+ strf: '%d.%m.%Y',
78
+ },
79
+ page_current: {
80
+ gsub: '<<--PAGE_CURRENT-->>',
81
+ key: :page__current
82
+ },
83
+ page_total: {
84
+ gsub: '<<--PAGE_TOTAL-->>',
85
+ key: :page__total
86
+ },
87
+ enumerator_original: {
88
+ gsub: '<<--ENUMERATOR_ORIGINAL-->>',
89
+ key: :enumerator__original
90
+ },
91
+ enumerator_integer: {
92
+ gsub: '<<--ENUMERATOR_INTEGER-->>',
93
+ key: :enumerator__integer
94
+ },
95
+ enumerator_char: {
96
+ gsub: '<<--ENUMERATOR_CHAR-->>',
97
+ key: :enumerator__char
98
+ },
99
+ enumerator_roman: {
100
+ gsub: '<<--ENUMERATOR_ROMAN-->>',
101
+ key: :enumerator__roman
102
+ },
103
+ filename: {
104
+ gsub: '<<--FILENAME-->>',
105
+ key: :filename
106
+ },
107
+ path: {
108
+ gsub: '<<--PATH-->>',
109
+ key: :path
110
+ },
111
+ heading: {
112
+ gsub: '<<--HEADLINE-->>',
113
+ key: :heading
114
+ },
115
+ subheading: {
116
+ gsub: '<<--SUBHEADING-->>',
117
+ key: :subheading
118
+ }
119
+ },
120
+ params: {
121
+ footer: {
122
+ font_size: 9
123
+ },
124
+ document: {
125
+ width: 500
126
+ },
127
+ image: {
128
+ density: 300
129
+ },
130
+ search: {
131
+ subfolders: false,
132
+ suffixs: [ 'jpg', 'png', 'pdf' ]
133
+ },
134
+ console: {
135
+ silent: nil,
136
+ mode: nil,
137
+ length: 50
138
+ }
139
+ }
140
+ }
141
+ end
142
+
143
+
144
+ def self.generate( folder, silent, options={} )
145
+
146
+ hash = Marshal.load( Marshal.dump( self.get_options() ) )
147
+ if self.validate_generate( folder, silent, options, hash )
148
+
149
+ hash[:path][:root] = folder
150
+ hash[:params][:console][:silent] = silent == :silent ? true : false
151
+ hash[:params][:console][:mode] = !hash[:params][:console][:silent] ? silent : ''
152
+ hash[:path] = LocalPathBuilder.generate( hash[:path], :silent, Time.now.to_i.to_s )
153
+ hash = self.options_update( options, hash, 'set_options' )
154
+
155
+ self.footer_image( hash )
156
+ prepares = self.footer_prepare( hash )
157
+ self.footer_generate( prepares, hash )
158
+ self.footer_merge( hash )
159
+ FileUtils.rm_rf( hash[:path][:children][:tmp][:full] )
160
+ end
161
+ end
162
+
163
+
164
+ private
165
+
166
+
167
+ def self.debug( obj )
168
+ return obj[:params][:console][:silent]
169
+ end
170
+
171
+
172
+ def self.options_update( vars, template, mode )
173
+ def self.str_difference( a, b )
174
+ a = a.to_s.downcase.split( '_' ).join( '' )
175
+ b = b.to_s.downcase.split( '_' ).join( '' )
176
+ longer = [ a.size, b.size ].max
177
+ same = a
178
+ .each_char
179
+ .zip( b.each_char )
180
+ .select { | a, b | a == b }
181
+ .size
182
+ ( longer - same ) / a.size.to_f
183
+ end
184
+
185
+
186
+ allow_list = [
187
+ :path__children__tmp__name,
188
+ :path__children__pdf_combined__name,
189
+ :footer__position__top,
190
+ :footer__position__bottom,
191
+ :footer__table__left__top__text,
192
+ :footer__table__left__bottom__text,
193
+ :footer__table__center__top__text,
194
+ :footer__table__center__bottom__text,
195
+ :footer__table__right__top__text,
196
+ :footer__table__right__bottom__text,
197
+ :selectors__timestamp__gsub,
198
+ :selectors__timestamp__strf,
199
+ :selectors__page_current__gsub,
200
+ :selectors__page_total__gsub,
201
+ :selectors__enumerator_original__gsub,
202
+ :selectors__enumerator_integer__gsub,
203
+ :selectors__enumerator_char__gsub,
204
+ :selectors__enumerator_roman__gsub,
205
+ :selectors__filename__gsub,
206
+ :selectors__path__gsub,
207
+ :selectors__heading__gsub,
208
+ :selectors__subheading__gsub,
209
+ :params__footer__font_size,
210
+ :params__document__width,
211
+ :params__image__density,
212
+ :params__search__subfolders,
213
+ :params__search__suffixs,
214
+ :params__console__length
215
+ ]
216
+
217
+ messages = []
218
+ _options = Marshal.load( Marshal.dump( template ) )
219
+
220
+ vars.keys.each do | key |
221
+ if allow_list.include?( key )
222
+
223
+ keys = key.to_s.split( '__' ).map { | a | a.to_sym }
224
+ case( keys.length )
225
+ when 1
226
+ _options[ keys[ 0 ] ] = vars[ key ]
227
+ when 2
228
+ _options[ keys[ 0 ] ][ keys[ 1 ] ] = vars[ key ]
229
+ when 3
230
+ _options[ keys[ 0 ] ][ keys[ 1 ] ][ keys[ 2 ] ] = vars[ key ]
231
+ when 4
232
+ _options[ keys[ 0 ] ][ keys[ 1 ] ][ keys[ 2 ] ][ keys[ 3 ] ] = vars[ key ]
233
+ when 5
234
+ _options[ keys[ 0 ] ][ keys[ 1 ] ][ keys[ 2 ] ][ keys[ 3 ] ][ keys[ 4 ] ] = vars[ key ]
235
+ when 6
236
+ _options[ keys[ 0 ] ][ keys[ 1 ] ][ keys[ 2 ] ][ keys[ 3 ] ][ keys[ 4 ] ][ keys[ 5 ] ] = vars[ key ]
237
+ end
238
+ else
239
+ nearest = allow_list
240
+ .map { | word | { score: self.str_difference( key, word ), word: word } }
241
+ .min_by { | item | item[:score] }
242
+
243
+ message = "\"#{key}\" is not a valid key, did you mean \"<--similar-->\"?"
244
+ message = message.gsub( '<--similar-->', nearest[:word].to_s )
245
+ messages.push( message )
246
+ end
247
+ end
248
+
249
+ result = nil
250
+ case mode
251
+ when 'check_options'
252
+ result = messages
253
+ when 'set_options'
254
+ result = _options
255
+ end
256
+
257
+ return result
258
+ end
259
+
260
+
261
+ def self.validate_generate( folder, silent, vars, template )
262
+ messages = {
263
+ folder: [],
264
+ silent: [],
265
+ options: [],
266
+ other: []
267
+ }
268
+
269
+ if folder.class.to_s.eql?( 'String' )
270
+ if File.directory?( folder )
271
+
272
+ else
273
+ messages[:folder].push( 'Is not a valid path or not exist.')
274
+ end
275
+ else
276
+ messages[:folder].push( 'Is not Type "String"')
277
+ end
278
+
279
+ if silent.class.to_s.eql?( 'Symbol' )
280
+ if [:silent, :short, :detail].include?( silent )
281
+
282
+ else
283
+ messages[:silent].push( 'Is not :silent, :short or :detail')
284
+ end
285
+ else
286
+ messages[:silent].push( 'Is not Type "Symbol"')
287
+ end
288
+
289
+ if vars.class.to_s.eql?( 'Hash' )
290
+ messages[:options] = self.options_update( vars, template, 'check_options' )
291
+ else
292
+ messages[:options].push( 'Is not Type "Hash".')
293
+ end
294
+
295
+ valid = messages.keys.map { | key | messages[ key ].length }.sum == 0
296
+
297
+ if !valid
298
+ puts 'Following errors occured:'
299
+ messages.keys.each do | key |
300
+ if messages[ key ].length != 0
301
+ puts " #{key[ 0, 1 ].upcase}#{key[ 1, key.length ]}"
302
+ messages[ key ].each do | m |
303
+ puts " - #{m}"
304
+ end
305
+ end
306
+ end
307
+ end
308
+ return valid
309
+ end
310
+
311
+
312
+ def self.footer_image( obj )
313
+ files = []
314
+
315
+ star = '*'
316
+ obj[:params][:search][:subfolders] ? star = '**/*' : ''
317
+ obj[:params][:search][:suffixs]
318
+ .each { | a | files += Dir[ "#{obj[:path][:full]}#{star}.#{a}" ].sort }
319
+
320
+ t = files
321
+ .map { | a | a.split( '.' ).last }
322
+ .inject( Hash.new( 0 ) ) { |total, e| total[e] += 1 ;total }
323
+ .map { | a | ".#{a[ 0 ]} #{a[ 1 ]}" }
324
+ .join(', ')
325
+
326
+ !self.debug( obj ) ? print( "1. \tFind Files (#{files.length} Total | #{t}):" ) : ''
327
+
328
+ files.each.with_index do | file, index |
329
+ a = obj[:params][:image][:density].to_s
330
+ b = obj[:path][:children][:tmp][:children][:jpg][:full]
331
+ c = File.basename( file ).split( '.' )[ 0..-2 ].join( '.' )
332
+ cmd = "convert -density #{a} -background white -alpha remove \"#{file}\" \"#{b}#{c}.jpg\""
333
+
334
+ out = IO.popen( cmd )
335
+ out.readlines
336
+
337
+ self.console_mode( file, index, obj )
338
+ end
339
+
340
+ !self.debug( obj ) ? puts : ''
341
+
342
+ return true
343
+ end
344
+
345
+
346
+ def self.footer_prepare( obj )
347
+ def self.roman_numerals( integer )
348
+ def self.next_lower_key( integer, values )
349
+ arabics = values.keys
350
+ next_lower_index = ( arabics.push( integer ).sort.index( integer ) ) - 1
351
+ arabics[next_lower_index]
352
+ end
353
+
354
+ values = {
355
+ 1 => 'I',
356
+ 4 => 'IV',
357
+ 5 => 'V',
358
+ 9 => 'IX',
359
+ 10 => 'X',
360
+ 40 => 'XL',
361
+ 50 => 'L',
362
+ 90 => 'XC',
363
+ 100 => 'C',
364
+ 400 => 'CD',
365
+ 500 => 'D',
366
+ 900 => 'CM',
367
+ 1000 => 'M'
368
+ }
369
+
370
+ roman = ''
371
+ while integer > 0
372
+ if values[ integer ]
373
+ roman += values[ integer ]
374
+ return roman
375
+ end
376
+
377
+ roman += values[ self.next_lower_key( integer, values ) ]
378
+ integer -= self.next_lower_key( integer, values )
379
+ end
380
+ end
381
+
382
+
383
+ def self.create_selectors( str, item, alpha )
384
+ if str.index( '--' ) == 1
385
+ item[:valid] = true
386
+ a = str.split( '--' )
387
+ item[:enumerator][:original] = a[ 0 ]
388
+ case a.length
389
+ when 2
390
+ item[:heading] = a[ 1 ]
391
+ when 3
392
+ item[:heading] = a[ 1 ]
393
+ item[:subheading] = a[ 2 ]
394
+ end
395
+
396
+ if /\A[-+]?[0-9]+\z/.match( item[:enumerator][:original] ).to_a.length != 0
397
+ item[:enumerator][:style] = :integer
398
+ item[:enumerator][:integer] = item[:enumerator][:original].to_i
399
+ item[:enumerator][:char] = alpha[ item[:enumerator][:integer]-1 ]
400
+ item[:enumerator][:roman] = self.roman_numerals( item[:enumerator][:integer] )
401
+ else
402
+ item[:enumerator][:style] = :char
403
+ item[:enumerator][:char] = item[:enumerator][:original].upcase
404
+ item[:enumerator][:integer] =alpha.index( item[:enumerator][:char] ) + 1
405
+ item[:enumerator][:roman] = self.roman_numerals( alpha.index( item[:enumerator][:char] ) + 1 )
406
+ end
407
+ else
408
+ item[:valid] = false
409
+ item[:heading] = str
410
+ end
411
+
412
+ return item
413
+ end
414
+
415
+ timestamp = Time.now.strftime( obj[:selectors][:timestamp][:strf] )
416
+ paths = Dir[ obj[:path][:children][:tmp][:children][:jpg][:full] + '*' ]
417
+ pages = []
418
+
419
+ alpha = ( 'A'.upto( 'Z' ) ).to_a
420
+ for i in 0..paths.length - 1
421
+ path = paths[ i ]
422
+
423
+ p = {
424
+ file: {
425
+ from: nil,
426
+ to: nil
427
+ },
428
+ selectors: {
429
+ valid: nil,
430
+ timestamp: nil,
431
+ heading: nil,
432
+ filename: nil,
433
+ path: nil,
434
+ subheading: nil,
435
+ enumerator: {
436
+ style: nil,
437
+ original: nil,
438
+ char: nil,
439
+ integer: nil,
440
+ roman: nil
441
+ },
442
+ page: {
443
+ current: nil,
444
+ total: nil
445
+ }
446
+ }
447
+ }
448
+
449
+ p[:file][:from] = path
450
+
451
+ name = File.basename( path ).split( '.' )[ 0..-2 ].join( '.' )
452
+ tmp = obj[:path][:children][:tmp][:children][:pdf_single][:full]
453
+ p[:file][:to] = "#{tmp}#{name}.pdf"
454
+
455
+ p[:selectors] = self.create_selectors( name, p[:selectors], alpha )
456
+ p[:selectors][:timestamp] = timestamp
457
+ p[:selectors][:filename] = path.split('/').last
458
+ p[:selectors][:path] = path
459
+ p[:selectors][:page][:current] = ( i + 1 ).to_s
460
+ p[:selectors][:page][:total] = paths.length.to_s
461
+ pages.push( p )
462
+ end
463
+
464
+ return pages
465
+ end
466
+
467
+
468
+ def self.footer_generate( prepares, obj )
469
+ !self.debug( obj ) ? print( "2.\tWrite Footer:" ) : ''
470
+
471
+ prepares.each.with_index do | prepare, index |
472
+ footer = Marshal.load( Marshal.dump( obj[:footer] ) )
473
+ footer[:table].keys.each do | align |
474
+ footer[:table][ align ].keys.each do | position |
475
+ sels = obj[:selectors].keys.map { | a | [ obj[:selectors][ a ][:gsub], obj[:selectors][ a ][:key] ] }
476
+ sels.each do | sel |
477
+ if footer[:table][ align ][ position ][:text].include? sel[ 0 ]
478
+ keys = sel[ 1 ].to_s.split( '__' ).map { | a | a.to_sym }
479
+ case keys.length
480
+ when 1
481
+ footer[:table][ align ][ position ][:text] = footer[:table][ align ][ position ][:text]
482
+ .gsub( sel[ 0 ], prepare[:selectors][ keys[ 0 ] ].to_s )
483
+ when 2
484
+ footer[:table][ align ][ position ][:text] = footer[:table][ align ][ position ][:text]
485
+ .gsub( sel[ 0 ], prepare[:selectors][ keys[ 0 ] ][ keys[ 1 ] ].to_s )
486
+ end
487
+ end
488
+ end
489
+ end
490
+ end
491
+
492
+ Prawn::Document.generate( prepare[:file][:to] ) do | pdf |
493
+ pdf.image(
494
+ prepare[:file][:from],
495
+ at: [ 0, pdf.bounds.top ],
496
+ width: obj[:params][:document][:width]
497
+ )
498
+
499
+ footer[:table].keys.each do | align |
500
+ footer[:table][ align ].keys.each do | position |
501
+ pdf.text_box(
502
+ footer[:table][ align ][ position ][:text],
503
+ size: obj[:params][:footer][:font_size],
504
+ align: align,
505
+ at: footer[:position][ position ],
506
+ )
507
+ end
508
+ end
509
+ end
510
+
511
+ self.console_mode( prepare[:file][:from], index, obj )
512
+ end
513
+
514
+ !self.debug( obj ) ? puts : ''
515
+
516
+ return true
517
+ end
518
+
519
+
520
+ def self.footer_merge( obj )
521
+ !self.debug( obj ) ? puts( "3.\tMerge" ) : ''
522
+
523
+ files = Dir[ obj[:path][:children][:tmp][:children][:pdf_single][:full] + '*.pdf' ].sort
524
+
525
+ pdf = CombinePDF.new
526
+ files.each do | file |
527
+ pdf << CombinePDF.load( file )
528
+ end
529
+
530
+ p = obj[:path][:children][:pdf_combined][:files][:result][:full]
531
+ pdf.save( p )
532
+
533
+ return true
534
+ end
535
+
536
+
537
+ def self.console_mode( file, index, obj )
538
+ if !self.debug( obj )
539
+ case obj[:params][:console][:mode]
540
+ when :short
541
+ index%obj[:params][:console][:length] == 0 ? print( "\n\t" ) : ''
542
+ print( '.' )
543
+ when :detail
544
+ puts ( "\t" )
545
+ p = ''
546
+ if file.length > obj[:params][:console][:length]
547
+ _start = obj[:params][:console][:length] / 5
548
+ _end = obj[:params][:console][:length] - _start
549
+ p += file[ 0, _start ]
550
+ p += '...'
551
+ p += file[ file.length - _end, file.length]
552
+ else
553
+ p = file
554
+ end
555
+ print( "\t- #{p}" )
556
+ end
557
+ else
558
+ end
559
+ end
560
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocumentsWithFooterToPdf
4
+ VERSION = "0.1.2"
5
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: documents_with_footer_to_pdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - a6b8
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: local_path_builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: fileutils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: combine_pdf
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.21
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.21
55
+ - !ruby/object:Gem::Dependency
56
+ name: prawn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.4.0
69
+ description: Add a footer to each document and create a single .pdf file all in one
70
+ command.
71
+ email:
72
+ - hello@13plus4.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - CHANGELOG.md
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - documents_with_footer_to_pdf.gemspec
89
+ - lib/documents_with_footer_to_pdf.rb
90
+ - lib/documents_with_footer_to_pdf/version.rb
91
+ homepage: https://github.com/a6b8/documents-with-footer-to-pdf
92
+ licenses:
93
+ - MIT
94
+ metadata:
95
+ allowed_push_host: https://rubygems.org
96
+ homepage_uri: https://github.com/a6b8/documents-with-footer-to-pdf
97
+ source_code_uri: https://github.com/a6b8/documents-with-footer-to-pdf
98
+ changelog_uri: https://raw.githubusercontent.com/a6b8/documents-with-footer-to-pdf/main/CHANGELOG.md
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 2.4.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.2.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Add a footer to each document and create a single .pdf file
118
+ test_files: []