Example usage for org.apache.poi.xwpf.usermodel XWPFParagraph getCTP

List of usage examples for org.apache.poi.xwpf.usermodel XWPFParagraph getCTP

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFParagraph getCTP.

Prototype

@Internal
    public CTP getCTP() 

Source Link

Usage

From source file:mj.ocraptor.extraction.tika.parser.microsoft.ooxml.XWPFWordExtractorDecorator.java

License:Apache License

private void extractParagraph(XWPFParagraph paragraph, XHTMLContentHandler xhtml)
        throws SAXException, XmlException, IOException {
    // If this paragraph is actually a whole new section, then
    // it could have its own headers and footers
    // Check and handle if so
    XWPFHeaderFooterPolicy headerFooterPolicy = null;
    if (paragraph.getCTP().getPPr() != null) {
        CTSectPr ctSectPr = paragraph.getCTP().getPPr().getSectPr();
        if (ctSectPr != null) {
            headerFooterPolicy = new XWPFHeaderFooterPolicy(document, ctSectPr);
            extractHeaders(xhtml, headerFooterPolicy);
        }/*from www. ja  v a  2s.c  o  m*/
    }

    // Is this a paragraph, or a heading?
    String tag = "p";
    String styleClass = null;
    if (paragraph.getStyleID() != null) {
        XWPFStyle style = styles.getStyle(paragraph.getStyleID());

        if (style != null && style.getName() != null) {
            TagAndStyle tas = WordExtractor.buildParagraphTagAndStyle(style.getName(),
                    paragraph.getPartType() == BodyType.TABLECELL);
            tag = tas.getTag();
            styleClass = tas.getStyleClass();
        }
    }

    if (styleClass == null) {
        xhtml.startElement(tag);
    } else {
        xhtml.startElement(tag, "class", styleClass);
    }

    // Output placeholder for any embedded docs:

    // TODO: replace w/ XPath/XQuery:
    for (XWPFRun run : paragraph.getRuns()) {
        XmlCursor c = run.getCTR().newCursor();
        c.selectPath("./*");
        while (c.toNextSelection()) {
            XmlObject o = c.getObject();
            if (o instanceof CTObject) {
                XmlCursor c2 = o.newCursor();
                c2.selectPath("./*");
                while (c2.toNextSelection()) {
                    XmlObject o2 = c2.getObject();

                    XmlObject embedAtt = o2.selectAttribute(new QName("Type"));
                    if (embedAtt != null && embedAtt.getDomNode().getNodeValue().equals("Embed")) {
                        // Type is "Embed"
                        XmlObject relIDAtt = o2.selectAttribute(new QName(
                                "http://schemas.openxmlformats.org/officeDocument/2006/relationships", "id"));
                        if (relIDAtt != null) {
                            String relID = relIDAtt.getDomNode().getNodeValue();
                            AttributesImpl attributes = new AttributesImpl();
                            attributes.addAttribute("", "class", "class", "CDATA", "embedded");
                            attributes.addAttribute("", "id", "id", "CDATA", relID);
                            xhtml.startElement("div", attributes);
                            xhtml.endElement("div");
                        }
                    }
                }
                c2.dispose();
            }
        }

        c.dispose();
    }

    // Attach bookmarks for the paragraph
    // (In future, we might put them in the right place, for now
    // we just put them in the correct paragraph)
    for (CTBookmark bookmark : paragraph.getCTP().getBookmarkStartList()) {
        xhtml.startElement("a", "name", bookmark.getName());
        xhtml.endElement("a");
    }

    TmpFormatting fmtg = new TmpFormatting(false, false);

    // Do the iruns
    for (IRunElement run : paragraph.getIRuns()) {
        if (run instanceof XWPFSDT) {
            fmtg = closeStyleTags(xhtml, fmtg);
            processSDTRun((XWPFSDT) run, xhtml);
            // for now, we're ignoring formatting in sdt
            // if you hit an sdt reset to false
            fmtg.setBold(false);
            fmtg.setItalic(false);
        } else {
            fmtg = processRun((XWPFRun) run, paragraph, xhtml, fmtg);
        }
    }
    closeStyleTags(xhtml, fmtg);

    // Now do any comments for the paragraph
    XWPFCommentsDecorator comments = new XWPFCommentsDecorator(paragraph, null);
    String commentText = comments.getCommentText();
    if (commentText != null && commentText.length() > 0) {
        xhtml.characters(commentText);
    }

    String footnameText = paragraph.getFootnoteText();
    if (footnameText != null && footnameText.length() > 0) {
        xhtml.characters(footnameText + "\n");
    }

    // Also extract any paragraphs embedded in text boxes:
    for (XmlObject embeddedParagraph : paragraph.getCTP().selectPath(
            "declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' declare namespace wps='http://schemas.microsoft.com/office/word/2010/wordprocessingShape' .//*/wps:txbx/w:txbxContent/w:p")) {
        extractParagraph(new XWPFParagraph(CTP.Factory.parse(embeddedParagraph.xmlText()), paragraph.getBody()),
                xhtml);
    }

    // Finish this paragraph
    xhtml.endElement(tag);

    if (headerFooterPolicy != null) {
        extractFooters(xhtml, headerFooterPolicy);
    }
}

