word_to_pdf 0.0.2 → 0.0.3
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 +4 -4
- data/lib/word_to_pdf/version.rb +1 -1
- data/lib/word_to_pdf.rb +26 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92cf2bc0f6a256e29582a267c1615c50590e0132b71b849b266f3d733c57a219
|
4
|
+
data.tar.gz: 5e4f2d2f377de3770d7962ec974cf7e99c7f8d6300fd68c0b8572d502a785ba3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64db84510844d95a20f6f5a4106dbbf626278ec4f1f1a2ad5fb6ac073607b382a3fb79bca68f193795049c77f4586416a85be7801fafba1ab53d82707e60b98f
|
7
|
+
data.tar.gz: c07abc0293bf8e7c0d546893dcd956e6b535c79aade80bfdb9d4bff68074a7d05b7d94fbd1f7b10216bf9767f105f4b6cfafe625f369cd0327cf077aba5e6b87
|
data/lib/word_to_pdf/version.rb
CHANGED
data/lib/word_to_pdf.rb
CHANGED
@@ -3,13 +3,29 @@ require 'securerandom'
|
|
3
3
|
require_relative 'word_to_pdf/install_check'
|
4
4
|
|
5
5
|
module WordToPdf
|
6
|
-
|
6
|
+
|
7
|
+
def self.convert(input_docx_file_path, output_pdf_file_path, values_hash = {})
|
8
|
+
# Checking if the soffice is avaliable or not
|
7
9
|
InstallCheck.ensure_office_installed!
|
8
10
|
|
11
|
+
temp_dir = create_temp_dir
|
12
|
+
filled_docx = fill_template(input_docx_file_path, values_hash, temp_dir)
|
13
|
+
pdf_path = convert_to_pdf(filled_docx, temp_dir)
|
14
|
+
|
15
|
+
move_pdf_to_destination(pdf_path, output_pdf_file_path)
|
16
|
+
|
17
|
+
puts "PDF generated: #{output_pdf_file_path}"
|
18
|
+
end
|
19
|
+
|
20
|
+
# creating empty tmp directory
|
21
|
+
def self.create_temp_dir
|
9
22
|
temp_dir = "/tmp/#{SecureRandom.hex(8)}"
|
10
23
|
Dir.mkdir(temp_dir) unless File.exist?(temp_dir)
|
24
|
+
temp_dir
|
25
|
+
end
|
11
26
|
|
12
|
-
|
27
|
+
def self.fill_template(input_docx_file_path, values_hash, temp_dir)
|
28
|
+
doc = Docx::Document.open(input_docx_file_path)
|
13
29
|
|
14
30
|
doc.paragraphs.each do |p|
|
15
31
|
values_hash.each do |key, value|
|
@@ -19,12 +35,15 @@ module WordToPdf
|
|
19
35
|
|
20
36
|
filled_docx = "#{temp_dir}/filled_template.docx"
|
21
37
|
doc.save(filled_docx)
|
38
|
+
filled_docx
|
39
|
+
end
|
22
40
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
41
|
+
def self.convert_to_pdf(filled_docx_path, output_dir)
|
42
|
+
system("soffice --headless --convert-to pdf #{filled_docx_path} --outdir #{output_dir}")
|
43
|
+
filled_docx_path.gsub('.docx', '.pdf')
|
44
|
+
end
|
27
45
|
|
28
|
-
|
46
|
+
def self.move_pdf_to_destination(temp_pdf_path, final_output_path)
|
47
|
+
File.rename(temp_pdf_path, final_output_path)
|
29
48
|
end
|
30
49
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: word_to_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ajit Dhanje
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
10
|
+
date: 2025-04-07 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: docx
|