So i was thinking about writing a document (layout?) system. Why reinvent the wheel? Well, I want a wheel that fits my cart. Im doing a “larger” web-based application and need to generate/edit/distribute many kinds of mainly-text-documents. One use case is:
Generate a prefilled letter that’s presented to the user, who edits
the text-content slightly and the document gets stored to DB and sent off
as PDF to some email-recipient
The reason im asking here is if there are any caveats that I’m missing, or any present solution that im not aware of that solves this in a quicker/standardized way!
I would like to:
- Display these in the browser (alongside other web content), with simple wysiwyg text-editing and formatting
- Be able to export the document to PDF / Docx / HTML
- Generate from layering templates, for example: Letterhead from company X + default letter layout + signatures at the bottom
- Have inline images, and have simple columns (for tabular data / lists)
- Store them in a Database
- Multiple pages
Im thinking of implementing the entire document as a JSON object and store it in a SQL column. Any language that can de/serialize JSON could then handle the construction of the document. Images could be base64encoded (and maybe compress the final object?) The templates could be documents themselves where elements have id:s so they can be programmatically filled etc. Not quite sure how the length of the elements would work nor positioning (maybe %-position all?). An exporter could be written per format that sets positions etc (pdf/doc/other)
Quick example of concept:
var document = {
metadata: {version:1, createdAt:"", createdBy:""},
styles: {},
pages: [{
elementFoo: {
position:[100, 100],
width:100,
content: "Content of the text-element that can be <b>styled</b>"
},
elementBar: {
position:[100, 200],
width:20,
content: "This might be an adress for a letterhead or a footer text or whatever other block"
}]
}