From source file:Modelo.EscribirWord.java

public void cambiarLogo() throws FileNotFoundException, IOException, InvalidFormatException, Exception {

    //ASPOSE//ww  w.  jav a2 s .  co m
    //    Document doc = new Document("HojaInventarioObjeto.doc");
    ////    doc.save("Out.pdf");

    //        HWPFDocument doc = new HWPFDocument(new FileInputStream("HojaInventarioTemplate.doc"));

    XWPFDocument document = new XWPFDocument(new FileInputStream("HojaInventarioTemplate.docx"));
    String imageOldName = "logo";
    try {
        //            LOG.info("replaceImage: old=" + "logo" + ", new=" + "imagePathNew");
        String imagePathNew = "PlayStation_1_Logo.png";

        int newImageWidth = 1;
        int newImageHeight = 2;

        int imageParagraphPos = -1;
        XWPFParagraph imageParagraph = null;

        List<IBodyElement> documentElements = document.getBodyElements();
        for (IBodyElement documentElement : documentElements) {
            imageParagraphPos++;
            if (documentElement instanceof XWPFParagraph) {
                imageParagraph = (XWPFParagraph) documentElement;
                if (imageParagraph != null && imageParagraph.getCTP() != null
                        && imageParagraph.getCTP().toString().trim().indexOf(imageOldName) != -1) {
                    break;
                }
            }
        }

        if (imageParagraph == null) {
            throw new Exception("Unable to replace image data due to the exception:\n" + "'" + imageOldName
                    + "' not found in in document.");
        }
        ParagraphAlignment oldImageAlignment = imageParagraph.getAlignment();

        // remove old image
        document.removeBodyElement(imageParagraphPos - 1);

        // now add new image

        // BELOW LINE WILL CREATE AN IMAGE
        // PARAGRAPH AT THE END OF THE DOCUMENT.
        // REMOVE THIS IMAGE PARAGRAPH AFTER 
        // SETTING THE NEW IMAGE AT THE OLD IMAGE POSITION
        XWPFParagraph newImageParagraph = document.createParagraph();
        XWPFRun newImageRun = newImageParagraph.createRun();
        //newImageRun.setText(newImageText);
        newImageParagraph.setAlignment(oldImageAlignment);

        try (FileInputStream is = new FileInputStream(imagePathNew)) {
            newImageRun.addPicture(is, XWPFDocument.PICTURE_TYPE_JPEG, imagePathNew, Units.toEMU(newImageWidth),
                    Units.toEMU(newImageHeight));
        }

        // set new image at the old image position
        document.setParagraph(newImageParagraph, imageParagraphPos);

        // NOW REMOVE REDUNDANT IMAGE FORM THE END OF DOCUMENT
        document.removeBodyElement(document.getBodyElements().size() - 1);

        //            return document;
    } catch (Exception e) {
        throw new Exception("Unable to replace image '" + imageOldName + "' due to the exception:\n" + e);
    } finally {
        // cleanup code
    }

}

