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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cefbb3b1de62605e67622ae97622315ce0f11ff70c89de286d2b5570b1394f2c
4
- data.tar.gz: 7f0cceb62fbf58319ae1e31c43ad839bb944236cf0780cc0df57ec45eba86515
3
+ metadata.gz: 92cf2bc0f6a256e29582a267c1615c50590e0132b71b849b266f3d733c57a219
4
+ data.tar.gz: 5e4f2d2f377de3770d7962ec974cf7e99c7f8d6300fd68c0b8572d502a785ba3
5
5
  SHA512:
6
- metadata.gz: c6b451533a04fae54f07f2f87ecbd3b1ee4080e7ac60ecb4b52fd168f4512365c66227a11ed0da35356f0c4d4483f97b70ed446799bbf125305ae9667b70e0cb
7
- data.tar.gz: 9889b2f5821200026a27e667eaeb74ac4a0fb7333f4dd9db4e0c2e777f55db369f4a2fcb516cae57c8babfd109865df2314bfd5385409dbfba3a2bff22c79e05
6
+ metadata.gz: 64db84510844d95a20f6f5a4106dbbf626278ec4f1f1a2ad5fb6ac073607b382a3fb79bca68f193795049c77f4586416a85be7801fafba1ab53d82707e60b98f
7
+ data.tar.gz: c07abc0293bf8e7c0d546893dcd956e6b535c79aade80bfdb9d4bff68074a7d05b7d94fbd1f7b10216bf9767f105f4b6cfafe625f369cd0327cf077aba5e6b87
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WordToPdf
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
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
- def self.convert(_input_docx_file_path, _output_pdf_file_path, values_hash = {})
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
- doc = Docx::Document.open(_input_docx_file_path)
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
- system("soffice --headless --convert-to pdf #{filled_docx} --outdir #{temp_dir}")
24
-
25
- generated_pdf = filled_docx.gsub('.docx', '.pdf')
26
- File.rename(generated_pdf, _output_pdf_file_path)
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
- puts "PDF generated: #{_output_pdf_file_path}"
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.2
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-06 00:00:00.000000000 Z
10
+ date: 2025-04-07 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: docx