I am trying to add a picture (org.docx4j.wml.Pict) into a Paragraph by using the following code.
It runs perfectly(no runtime error, creating the docx file) but when I try to open that file using MS-WORD is is showing error in file.
I tried to open it using wordpad it is opening fine and the inserted image is appearing.
Why this generated file is not opening with MS-Word
Please advice me, where I am doing the mistake.
Thanks & Regards,
B.V.Suresh Babu.
===================================================================================================
- Code: Select all
- try
 {
 
 startParg();startRun();
 int i=0;
 
 
 File file = new File(System.getProperty("user.dir") +"/"+PropertyUtility.getKeyValue(APP_HEADER_LOGO_PATH) );
 
 java.io.InputStream is = new java.io.FileInputStream(file );
 long length = file.length();
 
 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;
 
 Pict objPict = wmlFactory.createPict();;
 
 objPict.getAnyAndAny().add(newImage( bean.getDoc(), bytes,
 filenameHint, altText,
 id1, id2 ));
 
 
 bean.getCurrentParg().getContent().add(objPict);;
 
 
 endRun();endParg();
 }
 catch(Exception e) {
 e.printStackTrace();
 }


 News
 News Site map
 Site map SitemapIndex
 SitemapIndex RSS Feed
 RSS Feed