From source file:nl.architolk.ldt.processors.WordSerializer.java

License:Open Source License

protected void addHyperlink(XWPFParagraph para, String text, String bookmark) {
    //Create hyperlink in paragraph
    CTHyperlink cLink = para.getCTP().addNewHyperlink();
    cLink.setAnchor(bookmark);//from  ww  w. ja  v a2s . co m
    //Create the linked text
    CTText ctText = CTText.Factory.newInstance();
    ctText.setStringValue(text);
    CTR ctr = CTR.Factory.newInstance();
    ctr.setTArray(new CTText[] { ctText });

    //Create the formatting
    CTRPr rpr = ctr.addNewRPr();
    CTColor colour = CTColor.Factory.newInstance();
    colour.setVal("0000FF");
    rpr.setColor(colour);
    CTRPr rpr1 = ctr.addNewRPr();
    rpr1.addNewU().setVal(STUnderline.SINGLE);

    //Insert the linked text into the link
    cLink.setRArray(new CTR[] { ctr });

}

From source file:nl.architolk.ldt.processors.WordSerializer.java

License:Open Source License

protected void readInput(final PipelineContext pipelineContext, final ProcessorInput input, Config config,
        OutputStream outputStream) {

    try {//  w  ww.  ja  v a 2  s  .c  o m
        // Test
        BigInteger markId = BigInteger.ONE;
        // Read the input as a DOM
        final Document domDocument = readInputAsDOM(pipelineContext, input);

        // create document (docx)
        XWPFDocument doc = new XWPFDocument();

        //iterate through paragraphs;
        NodeList paragraphNodes = domDocument.getElementsByTagName("p");

        for (short i = 0; i < paragraphNodes.getLength(); i++) {
            Node paragraphNode = paragraphNodes.item(i);
            if (paragraphNode.getNodeType() == Node.ELEMENT_NODE) {
                //Create new paragraph
                XWPFParagraph paragraph = doc.createParagraph();

                //iterate through paragraph parts
                NodeList textNodes = paragraphNode.getChildNodes();
                for (short r = 0; r < textNodes.getLength(); r++) {
                    Node textNode = textNodes.item(r);
                    if (textNode.getNodeType() == Node.TEXT_NODE) {
                        XWPFRun run = paragraph.createRun();
                        run.setText(textNode.getTextContent());
                    }
                    if (textNode.getNodeType() == Node.ELEMENT_NODE) {
                        Element textElement = (Element) textNode;
                        if (textNode.getLocalName().toUpperCase().equals("B")) {
                            //Eigenlijk op een andere plaats, maar nu ff voor de test
                            String anchor = textElement.getAttribute("id");
                            if (!anchor.isEmpty()) {
                                CTBookmark bookStart = paragraph.getCTP().addNewBookmarkStart();
                                bookStart.setName(anchor);
                                bookStart.setId(markId);
                            }
                            XWPFRun run = paragraph.createRun();
                            run.setBold(true);
                            run.setText(textNode.getTextContent());
                            if (!anchor.isEmpty()) {
                                CTMarkupRange bookEnd = paragraph.getCTP().addNewBookmarkEnd();
                                bookEnd.setId(markId);
                                markId = markId.add(BigInteger.ONE);
                            }
                        } else if (textNode.getLocalName().toUpperCase().equals("A")) {
                            addHyperlink(paragraph, textNode.getTextContent(),
                                    textElement.getAttribute("href"));
                        } else {
                            XWPFRun run = paragraph.createRun();
                            run.setText(textNode.getTextContent());
                        }
                    }
                }
            }
        }
        // write workbook to stream
        doc.write(outputStream);
        outputStream.close();

    } catch (Exception e) {
        throw new OXFException(e);
    }

}

