@Test
public void testExtensions() throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
File file = new File(System.getProperty("user.dir") + "/src/test/resources/images/VENUS.BMP" );
// Our utility method wants that as a byte array
java.io.InputStream is = new java.io.FileInputStream(file );
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
if (length > Integer.MAX_VALUE) {
System.out.println("File too large!!");
}
byte[] bytes = new byte[(int)length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
System.out.println("Could not completely read file "+file.getName());
}
is.close();
String filenameHint = null;
String altText = null;
int id1 = 0;
int id2 = 1;
org.docx4j.wml.P p = newImage( wordMLPackage, bytes,
filenameHint, altText,
id1, id2 );
// Now add our p to the document
wordMLPackage.getMainDocumentPart().addObject(p);
}