Beispiel #1
0
        private static void CreateFooter(XWPFDocument doc, string headerText, string imageUrl = null)
        {
            if (doc.Document.body.sectPr == null)
            {
                doc.Document.body.sectPr = new CT_SectPr();
            }
            CT_SectPr m_SectPr = doc.Document.body.sectPr;

            CT_Ftr footer = new CT_Ftr();

            CT_SdtBlock   sdtBlock   = new CT_SdtBlock();
            CT_SdtPr      sdtPr      = sdtBlock.AddNewSdtPr();
            CT_SdtDocPart sdtDocPart = sdtPr.AddNewDocPartObj();

            sdtDocPart.AddNewDocPartGallery().val = "Page Numbers (Bottom of Page)";
            sdtDocPart.docPartUnique = new CT_OnOff();

            CT_SdtContentBlock sdtContentBlock = sdtBlock.AddNewSdtContent();
            CT_P p = sdtContentBlock.AddNewP();

            p.AddNewPPr().AddNewJc().val = ST_Jc.center;

            p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.begin;
            p.AddNewR().AddNewInstrText().Value     = "PAGE";
            p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.separate;
            p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.end;

            p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.begin;
            p.AddNewR().AddNewInstrText().Value     = "NUMPAGES";
            p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.separate;
            p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.end;


            footer.Items.Add(sdtBlock);

            XWPFRelation Hrelation  = XWPFRelation.FOOTER;
            XWPFFooter   xwpfFooter = (XWPFFooter)doc.CreateRelationship(Hrelation, XWPFFactory.GetInstance(), doc.FooterList.Count);

            xwpfFooter.SetXWPFDocument(doc);
            xwpfFooter.SetHeaderFooter(footer);

            CT_HdrFtrRef m_HdrFtr2 = m_SectPr.AddNewFooterReference();

            m_HdrFtr2.type = ST_HdrFtr.@default;
            m_HdrFtr2.id   = xwpfFooter.GetPackageRelationship().Id;
        }
Beispiel #2
0
        public XWPFFooter CreateFooter(ST_HdrFtr type, XWPFParagraph[] pars)
        {
            XWPFRelation relation = XWPFRelation.FOOTER;
            String       pStyle   = "Footer";
            int          i        = GetRelationIndex(relation);
            FtrDocument  ftrDoc   = new FtrDocument();
            XWPFFooter   wrapper  = (XWPFFooter)doc.CreateRelationship(relation, XWPFFactory.GetInstance(), i);

            wrapper.SetXWPFDocument(doc);
            CT_HdrFtr ftr = buildFtr(type, pStyle, wrapper, pars);

            wrapper.SetHeaderFooter(ftr);

            ftrDoc.SetFtr((CT_Ftr)ftr);

            assignFooter(wrapper, type);
            using (Stream outputStream = wrapper.GetPackagePart().GetOutputStream())
            {
                ftrDoc.Save(outputStream);
            }
            return(wrapper);
        }