Page 1 of 1

Load image but can't save it on word

PostPosted: Tue Jan 26, 2016 10:04 pm
by Xoxow
Hi there, i'm currently new to Docx4J so i'm trying to explain as correct as I can what problem I face.
And sorry for my bad english terms or words.

In my code I create a wordMLPackage.getMainDocumentPart().addParagraphOfText(champ1.getText().toString()); ( sheet word ).

Its refers to some EditText i've put in my Layout. I've found on google an image loader method and it's works with a boutton. I can load my image into my view with an ImageView.
But when I try to save my Docx it only save text. I think my problem is my array byte method.

My current code is :


WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();

String dataPath = "picturePath";

// The image to add
File file = new File(dataPath);

// 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 );
wordMLPackage.getMainDocumentPart().addObject(p);

wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Title", Titre.getText().toString());
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Subtitle", "Voici vos informations");
wordMLPackage.getMainDocumentPart().addParagraphOfText(champ1.getText().toString());
wordMLPackage.getMainDocumentPart().addParagraphOfText(champ2.getText().toString());
wordMLPackage.getMainDocumentPart().addParagraphOfText(champ3.getText().toString());
wordMLPackage.save(new java.io.File(folderDocuments.getAbsolutePath()+File.separator+ Titre.getText().toString() +".docx" + File.separator));

}

public static org.docx4j.wml.P newImage( WordprocessingMLPackage wordMLPackage,
byte[] bytes,
String filenameHint, String altText,
int id1, int id2) throws Exception {

BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);

Inline inline = imagePart.createImageInline( filenameHint, altText,
id1, id2, false);

// Now add the inline in w:p/w:r/w:drawing
org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
org.docx4j.wml.P p = factory.createP();
org.docx4j.wml.R run = factory.createR();
p.getContent().add(run);
org.docx4j.wml.Drawing drawing = factory.createDrawing();
run.getContent().add(drawing);
drawing.getAnchorOrInline().add(inline);

return p;

}


My " picturePath " is the following path from my image with the button.


I hope someone of you can help me i'll be glad !

Re: Load image but can't save it on word

PostPosted: Wed Jan 27, 2016 9:01 am
by jason
What does the logging say, especially for BinaryPartAbstractImage ? Maybe an issue with your image format (eg jpeg/png etc)

Re: Load image but can't save it on word

PostPosted: Mon Feb 01, 2016 7:46 pm
by Xoxow
My format image is " jpeg " but there is nothing on the logs

Re: Load image but can't save it on word

PostPosted: Tue Feb 02, 2016 7:53 pm
by jason
Have you configured logging?

Attach the output docx to this thread please

Re: Load image but can't save it on word

