Page 1 of 1

how can I get the Header.xml And Footer.xml...

PostPosted: Thu Nov 05, 2009 11:39 am
by kevin Feng
hi all,
exactly I want to get the header's content from the value of the r:id which I can get through the CTRel object.

the code of the test:
Code: Select all
   public static void main(String[] args) throws Docx4JException {
      File file = new File("K:\\word\\headerTest1.docx");
      WordprocessingMLPackage wmlpackage = null;
      wmlpackage = WordprocessingMLPackage.load(file);
      MainDocumentPart mdp = wmlpackage.getMainDocumentPart();
      Part part = mdp.getRelationshipsPart().getPart("rId6");
      ...
      ...
      ...
   }


but I don't know how to use the Part object to get the content.

useing the code, can I get the xml content??

how shall I do the next ...

Re: how can I get the Header.xml And Footer.xml...

PostPosted: Thu Nov 05, 2009 12:05 pm
by jason
See DocumentModel, which contains a list of SectionWrapper, each of which contains an org.docx4j.model.HeaderFooterPolicy.

Your WordML package has a method getDocumentModel().

If there is just a single sectPr in the document, you could do getDocumentModel().getSections().get(last-1).getHeaderFooterPolicy()

Re: how can I get the Header.xml And Footer.xml...

PostPosted: Thu Nov 05, 2009 12:54 pm
by kevin Feng
well :D ..
I got the content.. thank you jason.

but I want to get the xml of the header or the footer by the "r:id".

if I just know the "r:id" and the "w:type" in the headerReference's tag,

than how can I get the right object??

Re: how can I get the Header.xml And Footer.xml...

PostPosted: Thu Nov 05, 2009 1:54 pm
by jason
yourWordMLPkg.getMainDocumentPart().getRelationshipsPart().getPart(partId);

Re: how can I get the Header.xml And Footer.xml...

PostPosted: Fri Nov 06, 2009 5:40 am
by kevin Feng
Exactly using the above way,I can get the part by the rId.

:D

I still have one question..

Code: Select all
List<SectionWrapper> swList = wmlpackage.getDocumentModel().getSections();

The above code can't get the sectPr which is in the p tag,can it??

like the following document.xml, it has two sectPr tag.can it get the first sectPr?? I tried ,it can't
Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
  <w:body>
    <w:p w:rsidR="00F61F50" w:rsidRDefault="006C1A37" w:rsidP="00FC1C37">
      <w:pPr>
        <w:ind w:firstLine="420"/>
        <w:rPr>
          <w:rFonts w:ascii="宋体" w:hAnsi="宋体"/>
          <w:sz w:val="24"/>
          <w:szCs w:val="24"/>
          <w:lang w:eastAsia="zh-TW"/>
        </w:rPr>
       <w:sectPr w:rsidR="00F61F50" w:rsidSect="00DF1383">
          <w:headerReference w:type="default" r:id="rId6"/>
          <w:footerReference w:type="default" r:id="rId7"/>
          <w:pgSz w:w="11906" w:h="16838"/>
          <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="851" w:footer="992" w:gutter="0"/>
          <w:cols w:space="425"/>
          <w:docGrid w:type="lines" w:linePitch="312"/>
        </w:sectPr     </w:pPr>
      <w:r>
        <w:rPr>
          <w:rFonts w:ascii="宋体" w:hAnsi="宋体" w:hint="eastAsia"/>
          <w:sz w:val="24"/>
          <w:szCs w:val="24"/>
          <w:lang w:eastAsia="zh-TW"/>
        </w:rPr>
        <w:t>the first page</w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="006121D2" w:rsidRPr="00FC1C37" w:rsidRDefault="00F61F50" w:rsidP="00FC1C37">
      <w:pPr>
        <w:ind w:firstLine="420"/>
        <w:rPr>
          <w:rFonts w:ascii="宋体" w:hAnsi="宋体" w:hint="eastAsia"/>
          <w:sz w:val="24"/>
          <w:szCs w:val="24"/>
        </w:rPr>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:rFonts w:ascii="宋体" w:hAnsi="宋体" w:hint="eastAsia"/>
          <w:sz w:val="24"/>
          <w:szCs w:val="24"/>
        </w:rPr>
        <w:lastRenderedPageBreak/>
        <w:t>the second page</w:t>
      </w:r>
    </w:p>
   <w:sectPr w:rsidR="006121D2" w:rsidRPr="00FC1C37" w:rsidSect="00DF1383">
      <w:headerReference w:type="default" r:id="rId8"/>
      <w:footerReference w:type="default" r:id="rId9"/>
      <w:pgSz w:w="11906" w:h="16838"/>
      <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="851" w:footer="992" w:gutter="0"/>
      <w:cols w:space="425"/>
      <w:docGrid w:type="lines" w:linePitch="312"/>
    </w:sectPr>
</w:body>
</w:document>

Re: how can I get the Header.xml And Footer.xml...

PostPosted: Fri Nov 06, 2009 7:16 am
by jason
kevin Feng wrote:The above code can't get the sectPr which is in the p tag,can it??


It can since http://dev.plutext.org/trac/docx4j/changeset/966 of 31 October

So you need to have built docx4j from svn to get this, or use the recent nightly http://dev.plutext.org/docx4j/docx4j-ni ... 091106.jar