// Get the header
CTHdrFtrRef ref = sectPr.getHeaderReferenceArray(i);
PackagePart hdrPart = doc.getPartById(ref.getId());
- HdrDocument hdrDoc = HdrDocument.Factory.parse(hdrPart.getInputStream());
- CTHdrFtr hdrFtr = hdrDoc.getHdr();
- XWPFHeader hdr = new XWPFHeader(doc, hdrFtr);
+
+ XWPFHeader hdr = null;
+
+ for (POIXMLDocumentPart part : doc.getRelations()) {
+ if (part.getPackagePart().getPartName().equals(hdrPart.getPartName())) {
+ hdr = (XWPFHeader) part;
+ }
+ }
// Assign it
Enum type = ref.getType();
}
}
cursor.dispose();
- getAllPictures();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
*/
public XWPFPictureData getPictureData(){
String blipId = ctPic.getBlipFill().getBlip().getEmbed();
- for(POIXMLDocumentPart part: paragraph.getDocument().getRelations()){
+ for(POIXMLDocumentPart part: ((POIXMLDocumentPart) paragraph.getPart()).getRelations()){
if(part.getPackageRelationship().getId().equals(blipId)){
return (XWPFPictureData)part;
}
XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
-
XWPFHeader header = policy.getDefaultHeader();
XWPFFooter footer = policy.getDefaultFooter();
assertNotNull(header);
assertNotNull(footer);
+ }
- // TODO verify if the following is correct
- assertNull(header.toString());
+ public void testImageInHeader() {
+ XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx");
- }
+ XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
+
+ XWPFHeader header = policy.getDefaultHeader();
+
+ assertNotNull(header.getRelations());
+ assertEquals(1, header.getRelations().size());
+ }
public void testSetHeader() throws IOException {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
public class TestXWPFPictureData extends TestCase {
public void testRead(){
}
}
+ public void testPictureInHeader() {
+ XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx");
+ XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
+
+ XWPFHeader header = policy.getDefaultHeader();
+
+ List<XWPFPictureData> pictures = header.getAllPictures();
+ assertEquals(1, pictures.size());
+ }
+
public void testNew() throws Exception {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("EmptyDocumentWithHeaderFooter.docx");
byte[] jpegData = "test jpeg data".getBytes();
package org.apache.poi.xwpf.usermodel;
import java.math.BigInteger;
+import java.util.List;
import junit.framework.TestCase;
import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
assertEquals(false, run.isStrike());
assertEquals(null, run.getCTR().getRPr());
}
+
+ public void testPictureInHeader() {
+ XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx");
+ XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
+
+ XWPFHeader header = policy.getDefaultHeader();
+
+ int count = 0;
+
+ for (XWPFParagraph p : header.getParagraphs()) {
+ for (XWPFRun r : p.getRuns()) {
+ List<XWPFPicture> pictures = r.getEmbeddedPictures();
+
+ for (XWPFPicture pic : pictures) {
+ assertNotNull(pic.getPictureData());
+ }
+
+ count+= pictures.size();
+ }
+ }
+
+ assertEquals(1, count);
+ }
}