Page 1 of 1

Table is displaying as a single line in Android, Blackberry

PostPosted: Tue Nov 18, 2014 11:48 pm
by anitha_r
Hi Jason,

I've generated a docx report which contains tables and images added as inline texts in the tables.

I can able to view this document in MS Word properly.

But when I try to view this in Android or Blackberry phones, the table is displayed as a single line. The texts are wrapped and each character is displayed in a line inside the table.

I've attached the sample document which views the same in Android and Blackerry.

Please help me on this regard.

Re: Table is displaying as a single line in Android, Blackbe

PostPosted: Wed Nov 19, 2014 11:07 am
by jason
What viewer app is in use on the devices?

Unless you are using docx4j to create PDF or HTML, isn't this a deficiency in the viewer app?

Re: Table is displaying as a single line in Android, Blackbe

PostPosted: Thu Nov 20, 2014 12:44 am
by anitha_r
Hi Jason,

We are viewing the document through browser directly.

For example, if we mail this generated document, we will open this directly from the browser. We're not using any viewer app currently.

At the same time, if we open this doc in windows machine and save once, we can able to view this doc in both Android and Blackberry devices without any issues.


Thanks,
Anitha Stephen

Re: Table is displaying as a single line in Android, Blackbe

PostPosted: Thu Nov 20, 2014 6:56 am
by jason
Whatever browser the device is using may be using a plugin to display the docx. If you open a docx directly from the filesystem on the device, it may or may not use the same code (though chances are it does). Try that and see whether the behaviour is the same.

In any case, it sounds like you have discovered the way forward: compare the contents of the doc opened/saved on Windows,with the original, and identify the relevant difference. (use of w14, w15 namespace?)

If you are having trouble doing this, you can attach the two docx here, but please make them the shortest which is sufficient to repro the behaviour.

Re: Table is displaying as a single line in Android, Blackbe

PostPosted: Thu Nov 27, 2014 4:51 pm
by anitha_r
Hi Jason,

Please find attached the document which I've created using docx4j API.

I'm unable to find the namespace difference as you've mentioned. Please help me to resolve this issue.

If I open and save this document in MS Word, I can able to view the same document in both Android and Blackberry devices properly without any issues.

I've uploaded both the documents which is generated using docx4j API and the document which is saved once after generation.


Thanks,
Anitha Stephen

Re: Table is displaying as a single line in Android, Blackbe

PostPosted: Thu Nov 27, 2014 4:58 pm
by anitha_r
Hi Jason,

For your reference, I've included the code through which I'm generating the document.

Code: Select all
import org.docx4j.jaxb.Context;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.wml.ObjectFactory;
import org.docx4j.wml.Tbl;
import org.docx4j.wml.Tc;
import org.docx4j.wml.Tr;

/**
* @author anitha_r
*
*/
public class AddingATable {
    private static WordprocessingMLPackage  wordMLPackage;
    private static ObjectFactory factory;

    public static void main (String[] args) throws Docx4JException {
    wordMLPackage = WordprocessingMLPackage.createPackage();
    factory = Context.getWmlObjectFactory();

    Tbl table = factory.createTbl();
    Tr tableRow = null;
   
    for (int i=0; i<8; i++) {
       tableRow = factory.createTr();
       
        addTableCell(tableRow, "Injection flaws occur when an application sends untrusted data to an interpreter. Injection flaws are very prevalent, particularly in legacy code. They are often found in SQL, LDAP, Xpath, or NoSQL queries; OS commands; XML parsers, SMTP Headers, program arguments, etc. Injection flaws are easy to discover when examining code, but frequently hard to discover via testing. Scanners and fuzzers can help attackers find injection flaws");
        addTableCell(tableRow, "Injection flaws occur when an application sends untrusted data to an interpreter. Injection flaws are very prevalent, particularly in legacy code. They are often found in SQL, LDAP, Xpath, or NoSQL queries; OS commands; XML parsers, SMTP Headers, program arguments, etc. Injection flaws are easy to discover when examining code, but frequently hard to discover via testing. Scanners and fuzzers can help attackers find injection flaws.");
     
        table.getContent().add(tableRow);
    }

    wordMLPackage.getMainDocumentPart().addObject(table);

    wordMLPackage.save(new java.io.File("src/main/files/HelloWord4.docx"));
    }

    private static void addTableCell(Tr tableRow, String content) {
    Tc tableCell = factory.createTc();
    tableCell.getContent().add(
        wordMLPackage.getMainDocumentPart().createParagraphOfText(content));
    tableRow.getContent().add(tableCell);
    }
}


P.S: For demo purpose, I've added the same content in table.


Thanks,
Anitha Stephen

Re: Table is displaying as a single line in Android, Blackbe

PostPosted: Fri Nov 28, 2014 10:24 pm
by jason
If you compare the 2 docx using the Open XML SDK 2.0 Productivity Tool, you'll see Word added:

w:tblPr and tblGrid:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
    <w:tbl>
      <w:tblPr>
        <w:tblW w:w="0" w:type="auto"/>
        <w:tblInd w:w="-106" w:type="dxa"/>
        <w:tblLook w:val="00A0"/>
      </w:tblPr>
      <w:tblGrid>
        <w:gridCol w:w="4788"/>
        <w:gridCol w:w="4788"/>
      </w:tblGrid>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


and, for each cell, w:tcPr:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
          <w:tcPr>
            <w:tcW w:w="0" w:type="auto"/>
          </w:tcPr>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


I guess the consuming application expects some or all of this, so you might add it via your docx4j code.