Letter Generator
This repository contains the source code for Letters Generation (plain text or PDF) from templates
Installation
You can install this tools via yarn
:
yarn add letter-generator
Usage
1 - Create a template
You can use a template to generate your text with variables and flags
const templateText = "Here is a wonderful template.[flag_1> I don't want this to be printed out.][has:webpage>\nCheck out the {webpage} website!]\n[flag_2>I want this to be printed out.]";
const flags = { flag_1: false, flag_2: true };
const variables = { webpage: 'Datenanfragen.de' };
const template = new Template(templateText, flags, variables);
console.log(template.getText());
2 - Creating a Letter
You'll have to pass an object to the letter constructor containing those informations:
const props = {
sender_address: ['Jane Doe', '123 Some Lane', '12345 Some City', 'Some Country'],
recipient_address: ['John Doe', '667 One Street', '98765 Another City', 'A Country'],
information_block: 'A block of information',
subject: content,
content: 'Content of my letter',
signature: { type: 'text', name: 'Name' }
}
3 - Rendering the Letter
You can now create the letter object and use it:
The default layout is the DIN 5008-a layout
const letter = new Letter(props);
const letter_with_layout = new Letter(props, layout_function);
Once your Letter is generated you can create a PdfRender from it:
const render = new PdfRenderer(letter);
render.triggerOpenInNewWindow();
render.triggerDownload();
Contributing
First of all, thank you very much for taking the time to contribute! Contributions are incredibly valuable for a project like ours.
We warmly welcome issues and pull requests through GitHub.
Please be aware that by contributing, you agree for your work to be released under the MIT license, as specified in the LICENSE file.
If you are interested in contributing in other ways besides coding, we can also really use your help. Have a look at our contribute page for more details.