You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2020/10/12 02:46:56 UTC

[Bug 64801] New: How to set headers in landscape using java apache poi

https://bz.apache.org/bugzilla/show_bug.cgi?id=64801

            Bug ID: 64801
           Summary: How to set headers in landscape using java apache poi
           Product: POI
           Version: unspecified
          Hardware: PC
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: XWPF
          Assignee: dev@poi.apache.org
          Reporter: dkaruppan@symbiance.com
  Target Milestone: ---

Created attachment 37494
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=37494&action=edit
Headers not coming once landscape page come while generating dynamic document

HI I am generating dynamic .docx document from another document butheaders for
landcape page not coming .Below I have attached .docx file for your reference
please find and guide me in stright path

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 64801] How to set headers in landscape using java apache poi

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64801

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|blocker                     |normal
                 OS|                            |All

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 64801] How to set headers in landscape using java apache poi

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64801

--- Comment #2 from Dilipkumar <dk...@symbiance.com> ---
(In reply to Dominik Stadler from comment #1)
> Please provide the minimal java-code that produces the document. The
> resulting document alone does not help much in analyzing.


Hi Dominik ,

Here I have provided method to generate header and Footer code when landscape
coming while generating dynamic docx it doesn't support for us

 private void addHeaderFooter(XWPFDocument document) {
        try {
            /**
             * Header *
             */
            CTSectPr sectPr = document.getDocument().getBody().getSectPr();
            if (sectPr == null)
                sectPr = document.getDocument().getBody().addNewSectPr();
            XWPFHeaderFooterPolicy policy = new
XWPFHeaderFooterPolicy(document, sectPr);
            XWPFHeader header =
policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);
            XWPFParagraph[] parsHeader = new XWPFParagraph[1];
            XWPFParagraph paragraph = header.getParagraphArray(0);
            if (paragraph == null) {
                paragraph = header.createParagraph();
            }
            paragraph.setAlignment(ParagraphAlignment.LEFT);

            CTP ctParagraph = paragraph.getCTP();
            CTPPr paragraphProperties = ctParagraph.addNewPPr();
            CTJc ctJustification = paragraphProperties.addNewJc();
            ctJustification.setVal(STJc.LEFT);

            CTR leftHeader = ctParagraph.addNewR();
            CTText leftHeaderText = leftHeader.addNewT();
            leftHeaderText.setStringValue(sponsor);

            CTPTab rightTab = paragraph.createRun().getCTR().addNewPtab();
            rightTab.setRelativeTo(STPTabRelativeTo.MARGIN);
            rightTab.setAlignment(STPTabAlignment.RIGHT);
            rightTab.setLeader(STPTabLeader.NONE);
            paragraph.getCTP().addNewR().addNewT().setStringValue(protocol);
            parsHeader[0] = paragraph;

            document = paragraph.getDocument();
            int pos = document.getPosOfParagraph(paragraph);
            document.removeBodyElement(pos);
            /**
             * Footer *
             */
            Date date = new Date();
            String footerText = "Confidential";// "Created " + new
SimpleDateFormat("yyyy-MM-dd").format(date);

            XWPFFooter footer =
policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT);
            XWPFParagraph footerParagraph = footer.getParagraphArray(0);
            if (footerParagraph == null) {
                footerParagraph = footer.createParagraph();
            }
            footerParagraph.setAlignment(ParagraphAlignment.LEFT);

            ctParagraph = footerParagraph.getCTP();
            paragraphProperties = ctParagraph.addNewPPr();
            ctJustification = paragraphProperties.addNewJc();
            ctJustification.setVal(STJc.LEFT);

            CTR leftFooter = ctParagraph.addNewR();
            CTText leftFooterText = leftFooter.addNewT();
            leftFooterText.setStringValue(footerText);

            rightTab = footerParagraph.createRun().getCTR().addNewPtab();
            rightTab.setRelativeTo(STPTabRelativeTo.MARGIN);
            rightTab.setAlignment(STPTabAlignment.RIGHT);
            rightTab.setLeader(STPTabLeader.NONE);

            footerParagraph.getCTP().addNewFldSimple().setInstr("PAGE \\*
MERGEFORMAT");
            footerParagraph.createRun().setText(" of ");
            footerParagraph.getCTP().addNewFldSimple().setInstr("NUMPAGES \\*
MERGEFORMAT");

            XWPFParagraph[] parsFooter = new XWPFParagraph[1];
            parsFooter[0] = footerParagraph;
            policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 64801] How to set headers in landscape using java apache poi

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64801

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #1 from Dominik Stadler <do...@gmx.at> ---
Please provide the minimal java-code that produces the document. The resulting
document alone does not help much in analyzing.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org