Page 1 of 1

Image Rendering Issue

PostPosted: Wed Feb 08, 2012 6:08 am
by sureshbabubv
Dear All,

I am using the following code for rendering a image that is fetched from a remote url .


Code: Select all
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(bean.getDoc(), bytes);
         
           Inline inline = imagePart.createImageInline( filenameHint, altText,
                id1, id2);
      
           MainDocumentPart objDocumentPart = bean.getDoc().getMainDocumentPart();
      
           Relationship  rel=objDocumentPart.addTargetPart(imagePart);

  String wmlDrawing="<w:drawing style=\"position:absolute;margin-left:-7.2pt;margin-top:11.45pt;z-index:251623936;visibility:visible;mso-wrap-style:square;mso-width-percent:0;mso-height-percent:0;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:0;mso-height-percent:0;mso-width-relative:page;mso-height-relative:page;v-text-anchor:top\" xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 wp14\"><wp:anchor distT=\"0\" distB=\"0\" distL=\"114300\" distR=\"114300\" simplePos=\"0\"   behindDoc=\"0\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\" wp14:anchorId=\"5F157C69\" wp14:editId=\"5652B3BE\"><wp:simplePos x=\"0\" y=\"0\"/><wp:positionH relativeFrom=\"column\"><wp:posOffset>-372110</wp:posOffset></wp:positionH><wp:positionV relativeFrom=\"page\"><wp:posOffset>952500</wp:posOffset></wp:positionV><wp:extent cx=\""+iWidth+"\" cy=\""+iheight+"\" /><wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"9525\"/><wp:wrapNone/><wp:docPr id=\"203\" name=\"Picture 203\" descr=\"Logo\"/><wp:cNvGraphicFramePr><a:graphicFrameLocks xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" noChangeAspect=\"1\"/></wp:cNvGraphicFramePr><a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"><pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"><pic:nvPicPr><pic:cNvPr id=\"0\" name=\"Picture 203\" descr=\"Logo\"/><pic:cNvPicPr><a:picLocks noChangeAspect=\"1\" noChangeArrowheads=\"1\"/></pic:cNvPicPr></pic:nvPicPr><pic:blipFill><a:blip r:embed=\""+rel.getId()+"\"><a:extLst><a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\"><a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/></a:ext></a:extLst></a:blip><a:srcRect/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr bwMode=\"auto\"><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\""+iWidth+"\" cy=\""+iheight+"\"/></a:xfrm><a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom><a:noFill/><a:ln><a:noFill/></a:ln></pic:spPr></pic:pic></a:graphicData></a:graphic><wp14:sizeRelH relativeFrom=\"page\"><wp14:pctWidth>0</wp14:pctWidth></wp14:sizeRelH><wp14:sizeRelV relativeFrom=\"page\"><wp14:pctHeight>0</wp14:pctHeight></wp14:sizeRelV></wp:anchor></w:drawing>";
             
          
          
          
          
           Drawing objDrawing = (Drawing)XmlUtils.unmarshalString(wmlDrawing,Context.jc,Drawing.class);
         bean.getCurrentParg().getContent().add(objDrawing);;


When I execute my application in my local system(windows 2007 ), it is generating/rendering the image properly with out any error.

But I execute the application in my client machine (Linux box) The image is not rendering properly and getting the following error.

-
Code: Select all
[ERROR] : unexpected element (uri:"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", local:"sizeRelH"). Expect
- continuing (with possible element/attribute loss)
- [ERROR] : unexpected element (uri:"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", local:"sizeRelV"). Expect
- continuing (with possible element/attribute loss)
- found a:graphic
- found CTBlip


Currently I am using "docx4j-nightly-20120204.jar" file.

Please correct me where I am doing the mistake.


Thanks & Regards,
B.V.Suresh Babu.

Re: Image Rendering Issue

PostPosted: Wed Feb 08, 2012 11:15 pm
by sureshbabubv
Dear All,

I found a rootcause for this solution, I may be wrong also.

The scaling of the image that is generated in the reports (my local windows7, my remote Linux) is differed as shown in the attached file.

The scaling ratio of the images in the report generated by my application in local Windows7 environment--> 100%

The scaling ratio of the images in the report generated in my application in remote Linux environment --> 133%

I found one exception in the log file as shown below


