🤖 Document Templater - Template Based Document Generation Microservice
Document Templater is a powerful and flexible microservice designed to simplify the generation of complex, personalised documents from predefined templates. Combining ease of use with the ability to create highly personalised documents, this microservice is ideal for automating the process of generating reports, contracts, forms and more.
README idiomas: 🇦🇴 Português, 🇺🇸 English
Document Templater leverages the Carbone library to merge templates with data, producing the desired output documents. It utilizes Node.js and Express.js for the backend, allowing you to build a robust and customizable document generation service.
The core features of Document Templater include:
- 📝 Generate professional, elegant documents from pre-loaded templates.
- 🎨 Easily customise documents by incorporating specific data.
- 🌈 Support for multiple template formats, including Word (docx) and PDF.
- 🍏 Simple integration with external APIs to fetch data in real time.
- ⭐️ Flexible settings to adjust the appearance and content of documents.
- 📐 Intuitive API that allows seamless integration into your existing projects.
Document Templater offers a scalable and efficient solution to meet your document generation needs, saving you time and ensuring consistent, high-quality results.
Bring document generation to life easily and reliably with Document Templater.
Follow these steps to get started with Document Templater:
- Node.js: Make sure you have Node.js installed on your machine.
- LibreOffice: Make sure you have LibreOffice version 7.5.1.1 installed on your machine.
-
Clone the repository:
git clone https://github.com/m4nd0mb3/document-templater.git
-
Navigate to the project directory:
cd document-templater
-
Install dependencies:
npm install
-
Start the server:
npm start
-
Open your web browser and navigate to http://localhost:3000.
-
Explore the provided endpoints and examples to see how to generate different types of documents.
To run Document Templater using Docker, follow these steps:
-
Build the Docker image:
docker build -t document-templater:latest .
-
Run the Docker container:
docker run -p 3000:3000 -d document-templater:latest
-
Open your web browser and navigate to http://localhost:3000.
Document Templater provides a set of basic endpoints to interact with the document generation service. Below are the examples of how to use these endpoints.
Endpoint: api/v1/document/create
Method: POST
Description: Create or save a template document based on a provided template and data. Only document file field is required all others will be used to test the data in the sandbox.
Request Body:
{
"document": "path/to/pdf-template.docx",
"data":{
"firstname": "John",
"lastname": "Doe"
}
}
Response:
{
"message":"Data inserted successfully!"
}
Endpoint: api/v1/documents
Method: GET
Description: List all templates stored. Look that the string on tests_data we gonna use to test our sandbox...
Request Body:
{
}
Response:
{
"message": "success",
"data": [
{
"reference": "3da7aa72-0760-4b56-9ba6-efa337c1db2b.odt",
"name": "simple",
"tests_data": "{\"firstname\":\"rasmushed\",\"lastname\":\"Igor\",\"age\":\"30\"}"
},
{
"reference": "fbc57e45-6cbd-4250-8616-1e5038b01ad5.pptx",
"name": "Capa Envelope SV",
"tests_data": "{\"title\":\"Test PPTX\"}"
}
]
}
Endpoint: api/v1/document/{reference}/sandbox
Method: GET
Description: Generates a PDF document based on a reference provided template and data.
Request Body: Optional, but if you enter, the body data must to have the sabe key structure with tests_data.
Response:
A generated PDF document.
Endpoint: api/v1/document/{reference}/generate
Method: GET
Description: Generates a PDF document based on a reference provided template and data.
Request Body: Dhe body data must to have the sabe key structure with tests_data.
Response:
A generated PDF document.
Modify the configuration in .env
to customize settings such as port, file paths, and more.
Contributions are welcome! If you encounter issues or want to add new features, feel free to submit a pull request.
This project is licensed under the Apache-2.0 License.