Open Document Format made easy using pure JavaScript and Node.js
I created this fork because I needed to create documents on the server of an application built with Meteor, React and antd.
I did not find a smarter solution to the problem than simple-odf, but it lacked the ability to create tables. So I forked and added table handling, please note that this version is not available via npm.
Once testing has been done, I will create a pull request to the parent (connium/simple-odf) to fix that. In the meantime, users may clone my repostiory, run tsc on the root and integrate the result via:
npm install --save /path/to/simple-odf
This setting works perfectly for my setup so it should work in most cases.
Install simple-odf using npm
:
npm install --save simple-odf
Create your first document.
const simpleOdf = require("simple-odf");
const document = new simpleOdf.TextDocument();
const image = document.addParagraph().addImage("/home/homer/myself.png");
image.getStyle().setAnchorType(simpleOdf.AnchorType.AsChar);
image.getStyle().setSize(29.4, 36.5);
document.addHeading("Welcome to simple-odf");
const p1 = document.addParagraph("The quick, brown fox jumps over a lazy dog.");
p1.addText("\nThe five boxing wizards jump quickly.\n\n");
p1.addHyperlink("Visit me", "http://example.org/");
const style1 = new simpleOdf.ParagraphStyle();
// text formatting
style1.setColor(simpleOdf.Color.fromRgb(255, 0, 0));
style1.setFontSize(20);
style1.setTextTransformation(simpleOdf.TextTransformation.Uppercase);
style1.setTypeface(simpleOdf.Typeface.Bold);
// paragraph formatting
style1.setHorizontalAlignment(simpleOdf.HorizontalAlignment.Center);
style1.setPageBreakBefore();
style1.setKeepTogether();
p1.setStyle(style1);
// font usage
document.declareFont("Open Sans", "Open Sans", simpleOdf.FontPitch.Variable);
const p2 = document.addParagraph("It always seems impossible until it's done.");
const style2 = new simpleOdf.ParagraphStyle();
style1.setFontName("Open Sans");
document.addHeading("Credits", 2);
document.addParagraph("This was quite easy. Do you want to know why?");
const list = document.addList();
list.addItem("one-liner setup");
list.addItem("just write like you would do in a full-blown editor");
document.saveFlat("/home/homer/My_first_document.fodf");
Learn more about the OASIS Open Document Format.
If you want to contribute to simple-odf, you are very welcome. Send issues and pull requests with your ideas.
Before submitting a pull request, please make sure the following is done...
-
Fork the repo and create your branch from
master
. A guide on how to fork a repository: https://help.github.com/articles/fork-a-repo/Open terminal and type:
git clone https://github.com/<your_username>/simple-odf cd simple-odf git checkout -b my_branch
-
simple-odf uses npm for running development scripts. If you haven't already done so, please install npm.
-
Run
npm install
.npm install
-
If you've added code, add tests. You can use watch mode that continuously observes changed files to make your life easier.
npm test -- --watch
By contributing to simple-odf, you agree that your contributions will be licensed under its MIT license.