From source file:nl.detoren.ijc.io.OutputIntekenlijst.java

License:Open Source License

/**
 * Set spacing to double/*from   w  w w . j  a  v  a  2  s.  c o m*/
 *
 * @param para
 */
private void setDoubleLineSpacing(XWPFParagraph para) {
    CTPPr ppr = para.getCTP().getPPr();
    if (ppr == null)
        ppr = para.getCTP().addNewPPr();
    CTSpacing spacing = ppr.isSetSpacing() ? ppr.getSpacing() : ppr.addNewSpacing();
    spacing.setAfter(BigInteger.valueOf(0));
    spacing.setBefore(BigInteger.valueOf(0));
    spacing.setLineRule(STLineSpacingRule.AUTO);
    spacing.setLine(BigInteger.valueOf(480));
}

From source file:offishell.word.WordHeleper.java

License:MIT License

/**
 * <p>/*w w  w  .  ja  va2 s  .com*/
 * Helper method to remove all comments from the specified paragraph.
 * </p>
 * 
 * @param paragraph A target paragraph.
 */
public static void clearComment(XWPFParagraph paragraph) {
    if (paragraph != null) {
        CTP pContext = paragraph.getCTP();

        for (int i = pContext.sizeOfCommentRangeStartArray() - 1; 0 <= i; i--) {
            pContext.removeCommentRangeStart(i);
        }

        for (int i = pContext.sizeOfCommentRangeEndArray() - 1; 0 <= i; i--) {
            pContext.removeCommentRangeEnd(i);
        }

        for (XWPFRun run : paragraph.getRuns()) {
            CTR rContext = run.getCTR();

            for (int i = rContext.sizeOfCommentReferenceArray() - 1; 0 <= i; i--) {
                rContext.removeCommentReference(i);
            }
        }
    }
}

From source file:offishell.word.WordHeleper.java

License:MIT License

/**
 * <p>//from  w ww . ja  va2 s .  c  o  m
 * Helper method to clone {@link XWPFParagraph}.
 * </p>
 * 
 * @param in
 * @param out
 * @param converter
 */
public static void copy(XWPFParagraph in, XWPFParagraph out, UnaryOperator<String> converter) {
    // copy context
    ppr(out).set(in.getCTP().getPPr());

    // copy(doc, out.getDocument(), doc.getStyles().getStyle(in.getStyleID()));

    // copy children
    for (XWPFRun inRun : in.getRuns()) {
        copy(inRun, out.createRun(), converter);
    }
}

From source file:offishell.word.WordHeleper.java

License:MIT License

/**
 * <p>//from   w  ww.ja  v a 2s .  co  m
 * Helper method to retrieve {@link CTPPr}.
 * </p>
 * 
 * @param paragraph
 */
public static CTPPr ppr(XWPFParagraph paragraph) {
    CTP paraContext = paragraph.getCTP();

    return paraContext.isSetPPr() ? paraContext.getPPr() : paraContext.addNewPPr();
}

From source file:org.apache.tika.parser.microsoft.ooxml.XWPFWordExtractorDecorator.java

License:Apache License

