Display Image From SQL Blob Object
Posted: Fri Jan 09, 2015 1:14 am
I have a Blob object from javaDB and want to display it on a docx page.
he following code snippet was used to convert the blob object to byte array
this code is to add image to paragraph.
this is used to create inline image from the byte array
But when i run this code the Netbeans IDE gives an error about the format of the image. the error message is given below.
any suggestion on the way forward is welcomed.
he following code snippet was used to convert the blob object to byte array
- Code: Select all
HashMap<String, Object> hp = new HashMap<>();
- Code: Select all
hp.put("a_picture", resultSet.getBytes("ALUMNUS_PICTURE"));
- Code: Select all
byte[] bytes2 = serializeObject(data.get("a_picture"));
this code is to add image to paragraph.
- Code: Select all
P paragraph = addImageToParagraph(createInlineImage(wordMLPackage,
wordMLPackage.getMainDocumentPart(), bytes2, "filename", "alttext", 1, 2));
- Code: Select all
private org.docx4j.wml.P addImageToParagraph(Inline inLine) {
// Now add the anchor in w:p/w:r/w:drawing
ObjectFactory factory2 = new ObjectFactory();
org.docx4j.wml.P p = factory.createP();
org.docx4j.wml.Drawing drawing = factory2.createDrawing();
R run = factory.createR();
p.getContent().add(run);
run.getContent().add(drawing);
drawing.getAnchorOrInline().add(inLine);
return p;
}
this is used to create inline image from the byte array
- Code: Select all
private Inline createInlineImage(WordprocessingMLPackage wordMLPackage2,
Part sourcePart, byte[] bytes, String filenameHint, String altText,
int id1, int id2) throws Exception {
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage2,
sourcePart, bytes);
return imagePart.createImageInline(filenameHint, altText,
id1, id2, 800000, 750000, false);
}
But when i run this code the Netbeans IDE gives an error about the format of the image. the error message is given below.
- Code: Select all
org.docx4j.openpackaging.exceptions.Docx4JException: Error checking image format
at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.ensureFormatIsSupported(BinaryPartAbstractImage.java:598)
at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.ensureFormatIsSupported(BinaryPartAbstractImage.java:500)
at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.createImagePart(BinaryPartAbstractImage.java:264)
at Word.WordDoc.createInlineImage(WordDoc.java:203)
at Word.WordDoc.createWordDoc(WordDoc.java:103)
at wa_poly.MyJFrame.jButton3ActionPerformed(MyJFrame.java:1225)
at wa_poly.MyJFrame.access$400(MyJFrame.java:89)
at wa_poly.MyJFrame$5.actionPerformed(MyJFrame.java:285)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6527)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6292)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4883)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2739)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:719)
at java.awt.EventQueue$4.run(EventQueue.java:717)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.io.IOException: Cannot run program "imconvert": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.convertToPNG(BinaryPartAbstractImage.java:1279)
at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.ensureFormatIsSupported(BinaryPartAbstractImage.java:582)
... 43 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 48 more
any suggestion on the way forward is welcomed.