Open Source Ruby API to Create Word DOCX Documents

A Leading Free Ruby Library That Enables Software Developers to Create Word Documents, Add & Customize Tables, Insert Images, Apply Line Break and Text Formatting to Word Documents inside Ruby Apps.

What is PureDocx Library?

PureDocx is a powerful, open source Ruby library that simplifies the process of creation Microsoft Word .docx files inside Ruby applications. It provides a straightforward and intuitive way to generate Word documents programmatically, making it an excellent tool for software developers who need to create reports, invoices, or any other type of document on the fly. At its core, PureDocx allows you to define a document with a header and content. The header will appear on every page of the document, while the content will flow from one page to the next.

The PureDocx library is a fantastic library for any Ruby developer who needs to generate .docx files. Its simple API, flexible features, and open-source nature make it a top choice for a wide range of applications. Its clean and intuitive API allows developers to create complex documents with minimal code. With support for text, images, and tables, PureDocx gives you the flexibility to create a wide variety of documents. Its elegant DSL, support for headers/footers, images, and tables, and compatibility with popular office suites makes it a great choice for report generation and document automation.

Previous Next

Getting Started with PureDocx

The recommend way to install PureDocx is using RubyGems. Please use the following command for a smooth installation.

Install Docs via RubyGems


$ gem 'puredocx

// Or install it yourself as

$ gem install PureDocx

You can also download it directly from GitHub.

Word Documents Creation via Ruby

The open source PureDocx library has included complete support for creating and managing Word documents inside Ruby applications. At its core, PureDocx allows you to define a document with a header and content. The header will appear on every page of the document, while the content will flow from one page to the next. Software developers can apply various types of formatting, add tables and images and insert content with ease. Here's a basic example that shows how to create a word document using Ruby commands.

How to Create a Word Document inside Ruby Apps?

PureDocx.create('my_document.docx') do |doc|
  doc.header([
    doc.text('My Awesome Document Header')
  ])
  doc.content([
    doc.text('This is the main content of my document.')
  ])
end

Apply Text Formatting inside Documents via Ruby

The PureDocx Ruby library makes it easy for software developers to create and apply various types of styles and formatting to content inside Word documents. The library provides a range of options for formatting text, including bold or italic styles to text, setting the font size, aligning the text to the left, center, or right and many more. Here is a simple example that demonstrates, how software developers can apply different formatting options to text inside a Word document.

How to Apply Text Formatting inside a Word Documents via Ruby API?

Create & Customize Tables in Word Files via Ruby

Tables are a powerful way to organize and display data inside your documents. The PureDocx library makes it easy to create tables with custom styling inside Word documents via Ruby library. Software developers can also customize the appearance of their tables with a variety of options, such as setting the width of the table, defining the top and left padding for the table cells, specifying which sides of the table should not have a border, setting the width of individual columns, specifying which sides of the table should have a bold border and so on. The following example shows how can you create a simple table inside Ruby applications.

How to Create a Simple Table inside Ruby Apps?


table_data = [
  [{ column: [doc.text('Column 1')] }, { column: [doc.text('Column 2')] }],
  [{ column: [doc.text('Row 2, Col 1')] }, { column: [doc.text('Row 2, Col 2')] }]
]
doc.table(table_data)

How to Customize Table with Custom Styling via Ruby API?


table_options = {
  table_width: 8000,
  paddings: { top: 100, left: 100 },
  sides_without_border: [:top, :bottom],
  bold_sides: [:left, :right],
  col_width: [4000, 4000]
}
doc.table(table_data, table_options)

Apply Pagination, Line Break & New Pages via Ruby

The open source PureDocx library has provided various options for handling working documents inside Ruby application. The library allows you to add page numbers to your documents with ease. You can specify the position of the page numbers in the footer as 'left', 'right', or 'center'. You can use the brake method to add a line break and the new_page method to start a new page. The following example shows how to apply Line break and add new pages inside Word documents.

How to Apply Line Breaks and Add New Pages via Ruby?


doc.text('This is the first line.')
doc.brake
doc.text('This is the second line.')
doc.new_page
doc.text('This is on a new page.')