word_to_pdf 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 860662b571ac60a0c46ada13d542764d9b3566b8f80ac009976a14c60bfc59cd
4
+ data.tar.gz: 1ebb6dcea24f0043b36eed246ba2caddac5ae0c3977aa3724eb1b73379a91f2c
5
+ SHA512:
6
+ metadata.gz: 990b4cb31f39593acae400edb38af6d45e8cc8545939415638ff1555b94175e69214d1e76fb6c171a5e081924e01e4f511a557e12e376f4ef5acf4d801bbd1f4
7
+ data.tar.gz: 3e3cfe7e0e355444d38683a12c1502d5e6cb691b5216369861eff3b91dbb6eb351080e9855c13cbed55c519ddd1b53c3ab0946c41d06db6c58107111d920b008
@@ -0,0 +1,18 @@
1
+ # lib/docx_to_pdf/install_check.rb
2
+ module WordToPdf
3
+ class InstallCheck
4
+ def self.ensure_office_installed!
5
+ return if system('which soffice > /dev/null')
6
+
7
+ abort <<~MSG
8
+ ❌ LibreOffice is not installed or 'soffice' is not in PATH.
9
+ ➤ Please install it manually:
10
+ • On Ubuntu/Debian: sudo apt install libreoffice
11
+ • On macOS (with Homebrew): brew install --cask libreoffice
12
+ • On Windows: Download from https://www.libreoffice.org/download/
13
+
14
+ Then run this gem again.
15
+ MSG
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ require 'docx'
2
+ require 'securerandom'
3
+ require_relative 'word_to_pdf/install_check'
4
+
5
+ module WordToPdf
6
+ def self.convert(input_docx, output_pdf, values_hash)
7
+ InstallCheck.ensure_office_installed!
8
+
9
+ temp_dir = "/tmp/#{SecureRandom.hex(8)}"
10
+ Dir.mkdir(temp_dir) unless File.exist?(temp_dir)
11
+
12
+ doc = Docx::Document.open(input_docx)
13
+
14
+ doc.paragraphs.each do |p|
15
+ values_hash.each do |key, value|
16
+ p.text = p.text.gsub("{{#{key}}}", value.to_s)
17
+ end
18
+ end
19
+
20
+ filled_docx = "#{temp_dir}/filled_template.docx"
21
+ doc.save(filled_docx)
22
+
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)
27
+
28
+ puts "PDF generated: #{output_pdf}"
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: word_to_pdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ajit Dhanje
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-04-05 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: docx
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.8.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.8.0
26
+ executables: []
27
+ extensions: []
28
+ extra_rdoc_files: []
29
+ files:
30
+ - lib/word_to_pdf.rb
31
+ - lib/word_to_pdf/install_check.rb
32
+ licenses: []
33
+ metadata: {}
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.6.6
49
+ specification_version: 4
50
+ summary: A gem to convert word file formated to pdf can be used for invoicing and
51
+ other template
52
+ test_files: []