PostPosted: Wed Feb 03, 2016 1:15 am
by Xoxow
Code: Select all
02-02 14:54:16.541: D/dalvikvm(14239): Debugger has detached; object registry had 1 entries
02-02 15:05:31.791: D/libEGL(17404): loaded /system/lib/egl/libEGL_mali.so
02-02 15:05:31.791: D/libEGL(17404): loaded /system/lib/egl/libGLESv1_CM_mali.so
02-02 15:05:31.796: D/libEGL(17404): loaded /system/lib/egl/libGLESv2_mali.so
02-02 15:05:31.806: E/(17404): Device driver API match
02-02 15:05:31.806: E/(17404): Device driver API version: 23
02-02 15:05:31.806: E/(17404): User space API version: 23
02-02 15:05:31.806: E/(17404): mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Fri Mar 21 13:52:50 KST 2014
02-02 15:05:31.861: D/OpenGLRenderer(17404): Enabling debug mode 0
02-02 15:05:42.296: W/IInputConnectionWrapper(17404): showStatusIcon on inactive InputConnection
02-02 15:05:44.886: D/dalvikvm(17404): GC_FOR_ALLOC freed 220K, 15% free 6056K/7088K, paused 18ms, total 18ms
02-02 15:05:44.926: I/dalvikvm-heap(17404): Grow heap (frag case) to 18.700MB for 12582928-byte allocation
02-02 15:05:44.951: D/dalvikvm(17404): GC_FOR_ALLOC freed 39K, 6% free 18305K/19380K, paused 21ms, total 21ms
02-02 15:05:46.421: W/System.err(17404): log4j:WARN No appenders could be found for logger (org.docx4j.openpackaging.packages.WordprocessingMLPackage).
02-02 15:05:46.421: W/System.err(17404): log4j:WARN Please initialize the log4j system properly.
02-02 15:05:46.431: I/System.out(17404): 9 [main] INFO org.docx4j.utils.Log4jConfigurator  - Since your log4j configuration (if any) was not found, docx4j has configured log4j automatically.
02-02 15:05:46.456: W/System.err(17404): No XmlSchema annotation found for org.docx4j.relationships
02-02 15:05:46.476: W/System.err(17404): No XmlSchema annotation found for org.docx4j.relationships
02-02 15:05:46.476: W/System.err(17404): No XmlSchema annotation found for org.docx4j.relationships
02-02 15:05:46.476: W/System.err(17404): No XmlSchema annotation found for org.docx4j.relationships
02-02 15:05:46.476: W/System.err(17404): No XmlSchema annotation found for org.docx4j.relationships
02-02 15:05:46.486: W/System.err(17404): No XmlSchema annotation found for org.docx4j.relationships
02-02 15:05:46.501: W/System.err(17404): No XmlSchema annotation found for org.docx4j.relationships
02-02 15:05:46.521: W/System.err(17404): No XmlSchema annotation found for org.docx4j.relationships
02-02 15:05:46.526: W/System.err(17404): No XmlSchema annotation found for org.docx4j.relationships
02-02 15:05:46.536: I/System.out(17404): 114 [main] ERROR org.docx4j.jaxb.NamespacePrefixMapperUtils  - name: com.sun.xml.internal.bind.namespacePrefixMapper value: org.docx4j.jaxb.NamespacePrefixMapperSunInternal@42d998c8 .. trying RI.
02-02 15:05:46.536: I/System.out(17404): 115 [main] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils  - Using NamespacePrefixMapper, which is suitable for the JAXB RI
02-02 15:05:46.536: I/System.out(17404): 115 [main] INFO org.docx4j.jaxb.Context  - Using JAXB Reference Implementation
02-02 15:05:46.541: I/System.out(17404): 120 [main] INFO org.docx4j.jaxb.Context  - loading Context jc
02-02 15:05:46.906: D/dalvikvm(17404): GC_FOR_ALLOC freed 3190K, 18% free 19427K/23424K, paused 38ms, total 38ms
02-02 15:05:47.711: D/dalvikvm(17404): GC_FOR_ALLOC freed 4430K, 22% free 19683K/24920K, paused 39ms, total 39ms
02-02 15:05:48.396: D/dalvikvm(17404): GC_FOR_ALLOC freed 4505K, 22% free 19948K/25260K, paused 43ms, total 43ms
02-02 15:05:48.976: D/dalvikvm(17404): GC_FOR_ALLOC freed 4669K, 22% free 20136K/25612K, paused 41ms, total 41ms
02-02 15:05:49.531: D/dalvikvm(17404): GC_FOR_ALLOC freed 4477K, 21% free 20580K/25864K, paused 45ms, total 45ms
02-02 15:05:50.101: D/dalvikvm(17404): GC_FOR_ALLOC freed 4615K, 21% free 21034K/26456K, paused 47ms, total 47ms
02-02 15:05:50.631: D/dalvikvm(17404): GC_FOR_ALLOC freed 4889K, 22% free 21356K/27064K, paused 51ms, total 51ms
02-02 15:05:51.211: D/dalvikvm(17404): GC_FOR_ALLOC freed 4838K, 21% free 21832K/27492K, paused 55ms, total 55ms
02-02 15:05:51.821: D/dalvikvm(17404): GC_FOR_ALLOC freed 5060K, 21% free 22243K/28128K, paused 61ms, total 61ms
02-02 15:05:52.536: D/dalvikvm(17404): GC_FOR_ALLOC freed 5161K, 21% free 22693K/28676K, paused 65ms, total 65ms
02-02 15:05:53.211: D/dalvikvm(17404): GC_FOR_ALLOC freed 5266K, 21% free 23175K/29276K, paused 71ms, total 71ms
02-02 15:05:53.816: D/dalvikvm(17404): GC_FOR_ALLOC freed 5604K, 22% free 23457K/29916K, paused 73ms, total 74ms
02-02 15:05:54.426: D/dalvikvm(17404): GC_FOR_ALLOC freed 5739K, 22% free 23698K/30292K, paused 77ms, total 77ms
02-02 15:05:55.146: D/dalvikvm(17404): GC_FOR_ALLOC freed 5743K, 22% free 24016K/30616K, paused 80ms, total 80ms
02-02 15:05:55.931: D/dalvikvm(17404): GC_FOR_ALLOC freed 5802K, 22% free 24367K/31036K, paused 85ms, total 85ms
02-02 15:05:56.116: W/System.err(17404): No XmlSchema annotation found for org.docx4j.vml.root
02-02 15:05:56.536: D/dalvikvm(17404): GC_FOR_ALLOC freed 5963K, 22% free 24675K/31508K, paused 87ms, total 87ms
02-02 15:05:57.461: I/dalvikvm(17404): Jit: resizing JitTable from 4096 to 8192
02-02 15:05:57.576: D/dalvikvm(17404): GC_FOR_ALLOC freed 6276K, 23% free 24780K/31916K, paused 108ms, total 108ms
02-02 15:05:58.261: D/dalvikvm(17404): GC_FOR_ALLOC freed 5936K, 22% free 25263K/32056K, paused 102ms, total 102ms
02-02 15:05:58.891: D/dalvikvm(17404): GC_FOR_ALLOC freed 5838K, 21% free 25990K/32700K, paused 105ms, total 105ms
02-02 15:05:59.536: D/dalvikvm(17404): GC_FOR_ALLOC freed 6276K, 22% free 26537K/33672K, paused 106ms, total 106ms
02-02 15:06:00.106: D/dalvikvm(17404): GC_FOR_ALLOC freed 6569K, 22% free 26984K/34400K, paused 128ms, total 128ms
02-02 15:06:00.326: W/System.err(17404): No XmlSchema annotation found for org.docx4j.vml.root
02-02 15:06:00.666: D/dalvikvm(17404): GC_FOR_ALLOC freed 6214K, 21% free 27929K/34996K, paused 124ms, total 124ms
02-02 15:06:00.691: I/System.out(17404): 14269 [main] INFO org.docx4j.jaxb.Context  - loaded ae.com.sun.xml.bind.v2.runtime.JAXBContextImpl .. loading others ..
02-02 15:06:01.411: D/dalvikvm(17404): GC_FOR_ALLOC freed 7243K, 23% free 28136K/36256K, paused 130ms, total 130ms
02-02 15:06:01.471: W/System.err(17404): No XmlSchema annotation found for org.docx4j.model.structure.jaxb
02-02 15:06:01.481: W/System.err(17404): No XmlSchema annotation found for org.docx4j.model.structure.jaxb
02-02 15:06:01.486: W/System.err(17404): No XmlSchema annotation found for org.docx4j.model.structure.jaxb
02-02 15:06:01.491: W/System.err(17404): No XmlSchema annotation found for org.docx4j.model.structure.jaxb
02-02 15:06:01.491: W/System.err(17404): No XmlSchema annotation found for org.docx4j.model.structure.jaxb
02-02 15:06:01.496: I/System.out(17404): 15072 [main] INFO org.docx4j.jaxb.Context  - .. others loaded ..
02-02 15:06:01.496: W/System.err(17404): Context init: 15066ms
02-02 15:06:01.496: I/System.out(17404): 15074 [main] INFO org.docx4j.model.structure.PageDimensions  - Using paper size: LETTER
02-02 15:06:01.496: I/System.out(17404): 15074 [main] INFO org.docx4j.model.structure.PageDimensions  - Landscape orientation: false
02-02 15:06:01.496: I/System.out(17404): 15076 [main] INFO org.docx4j.openpackaging.parts.Part  - /_rels/.rels
02-02 15:06:01.501: I/System.out(17404): 15077 [main] INFO org.docx4j.openpackaging.parts.relationships.RelationshipsPart  - adding part with proposed name: /word/document.xml
02-02 15:06:01.501: I/System.out(17404): 15079 [main] INFO org.docx4j.openpackaging.Base  - shortcut was set
02-02 15:06:01.501: I/System.out(17404): 15081 [main] INFO org.docx4j.openpackaging.parts.Part  - /word/styles.xml
02-02 15:06:01.556: I/System.out(17404): The Android Project
02-02 15:06:01.556: I/System.out(17404): 0
02-02 15:06:01.561: I/System.out(17404): 15136 [main] WARN org.docx4j.XmlUtils  - Using default SAXParserFactory: null
02-02 15:06:01.561: I/System.out(17404): 15138 [main] INFO org.docx4j.openpackaging.parts.Part  - /word/_rels/document.xml.rels
02-02 15:06:01.561: I/System.out(17404): 15139 [main] INFO org.docx4j.openpackaging.parts.relationships.RelationshipsPart  - adding part with proposed name: /word/styles.xml
02-02 15:06:01.561: I/System.out(17404): 15139 [main] INFO org.docx4j.openpackaging.Base  - shortcut was set
02-02 15:06:01.566: I/System.out(17404): 15141 [main] INFO org.docx4j.openpackaging.parts.Part  - /docProps/core.xml
02-02 15:06:01.566: I/System.out(17404): 15142 [main] INFO org.docx4j.openpackaging.parts.relationships.RelationshipsPart  - adding part with proposed name: /docProps/core.xml
02-02 15:06:01.566: I/System.out(17404): 15143 [main] INFO org.docx4j.openpackaging.Base  - shortcut was set
02-02 15:06:01.566: I/System.out(17404): 15144 [main] INFO org.docx4j.openpackaging.parts.Part  - /docProps/app.xml
02-02 15:06:01.566: I/System.out(17404): 15144 [main] INFO org.docx4j.openpackaging.parts.relationships.RelationshipsPart  - adding part with proposed name: /docProps/app.xml
02-02 15:06:01.566: I/System.out(17404): 15145 [main] INFO org.docx4j.openpackaging.Base  - shortcut was set
02-02 15:06:01.566: W/System.err(17404): java.io.FileNotFoundException: /picturePath: open failed: ENOENT (No such file or directory)
02-02 15:06:01.566: W/System.err(17404):    at libcore.io.IoBridge.open(IoBridge.java:409)
02-02 15:06:01.566: W/System.err(17404):    at java.io.FileInputStream.<init>(FileInputStream.java:78)
02-02 15:06:01.566: W/System.err(17404):    at org.plutext.DocxToHtml.MainActivity.genererDocx(MainActivity.java:172)
02-02 15:06:01.566: W/System.err(17404):    at org.plutext.DocxToHtml.MainActivity.access$0(MainActivity.java:129)
02-02 15:06:01.566: W/System.err(17404):    at org.plutext.DocxToHtml.MainActivity$1.onClick(MainActivity.java:82)
02-02 15:06:01.566: W/System.err(17404):    at android.view.View.performClick(View.java:4640)
02-02 15:06:01.566: W/System.err(17404):    at android.view.View$PerformClick.run(View.java:19425)
02-02 15:06:01.571: W/System.err(17404):    at android.os.Handler.handleCallback(Handler.java:733)
02-02 15:06:01.571: W/System.err(17404):    at android.os.Handler.dispatchMessage(Handler.java:95)
02-02 15:06:01.571: W/System.err(17404):    at android.os.Looper.loop(Looper.java:146)
02-02 15:06:01.571: W/System.err(17404):    at android.app.ActivityThread.main(ActivityThread.java:5593)
02-02 15:06:01.571: W/System.err(17404):    at java.lang.reflect.Method.invokeNative(Native Method)
02-02 15:06:01.571: W/System.err(17404):    at java.lang.reflect.Method.invoke(Method.java:515)
02-02 15:06:01.571: W/System.err(17404):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
02-02 15:06:01.571: W/System.err(17404):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
02-02 15:06:01.571: W/System.err(17404):    at dalvik.system.NativeStart.main(Native Method)
02-02 15:06:01.571: W/System.err(17404): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
02-02 15:06:01.571: W/System.err(17404):    at libcore.io.Posix.open(Native Method)
02-02 15:06:01.571: W/System.err(17404):    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
02-02 15:06:01.571: W/System.err(17404):    at libcore.io.IoBridge.open(IoBridge.java:393)
02-02 15:06:01.571: W/System.err(17404):    ... 15 more
02-02 15:06:01.571: I/Choreographer(17404): Skipped 887 frames!  The application may be doing too much work on its main thread.
02-02 15:06:05.771: W/IInputConnectionWrapper(17404): showStatusIcon on inactive InputConnection


