Return-Path: X-Original-To: apmail-poi-user-archive@www.apache.org Delivered-To: apmail-poi-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 27C53E4FC for ; Fri, 11 Jan 2013 16:31:31 +0000 (UTC) Received: (qmail 31654 invoked by uid 500); 11 Jan 2013 16:31:30 -0000 Delivered-To: apmail-poi-user-archive@poi.apache.org Received: (qmail 31614 invoked by uid 500); 11 Jan 2013 16:31:30 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Delivered-To: moderator for user@poi.apache.org Received: (qmail 25618 invoked by uid 99); 11 Jan 2013 16:28:46 -0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mike.mccullough@gmail.com designates 209.85.212.50 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=rXyDL0IjzdfU7jyxyFYREGVJrylh+Ck8u8ixSHJKhqE=; b=cP0txJMlvJmCUaknhvyi5e0tvCp0nBzHhAJXsyQUemut96bg23KwKnBCUGfPmclfMZ Z9YQRVJYl6fuPTUzSSsz+IQD+xiqolz86KPoqQiSIamTjGslSBXE07GckK3yvrO84mrP k5ormtH9bnz6UZkhSVciCJFPARxBm5ncgFca3Bx347OhnhDfED9qw7CQq8+FH/0aUbdJ HCjNEey5tWllls/alU7sRpaf81yZztYpYzwuS8Njo9eH0DWlwmT2WY+ZuCRiTlZOzXfD DnQ62mfNQlzxCI2fEEyfFFjkrFykMuxt67p4RuowYyaCf/ZYqft8WzsCwlCRLuBBibP2 PMig== MIME-Version: 1.0 Date: Fri, 11 Jan 2013 11:28:17 -0500 Message-ID: Subject: XWPFFooter / XWPFHeader creation From: Mike McCullough To: user@poi.apache.org Content-Type: multipart/alternative; boundary=bcaec5040914719ea304d305c8cd X-Virus-Checked: Checked by ClamAV on apache.org --bcaec5040914719ea304d305c8cd Content-Type: text/plain; charset=ISO-8859-1 Hello- I've been encountering problems trying to create a footer or header for the DOCX format. Most of the examples that I have seen (including the example ones from Apache POI) use the idea of a template file--however, either there's not a way to copy only the XWPFHeaderFooterPolicy or I would have to remove what's existing in the document template so that I'm able to utilize headers this way. I will say that this method works, but is not, at least in my opinion, the optimal way to create a header or footer. So for the method for creating the HeaderFooterPolicy for the non-template route: -- XWPFHeaderFooterPolicy headerFooterPolicy = document.getHeaderFooterPolicy(); if (headerFooterPolicy == null) { CTBody body = document.getDocument().getBody(); CTSectPr sectPr = body.getSectPr(); if (sectPr == null) { sectPr = body.addNewSectPr(); } headerFooterPolicy = new XWPFHeaderFooterPolicy(document, sectPr); } -- I noticed that unless I did the above to create a SectPr, using the XWPFHeaderFooterPolicy(XWPFDocument document) constructor would throw a NullPointerException since the constructor just always assumes there's a SectPr. This could provide a bug fix to other folks who may have encountered this problem. Now that I have a working XWPFHeaderFooterPolicy, theoretically speaking I should be able to just call headerFooterPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, new XWPFParagraph[]{...}) function to create a default footer (likewise for a default header). However, when I take this approach, I'm encountering the following problem when opening the docx file with Microsoft Word: "A text/xml declaration may occur only at the very beginning of input. Location: Part: /word/footer1.xml, Line: 2, Column: 192" Upon inspection of this XML file, I see that the following problem: -- Test Footer Test Footer -- Which shows that POI is producing malformed XML (two lines of the same thing), but I have not encountered why this is the case. My code that produces the XWPFFooter is shown below: -- CTP ctP1 = CTP.Factory.newInstance(); CTR ctR1 = ctP1.addNewR(); CTText text = ctR1.addNewT(); text.setStringValue("Test Footer); XWPFParagraph paragraph= new XWPFParagraph(ctP1, document); XWPFFooter footer = headerFooterPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, new XWPFParagraph[]{paragraph}); -- If there's anyone who's able to help with this particular problem, please let me know. I am not necessarily interested in using the template approach because I really believe that it's a bad solution, and would like to understand either what I'm missing or shortcomings of the library which will resort to me using the template approach. Thanks, Mike --bcaec5040914719ea304d305c8cd--