private void extractParagraph(XWPFParagraph paragraph, XWPFListManager listManager, XHTMLContentHandler xhtml)
        throws SAXException, XmlException, IOException {
    // If this paragraph is actually a whole new section, then
    //  it could have its own headers and footers
    // Check and handle if so
    XWPFHeaderFooterPolicy headerFooterPolicy = null;
    if (paragraph.getCTP().getPPr() != null) {
        CTSectPr ctSectPr = paragraph.getCTP().getPPr().getSectPr();
        if (ctSectPr != null) {
            headerFooterPolicy = new XWPFHeaderFooterPolicy(document, ctSectPr);
            extractHeaders(xhtml, headerFooterPolicy, listManager);
        }//  ww w  . ja v a 2 s . c o  m
    }

    // Is this a paragraph, or a heading?
    String tag = "p";
    String styleClass = null;
    if (paragraph.getStyleID() != null) {
        XWPFStyle style = styles.getStyle(paragraph.getStyleID());

        if (style != null && style.getName() != null) {
            TagAndStyle tas = WordExtractor.buildParagraphTagAndStyle(style.getName(),
                    paragraph.getPartType() == BodyType.TABLECELL);
            tag = tas.getTag();
            styleClass = tas.getStyleClass();
        }
    }

    if (styleClass == null) {
        xhtml.startElement(tag);
    } else {
        xhtml.startElement(tag, "class", styleClass);
    }

    writeParagraphNumber(paragraph, listManager, xhtml);
    // Output placeholder for any embedded docs:

    // TODO: replace w/ XPath/XQuery:
    for (XWPFRun run : paragraph.getRuns()) {
        XmlCursor c = run.getCTR().newCursor();
        c.selectPath("./*");
        while (c.toNextSelection()) {
            XmlObject o = c.getObject();
            if (o instanceof CTObject) {
                XmlCursor c2 = o.newCursor();
                c2.selectPath("./*");
                while (c2.toNextSelection()) {
                    XmlObject o2 = c2.getObject();

                    XmlObject embedAtt = o2.selectAttribute(new QName("Type"));
                    if (embedAtt != null && embedAtt.getDomNode().getNodeValue().equals("Embed")) {
                        // Type is "Embed"
                        XmlObject relIDAtt = o2.selectAttribute(new QName(
                                "http://schemas.openxmlformats.org/officeDocument/2006/relationships", "id"));
                        if (relIDAtt != null) {
                            String relID = relIDAtt.getDomNode().getNodeValue();
                            AttributesImpl attributes = new AttributesImpl();
                            attributes.addAttribute("", "class", "class", "CDATA", "embedded");
                            attributes.addAttribute("", "id", "id", "CDATA", relID);
                            xhtml.startElement("div", attributes);
                            xhtml.endElement("div");
                        }
                    }
                }
                c2.dispose();
            }
        }

        c.dispose();
    }

    // Attach bookmarks for the paragraph
    // (In future, we might put them in the right place, for now
    //  we just put them in the correct paragraph)
    for (int i = 0; i < paragraph.getCTP().sizeOfBookmarkStartArray(); i++) {
        CTBookmark bookmark = paragraph.getCTP().getBookmarkStartArray(i);
        xhtml.startElement("a", "name", bookmark.getName());
        xhtml.endElement("a");
    }

    TmpFormatting fmtg = new TmpFormatting(false, false);

    // Do the iruns
    for (IRunElement run : paragraph.getIRuns()) {
        if (run instanceof XWPFSDT) {
            fmtg = closeStyleTags(xhtml, fmtg);
            processSDTRun((XWPFSDT) run, xhtml);
            //for now, we're ignoring formatting in sdt
            //if you hit an sdt reset to false
            fmtg.setBold(false);
            fmtg.setItalic(false);
        } else {
            fmtg = processRun((XWPFRun) run, paragraph, xhtml, fmtg);
        }
    }
    closeStyleTags(xhtml, fmtg);

    // Now do any comments for the paragraph
    XWPFCommentsDecorator comments = new XWPFCommentsDecorator(paragraph, null);
    String commentText = comments.getCommentText();
    if (commentText != null && commentText.length() > 0) {
        xhtml.characters(commentText);
    }

    String footnameText = paragraph.getFootnoteText();
    if (footnameText != null && footnameText.length() > 0) {
        xhtml.characters(footnameText + "\n");
    }

    // Also extract any paragraphs embedded in text boxes:
    for (XmlObject embeddedParagraph : paragraph.getCTP().selectPath(
            "declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' declare namespace wps='http://schemas.microsoft.com/office/word/2010/wordprocessingShape' .//*/wps:txbx/w:txbxContent/w:p")) {
        extractParagraph(new XWPFParagraph(CTP.Factory.parse(embeddedParagraph.xmlText()), paragraph.getBody()),
                listManager, xhtml);
    }

    // Finish this paragraph
    xhtml.endElement(tag);

    if (headerFooterPolicy != null) {
        extractFooters(xhtml, headerFooterPolicy, listManager);
    }
}