Here is my log , I hope it will be helpfull for you Jason

Re: Load image but can't save it on word

PostPosted: Fri Feb 05, 2016 8:44 pm
by Xoxow
Code: Select all
02-05 10:35:18.721: W/System.err(25554): java.lang.NullPointerException
02-05 10:35:18.721: W/System.err(25554):    at java.io.File.fixSlashes(File.java:185)
02-05 10:35:18.721: W/System.err(25554):    at java.io.File.<init>(File.java:134)
02-05 10:35:18.721: W/System.err(25554):    at org.plutext.DocxToHtml.MainActivity2.genererDocx(MainActivity2.java:100)
02-05 10:35:18.721: W/System.err(25554):    at org.plutext.DocxToHtml.MainActivity2.access$0(MainActivity2.java:82)
02-05 10:35:18.721: W/System.err(25554):    at org.plutext.DocxToHtml.MainActivity2$1.onClick(MainActivity2.java:54)
02-05 10:35:18.721: W/System.err(25554):    at android.view.View.performClick(View.java:4640)
02-05 10:35:18.721: W/System.err(25554):    at android.view.View$PerformClick.run(View.java:19425)
02-05 10:35:18.721: W/System.err(25554):    at android.os.Handler.handleCallback(Handler.java:733)
02-05 10:35:18.721: W/System.err(25554):    at android.os.Handler.dispatchMessage(Handler.java:95)
02-05 10:35:18.721: W/System.err(25554):    at android.os.Looper.loop(Looper.java:146)
02-05 10:35:18.721: W/System.err(25554):    at android.app.ActivityThread.main(ActivityThread.java:5593)
02-05 10:35:18.721: W/System.err(25554):    at java.lang.reflect.Method.invokeNative(Native Method)
02-05 10:35:18.726: W/System.err(25554):    at java.lang.reflect.Method.invoke(Method.java:515)
02-05 10:35:18.726: W/System.err(25554):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
02-05 10:35:18.726: W/System.err(25554):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
02-05 10:35:18.726: W/System.err(25554):    at dalvik.system.NativeStart.main(Native Method)


Here new logs