Page 1 of 1

XHTML import: Support css line-height

PostPosted: Tue Aug 12, 2014 4:58 pm
by geoM
Hi,

I've just tested
docx4j-3.2.0-beta.jar und
docx4j-ImportXHTML-3.2.0-beta.jar
with <p style="line-height: 250%;"> and it has not been accepted, even as a class in a css file.

I do something wrong?

Any help would be greatly appreciated, thanks!

Re: docx4j 3.2.0 beta - please try it!

PostPosted: Tue Aug 12, 2014 8:31 pm
by jason
Just tested now; running

Code: Select all
       String xhtml = "<p style='line-height: 250%;'>Hello...


through the ConvertInXHTMLFragment sample produces

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
                <w:spacing w:line="600" w:after="0"/>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


which the Word UI shows as: line spacing, multiple 2.5

What exactly are you seeing?

Re: docx4j 3.2.0 beta - please try it!

PostPosted: Tue Aug 12, 2014 11:47 pm
by geoM
Hi Jason,

I have a file with the content:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/word.css" rel="stylesheet" type="text/css"/>
<title>
Teildokument
</title>
</head>
<body>
<p style="line-height: 250%;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, ..</p>
</body>
</html>

and then in java:
Code: Select all
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
XHTMLImporterImpl xHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
try {     
    wordMLPackage.getMainDocumentPart().getContent().addAll(xHTMLImporter.convert(new File(filePath), null) );
}
catch (org.docx4j.org.xhtmlrenderer.util.XRRuntimeException xrre) {
   . . .
}
SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
. . .

The result in document.xml looks like:
Code: Select all
<w:document mc:Ignorable="w14 wp14">
            <w:body>
                <w:p>
                    <w:pPr>
                        <w:spacing w:after="0"/>
                    </w:pPr>
                    <w:bookmarkStart w:name="_GoBack" w:id="0"/>
                    <w:bookmarkEnd w:id="0"/>
                    <w:proofErr w:type="spellStart"/>
                    <w:r>
                        <w:rPr>
                            <w:color w:val="000000"/>
                            <w:sz w:val="20"/>
                        </w:rPr>
                        <w:t>Lorem</w:t>
                    </w:r>
                    <w:proofErr w:type="spellEnd"/>
                    <w:r>
                        <w:rPr>
                            <w:color w:val="000000"/>
                            <w:sz w:val="20"/>
                        </w:rPr>
                        <w:t xml:space="preserve"> </w:t>
                    </w:r>
                    <w:proofErr w:type="spellStart"/>
                    <w:r>
                        <w:rPr>
                            <w:color w:val="000000"/>
                            <w:sz w:val="20"/>
                        </w:rPr>
                        <w:t>ipsum</w:t>
                    </w:r>
                    <w:proofErr w:type="spellEnd"/>
                    <w:r>
                        <w:rPr>
                            <w:color w:val="000000"/>
                            <w:sz w:val="20"/>
                        </w:rPr>
                        <w:t xml:space="preserve"> dolor sit </w:t>
                    </w:r>
                    . . . . . . . . . .

Re: docx4j 3.2.0 beta - please try it!

PostPosted: Wed Aug 13, 2014 6:48 pm
by jason
The presence of

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
                    <w:bookmarkStart w:name="_GoBack" w:id="0"/>
                    <w:bookmarkEnd w:id="0"/>
                    <w:proofErr w:type="spellStart"/>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


tells me that is not the unadulterated output of XHTMLImporterImpl

You can do System.out.println(wordMLPackage.getMainDocumentPart().getXml()) to see that.

Please also check you don't have old docx4j jars on your classpath

Re: docx4j 3.2.0 beta - please try it!

PostPosted: Wed Aug 13, 2014 7:45 pm
by geoM
Mea culpa!

You would absolutely right. I had deleted the old docx4j libs from "Build Path" in Eclipse, but they were still used under WEB-INF / lib.

Many thanks and I'm sorry for your lost time!