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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
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: [hidden email]
          Reporter: [hidden email]
  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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

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

Dominik Stadler <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64801

Dominik Stadler <[hidden email]> changed:

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

--- Comment #1 from Dominik Stadler <[hidden email]> ---
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64801

--- Comment #2 from Dilipkumar <[hidden email]> ---
(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: [hidden email]
For additional commands, e-mail: [hidden email]