Code: Select all
Batik not in class path
java.lang.NoClassDefFoundError: org/apache/batik/bridge/UserAgent
   at org.apache.fop.image.loader.batik.PreloaderSVG.preloadImage(PreloaderSVG.java:69)
   at org.apache.xmlgraphics.image.loader.ImageManager.preloadImage(ImageManager.java:175)
   at org.apache.xmlgraphics.image.loader.cache.ImageCache.needImageInfo(ImageCache.java:128)
   at org.apache.xmlgraphics.image.loader.ImageManager.getImageInfo(ImageManager.java:122)
   at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.getImageInfo(BinaryPartAbstractImage.java:696)
   at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.ensureFormatIsSupported(BinaryPartAbstractImage.java:352)
   at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.ensureFormatIsSupported(BinaryPartAbstractImage.java:331)
   at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.createImagePart(BinaryPartAbstractImage.java:225)
   at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.createImagePart(BinaryPartAbstractImage.java:144)
   at com.csc.reportbuilder.tmpronto.xsltdocx4jreport.WordGenStatic.addTextBoxContent_new_image(WordGenStatic.java:1213)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:275)
   at org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:440)
   at org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:222)
   at org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java:473)
   at org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:208)
   at org.apache.xpath.Expression.executeCharsToContentHandler(Expression.java:313)
   at org.apache.xalan.templates.ElemValueOf.execute(ElemValueOf.java:274)
   at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
   at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
   at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
   at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
   at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
   at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
   at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
   at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
   at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
   at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
   at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
   at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2270)
   at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1356)
   at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
   at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1273)
   at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1251)
   at com.csc.reportbuilder.tmpronto.xsltdocx4jreport.IssReportBuilder.buildReport(IssReportBuilder.java:92)
   at com.csc.reportbuilder.tmpronto.xsltdocx4jreport.IssReportDump.buildReport(IssReportDump.java:311)
   at com.csc.reportbuilder.tmpronto.xsltdocx4jreport.IssReportDump.<init>(IssReportDump.java:169)
   at com.csc.reportbuilder.tmpronto.xsltdocx4jreport.IssReportDump.main(IssReportDump.java:300)
Caused by: java.lang.ClassNotFoundException: org.apache.batik.bridge.UserAgent
   at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
   ... 41 more



Does this related to the Scaling of image? Please advice me on this issue.
scaling_problem.jpg
Scaling issue in Local Windows 7 Environment, Remote Linux Environment
scaling_problem.jpg (125.44 KiB) Viewed 2356 times

Re: Image Rendering Issue

PostPosted: Thu Feb 09, 2012 3:04 am
by sureshbabubv
Dear All,

When I am digging for the root cause of this issue, I found some deviation of cx, cy values of the ImagePart in windows,linux boxes



Code: Select all
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(bean.getDoc(),bytes);
            
         
           
              Inline inline = imagePart.createImageInline( filenameHint, altText,
                   id1, id2);
         
              MainDocumentPart objDocumentPart = bean.getDoc().getMainDocumentPart();
         
              Relationship  rel=objDocumentPart.addTargetPart(imagePart);

              ImageInfo objImageInfo = imagePart.getImageInfo();
             

         CxCy cxcy = CxCy.scale(objImageInfo, page);
      
                
             int iWidth= (int)cxcy.getCx();
               
                int iheight= (int)cxcy.getCy();
                
          
        System.out.println("the image CX and CY sizes while rendering are  Width: "+iWidth+ "  iheight:   "+iheight);




I am getting the following results

//CX,CY Values when Running the application in Eclipse of windows7(mylocal machine)

Width: 1905000 iheight: 1752600



//CX,CY Values when Running the application from Commandprompt of windows7(mylocal machine)

Width: 1905000 iheight: 1752600


//CX,CY Values when Running the application in linux (my client remote machine)

Width: 2540000 iheight: 2336800


Please advice me how to resolve my issue.

Thanks & Regards,
B.V.Suresh Babu.

Re: Image Rendering Issue

PostPosted: Sat Feb 11, 2012 3:53 am
by sureshbabubv
Dear All,

I identified the reason for this issue.

The CXCY values are depending on SVG properties of the operating system.

For that reason, I am getting different values.

Thanks & Regards,
B.V.Suresh Babu.

Re: Image Rendering Issue

PostPosted: Thu Feb 16, 2012 12:57 am
by sureshbabubv
Dear All,

I temporary resolved this issue in linux by applying the following logic.

Code: Select all
String OS = System.getProperty("os.name").toUpperCase();

              if (OS.contains("NUX")){
                    double ratio =  0.75 ;
                    iWidth = (int) (iWidth * ratio);
                    iheight = (int) (iheight * ratio);
                              }

where iWidth , iheight are the values that I am assigning to the wordprocessing unmarshalled string.

Thanks & Regards,
B.V.SuRESH bABU.

Re: Image Rendering Issue

PostPosted: Thu Feb 16, 2012 7:02 am
by jason
Your image is in SVG format?