Site icon Wil Selby

Developing a Naval Correspondence Document Generator

This page details the progress I have made developing a web template to correctly format official military documents. The goal of this project was to eliminate time revising and editing errors in official correspondence by developing a web based interface that would allow a user to select the required fields and submit their content and immediately receive a properly formatted document for their review.

Why Was This needed?

In the Department of the Navy as well as the United States Marine Corps, official documents are required to follow strict formatting rules in order to ensure proper handling and dissemination. The official reference publication that describes these requirements is the Correspondence Manual (SECNAV Manual M-5216.5). The manual includes procedures for e-mail, faxes, memorandums, and business letters. The majority of official documents created and handled on a daily basis is the standard naval letter.

This format was developed when documents were written on typewriters requiring specific number of spaces between elements in the document. However, the formatting required isn’t easily recreated on modern day word processing software. This typically results in small errors which require extensive man-hours to edit and revise, often going through multiple drafts as it works it way from the originator, up the chain of command, and finally to its destination.

The pages above show the examples of standard naval format from the Correspondence Manual. This depicts the various fields that are available as well as the formatting with respect to spaces and hard returns. These examples were used as the reference when creating a base template.

Creating .docx Templates

The first step was to find a way to create dynamic .doc files. The standard naval letter has several required fields such as the date, “To,” and “From” fields. Other fields such as “Enclosures,” “References,” and “Via” are optional. Additionally, the body of the document can be multiple paragraphs and have various level of sub-paragraphs which have their own unique formatting requirements. I used the DocXFactory library as the foundation for this project. This library enables you to create a template .docx file containing all the fields your output file may need and control the formatting of each field. The fields and formatting can be used multiple times if you have multiple entries for a single field. I created the template file NavalLetterTemplate.docx based off of the Correspondence Manual and NavalLetter.cpp which has the .c++ functions to input strings into the .docx fields and saves the final .docx file. This code was initially tested to run via command line input. However, this needed to be adapted to a web-based interface for users to have access to it at the office.

Developing The Web Interface

Developing a web server and designing web pages was new to me so I decided to use the Tornado webserver library. This is a python based library that allows developers to quickly set-up robust webservers. I used Intorduction To Tornado to develop the server backend code and used HTML and CSS: Design and Build Websites to develop the HTML pages. The file runs the server and the files naval_letter.html and download.html are the web pages. The primary HTML file is a basic page which lets a user choose which fields are required for their specific file and enter the requisite text for those fields. It looks similar to the screenshot below.

Generating Python Wrappers for DocxFactory

Since the tornado libraries are written in Python but the DocxFactory functions are written in C++, I had to develop wrappers for the DocxFactory libraries and the functions I developed in order to be able to run these functions on the server. I used SWIG to develop these wrappers. The process requires a .cpp file of the functions (NavalLetter.cpp) and a module file (NavalLetter.swig). SWIG generates the wrapper files and outputs which can be import into Python code. This allows the python server to use the DocxFactory library and functions.

Hosting the Server

I wanted to host this code for free online. I looked at services such as Heroku but they didn’t allow enough flexibility to build the required libraries. In the end, I found Amazon Web Services the best place to host the website. I created a Ubuntu instance which allowed me to build the DocxFactory libraries and load the rest of the code described above. I could then run the web server remotely. Lastly, I added a subdomain to point to the AWS instance.

Exit mobile version