Page 1 of 1

css for line-height import

PostPosted: Tue May 13, 2014 7:06 am
by johnp
I have an html table which is importing properly except for the spacing between lines in a TD element.
I'm using this css, (which works in html but not the imported docx):
Code: Select all
td
{
line-height: 1.0;
}


What should I be using instead?

Re: css for line-height import

PostPosted: Tue May 13, 2014 8:03 pm
by jason
Based on a quick look at the source code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        public LineSpacing(CSSValue value) {   
               
                debug(CSS_NAME, value);
               
                CSSPrimitiveValue cssPrimitiveValue = (CSSPrimitiveValue)value;
                short ignored = 1;
                float fVal = cssPrimitiveValue.getFloatValue(ignored); // unit type ignored in cssparser

                int twip;
               
                short type = cssPrimitiveValue.getPrimitiveType();
                if (CSSPrimitiveValue.CSS_IN == type) {
                        twip = UnitsOfMeasurement.inchToTwip(fVal);
                } else if (CSSPrimitiveValue.CSS_MM == type) {
                        twip = UnitsOfMeasurement.mmToTwip(fVal);              
                } else if (CSSPrimitiveValue.CSS_PERCENTAGE == type) {
                        twip = twipFromPercentage(fVal);               
                } else {
                        log.error("No support for unit " + type);
                        twip = 0;
                }
                this.setObject(BigInteger.valueOf(twip) );
               
        }
 
Parsed in 0.016 seconds, using GeSHi 1.0.8.4


please try adding a unit (inches, mm, or %)

Re: css for line-height import

PostPosted: Wed May 14, 2014 2:24 am
by johnp
Thanks for the reply.

I have tried each of those(%,mm,in) without any change in the docx output.

Also, I'm getting this error msg, even though I don't have "em" in any of my css.

2014-05-13 06:48:51,762 [tomcat-http--35] WARN No support for unit: CSS_EMS; instead of em, please use an absolute unit.
2014-05-13 06:48:51,942 [tomcat-http--35] WARN No support for unit: CSS_EMS; instead of em, please use an absolute unit.
2014-05-13 06:48:52,103 [tomcat-http--35] WARN No support for unit: CSS_EMS; instead of em, please use an absolute unit.
2014-05-13 06:48:52,123 [tomcat-http--35] WARN No support for unit: CSS_EMS; instead of em, please use an absolute unit.
2014-05-13 06:48:52,124 [tomcat-http--35] WARN sourcePartStore undefined

I suspect I'm not setting up the import properly. All I'm doing is this:

Code: Select all
InputStream byteStream = urlConn.getInputStream();
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();

XHTMLImporterImpl xhtmlImp = new XHTMLImporterImpl(wordMLPackage);

String baseURL = urlString.substring(0, urlString.lastIndexOf("/"));
wordMLPackage.getMainDocumentPart().getContent()
            .addAll(xhtmlImp.convert(byteStream,baseURL));

wordMLPackage.save(outputStream);


I'm going to find a working example that doesn't give the "em" warning and go from there.

Re: css for line-height import

PostPosted: Wed May 14, 2014 11:45 pm
by jason
With https://github.com/plutext/docx4j/commi ... d0a562d485 the property is now recognised.

So style='line-height: 10mm;' becomes <w:spacing w:line="567">

The exact semantics need to be reviewed. See further http://webapp.docx4java.org/OnlineDemo/ ... ing_1.html

Re: css for line-height import

PostPosted: Thu May 15, 2014 1:29 am
by johnp
Excellent, I will it try it out.
Thanks.