Wednesday 15 August 2012

java - Docx4j in Android throws Verify Error -


In my Android application, I want to create a word document with an image file. For this, I have downloaded and copied to the Libs folder. When I tried to get the image from the path (also bitmap from ImageView) and save it in the document, the app crashed through the errors given below

The code snippet I've tried has been given below,

  import java .io ByteArrayOutputStream; Import org.docx4j.dml.wordprocessingDrawing.Inline; Import org.docx4j.openpackaging.exceptions.InvalidFormatException; Import org.docx4j.openpackaging.packages.WordprocessingMLPackage; Import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage; Import org.docx4j.wml.Drawing; Import org.docx4j.wml.ObjectFactory; Import org.docx4j.wml.P; Import org.docx4j.wml.R; Import Android.graphics. Bitmap; Import Android.graphics. Canvas; Import android.view.View; Public Square SaveWordDocument {Public SaveWordDocument (see v) {// TODO Try Automatically Generated Manufacturer Stub {WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage .createPackage (); Bitmap BMP = load bitmapfreeview (V); Bytereon output stream stream = new byteOutStream (); BMP. Commerce (bitmap.compress format.png, 100, stream); Byte [] bytes = stream.toByteArray (); Try {AddImageToPackage (wordMLPackage, Bytes); WordMLPackage.save (new java.io.file ("/sdcard0/OrderPlace/Order.docx")); } Grip (Exception E) {// TODO Auto generated blocking block e.printStackTrace (); }} Hold (Invalid FormatException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); }} Private Static Zero addImageToPackage (WordprocessingMLPackage wordMLPackage, Byte [] bytes) {BinaryPartAbstractImage imagePart; Try {imagePart = BinaryPartAbstractImage .createImagePart (wordMLPackage, bytes); Int docPrId = 1; Int cNvPrId = 2; Inline inline = imagePart.createImageInline ("filename sign", "alternate text", docPrId, cNvPrId, incorrect); P paras = addInlineImageToParagraph (inline); . WordMLPackage.getMainDocumentPart () addObject (paragraph); } Grip (Exception E) {// TODO Auto generated blocking block e.printStackTrace (); }} Private static P addInlineImageToParagraph (Inline Inline) {// now add an in-line image to a Paragraph ObjectFactory factory = New ObjectFactory (); P. Para = Factory. R Run = Factory. Kreter (); . Add paragraph.getContent () (run); Drawing Drawing = Factory. CreedDolling (); . Run.getContent () (drawing); . Drawing.getAnchorOrInline () (inline); Return paragraph; } Public static bitmap loadbitmapformviewview (see V) {bitmap b = bitmap.creditbeta map (v.getLayoutParams (). Width, v.getLayoutParams (). Height, bitmap config.argb_8888); Canvas C = new canvas (B); V.layout (v.getLeft (), v.getTop (), v.getRight (), v.getBottom ()); V.draw (c); Return b; }}  

When I debug the code, the error throws the following on the line,

  word processing mlpackage wordmlpack = word processingmlpack .createPackage ();  

Even after trying me for several hours, I can not find a solution. Please help me find solutions.


No comments:

Post a Comment