From source file:org.cgiar.ccafs.marlo.action.summaries.AnualReportPOISummaryAction.java

License:Open Source License

@Override
public String execute() throws Exception {
    try {/*from w  ww . jav a 2  s  .  c o  m*/

        CTDocument1 doc = document.getDocument();
        CTBody body = doc.getBody();

        poiSummary.pageHeader(document, this.getText("summaries.annualReport.header"));
        // Get datetime
        ZonedDateTime timezone = ZonedDateTime.now();
        String zone = timezone.getOffset() + "";
        if (zone.equals("Z")) {
            zone = "+0";
        }

        //
        this.createPageFooter();
        // poiSummary.pageFooter(document, "This report was generated on " + currentDate);

        // Cover
        poiSummary.textLineBreak(document, 10);
        poiSummary.textHeadCoverTitle(document.createParagraph(),
                this.getText("summaries.annualReport.mainTitle"));

        // First page
        poiSummary.textLineBreak(document, 17);
        poiSummary.textHead1Title(document.createParagraph(),
                this.getText("summaries.annualReport.mainTitle2"));
        poiSummary.textHead1Title(document.createParagraph(), this.getText("summaries.annualReport.cover"));
        String unitName = this.getLoggedCrp().getAcronym() != null
                && !this.getLoggedCrp().getAcronym().isEmpty() ? this.getLoggedCrp().getAcronym()
                        : this.getLoggedCrp().getName();
        poiSummary.textParagraph(document.createParagraph(),
                this.getText("summaries.annualReport.unitName") + ": " + unitName);
        poiSummary.textParagraph(document.createParagraph(),
                this.getText("summaries.annualReport.LeadCenter") + ":");
        this.addParticipatingCenters();

        // section 1 - key results
        poiSummary.textHead1Title(document.createParagraph(),
                this.getText("summaries.annualReport.keyResults"));
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.keyResults.crpProgress"));
        this.addExpectedCrp();
        this.addCrpProgressOutcomes();
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.keyResults.progressFlagships"));
        this.addAdjustmentDescription();
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.keyResults.dimensions"));
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("summaries.annualReport.keyResults.dimensions.gender"));
        this.addCrossCuttingGender();
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("summaries.annualReport.keyResults.dimensions.youth"));
        this.addCrossCuttingYouth();
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("summaries.annualReport.keyResults.dimensions.otherAspects"));
        this.addCrossCuttingOtherAspects();
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("summaries.annualReport.keyResults.dimensions.capacityDevelopment"));
        this.addCrossCuttingCapacityDevelopment();
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("summaries.annualReport.keyResults.dimensions.openData"));
        this.addCrossCuttingOpenData();
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("summaries.annualReport.keyResults.dimensions.intellectualAssets"));
        this.addCrossCuttingIntellectualAssets();

        // section 2 - variance from planned program
        poiSummary.textHead1Title(document.createParagraph(),
                this.getText("summaries.annualReport.effectiveness"));
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.effectiveness.program"));
        this.addVariancePlanned();

        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.effectiveness.funding"));
        this.addFundingSummarize();
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.effectiveness.partnership"));
        this.addExternalPartnerships();
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.effectiveness.cross"));
        this.addCrossPartnerships();
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.effectiveness.mel"));
        this.addReportSynthesisMelia();
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.effectiveness.efficiency"));
        this.addImprovingEfficiency();

        // section 3 - crp management
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead1Title(document.createParagraph(),
                this.getText("summaries.annualReport.management"));
        this.addManagement();

        /* Create a landscape text Section */
        XWPFParagraph para = document.createParagraph();
        CTSectPr sectionTable = body.getSectPr();
        CTPageSz pageSizeTable = sectionTable.addNewPgSz();
        CTP ctpTable = para.getCTP();
        CTPPr brTable = ctpTable.addNewPPr();
        brTable.setSectPr(sectionTable);
        /* standard Letter page size */
        pageSizeTable.setOrient(STPageOrientation.LANDSCAPE);
        pageSizeTable.setW(BigInteger.valueOf(842 * 20));
        pageSizeTable.setH(BigInteger.valueOf(595 * 20));
        this.loadTablePMU();

        // Table a1
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead1Title(document.createParagraph(), "TABLES");
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableA.title"));
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableA1.title"));
        this.createTableA1();

        // Table a2
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableA2.title"));
        this.createTableA2();

        // Table b
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableB.title"));
        this.createTableB();
        poiSummary.textNotes(document.createParagraph(),
                this.getText("summaries.annualReport.tableB.description1"));
        poiSummary.textNotes(document.createParagraph(),
                this.getText("summaries.annualReport.tableB.description2"));

        // Table c
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("annualReport.ccDimensions.tableCTitle"));
        this.createTableC();

        // Table d
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableD.title"));

        // Table d1
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableD1.title"));
        this.createTableD1();
        poiSummary.textNotes(document.createParagraph(), this.getText("summaries.annualReport.tableD1.footer"));

        // Table d2
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableD2.title"));
        this.createTableD2();
        poiSummary.textNotes(document.createParagraph(), this.getText("summaries.annualReport.tableD2.footer"));

        // Table e
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("annualReport.ccDimensions.tableETitle",
                        new String[] { String.valueOf(this.getSelectedYear()) }));
        this.createTableE();
        poiSummary.textNotes(document.createParagraph(), this.getText("intellectualAsset.title.help2017"));

        // Table f
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead2Title(document.createParagraph(), this.getText("financialPlan.tableF.title2017"));
        this.createTableF();
        poiSummary.textNotes(document.createParagraph(),
                this.getText("financialPlan.tableF.expenditureArea.help"));
        poiSummary.textNotes(document.createParagraph(),
                this.getText("financialPlan.tableF.expenditureArea.help2017"));
        poiSummary.textNotes(document.createParagraph(),
                "**" + this.getText("summaries.annualReport.tableJ.description.help2"));

        // Table g
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableG.title"));
        this.createTableG();

        // Table h
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableH.title"));
        this.createTableH();
        poiSummary.textNotes(document.createParagraph(),
                this.getText("summaries.powb.tableG.description.help"));

        // Table i1
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableI.title"));
        poiSummary.textHead3Title(document.createParagraph(), this.getText("annualReport.melia.tableI.title",
                new String[] { String.valueOf(this.getSelectedYear()) }) + " POWB");
        this.createTableI1();

        // Table i2
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead3Title(document.createParagraph(),
                this.getText("annualReport.melia.evaluation.title"));
        this.createTableI2();

        // Table j
        poiSummary.textLineBreak(document, 1);
        poiSummary.textHead2Title(document.createParagraph(),
                this.getText("summaries.annualReport.tableJ.title"));
        this.createTableJ();
        poiSummary.textNotes(document.createParagraph(),
                this.getText("summaries.annualReport.tableJ.description.help2"));

        poiSummary.textNotes(document.createParagraph(),
                "*" + this.getText("summaries.annualReport.tableJ.description.help"));

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        document.write(os);
        bytesDOC = os.toByteArray();
        os.close();
        document.close();
    } catch (Exception e) {
        LOG.error("Error generating " + this.getFileName() + ". Exception: " + e.getMessage());
        throw e;
    }

    // Calculate time of generation
    long stopTime = System.currentTimeMillis();
    stopTime = stopTime - startTime;
    LOG.info("Downloaded successfully: " + this.getFileName() + ". User: "
            + this.getCurrentUser().getComposedCompleteName() + ". CRP: " + this.getLoggedCrp().getAcronym()
            + ". Cycle: " + this.getSelectedCycle() + ". Time to generate: " + stopTime + "ms.");
    return SUCCESS;
}