Date: prev next · Thread: first prev next last


I'm started to explore the odftoolkit some days before and I'm curious, whether I could generate a simple invoice using some existing data.

The invoice-document starts with an "address"-paragraph, followed by a table with product-items, again followed by a paragraph with additional information.

I began with the following steps:

1) loading an existing template-document:

        OdfTextDocument outputDocument =OdfTextDocument.loadDocument(templateFile);
        OdfFileDom contentDom = outputDocument.getContentDom();

Is this the right beginning? I also found:

OdfDocument anotherOutputDocument = OdfDocument.loadDocument(templateFile);

2) adding the address:

           outputDocument.newParagraph(address.toString());

3) adding a table:

                OdfTable table = OdfTable.newTable(outputDocument, positions.size(), 5);

4) adding the product-items:


                for (Position position : positions) {
                    OdfTableRow rowForPosition = table.getRowByIndex(position.getPos());
                    // first-cell in row
                    OdfTableCell cellPosNr = rowForPositionIndex.getCellByIndex(0);
                    cellPosNr.setStringValue(position.getPos());
                    // Icon (I would like to include a jpg):
                    String strFile = position.getImageFilePath("icon");
                    File imageFile = new File(strFile);
                    if(imageFile.exists()) {
                       OdfTableCell cellIcon = rowForPositionIndex.getCellByIndex(1);
                       OdfDrawImage image = new OdfDrawImage(contentDom);
                      image.newImage(new URI(strFile));
                      cellIcon.getOdfElement().appendChild(image);
                    }
                    // some other stuff..

5) returning the document.

I'm a little bit puzzled, since the doku says, that "OdfTableCell" is deprecated, but I read at the mail-archive: "deprecated afterwards in favour of the
Simple API and now likely being enabled again".

In the end, I got an odt-document and was able to open it using libreoffice.

Unfortunately I didn't succeed to add the image to the table cell. Can you give me an advice, how this should be implemented?

And a more general question: Is this the way, the ofttoolkit should be used?




--
To unsubscribe e-mail to: dev+unsubscribe@odftoolkit.org
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.odftoolkit.org/dev/
Privacy Policy: https://www.documentfoundation.org/privacy

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.