0.0
The project is in a healthy, maintained state
A gem to convert word file(.docx) to pdf can be used for invoicing and other template
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 0.8.0
 Project Readme

DOCX to PDF Converter with Placeholder Replacement

This Ruby utility replaces placeholders in a .docx file with provided values and converts the result to a PDF using LibreOffice.

Features

  • Replace placeholders like {{name}}, {{date}}, etc. in a Word document.
  • Generate a filled PDF version of the document.
  • Temporary files are managed in the system temp directory.
  • Safe file generation using SecureRandom.

Requirements

  • Ruby (>= 2.5)
  • LibreOffice installed and available as soffice in the system path
  • Gems:
    • docx
    • securerandom

Install:

Add the following line to your application's Gemfile:

gem 'docx'
gem 'word_to_pdf'

And then execute:

bundle install

Or install it yourself as:

gem install docx

Convert

first create a template sample word file(.docx)

This is test file
Name: {{name}}
date of birth: {{date}}

or \

You can download a sample .docx template to test this gem:

👉 Click here to get the sample file

require 'word_to_pdf'

WordToPdf.convert(
  '/path/to/template.docx',
  '/path/to/output.pdf',
  {
    first_name: 'Test',
    last_name: 'Example'
  }
)

You will have the downloaded file on the /path/to/output.pdf location