I'm using latest docx4j (3.3.7) and generate table, which contains one cell with text rotated by 90 degrees. docx
output is correct, but when exported to pdf
, text in this cell isn't rotated, just regular left-to-right direction.
Same behaviour is with Plutext's commercial PDF Converter (enabled by default) and with docx4j-export-fo
.
How can I force text in table cell to rotate?
Code I use to rotate text in tableCell (work fine in docx
, ignored during pdf
export):
TcPr tableCellProperties = tableCell.getTcPr();
if (tableCellProperties == null) {
tableCellProperties = new TcPr();
tableCell.setTcPr(tableCellProperties);
}
TextDirection td = new TextDirection();
td.setVal("tbRl");
tableCellProperties.setTextDirection(td);
I also tried this, with same effect:
TextDirection td = new TextDirection();
td.setVal("tbRl");
paragraph.setPPr(new PPr());
paragraph.getPPr().setTextDirection(td);
I'm exporting to PDF using method:
Docx4J.toPDF(wordprocessingMLPackage, fileOutputStream);
Since XSL FO has the property reference-orientation, it should be possible to implement in docx4j-export-fo:
17 June 2018 edit
https://github.com/plutext/docx4j-export-FO/commit/3b2c7423c25fe73bb5a85d9aa8755cce6e1aca8e and https://github.com/plutext/docx4j/commit/d8254cbf69d7bb3decaa94254946bd293c5d3ec0 implement this.
The result is imperfect, however; testing the following XSL-FO with FOP 2.3:
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<layout-master-set
xmlns="http://www.w3.org/1999/XSL/Format"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing">
<simple-page-master margin-bottom="12mm"
margin-left="1in" margin-right="1in" margin-top="12mm"
master-name="s1-simple" page-height="297mm" page-width="210mm">
<region-body column-count="1" column-gap="12mm"
margin-bottom="36.0pt" margin-left="0mm" margin-right="0mm"
margin-top="36.0pt" />
<region-before extent="0.0pt"
region-name="xsl-region-before-simple" />
<region-after extent="0.0pt"
region-name="xsl-region-after-simple" />
</simple-page-master>
<page-sequence-master master-name="s1">
<repeatable-page-master-alternatives>
<conditional-page-master-reference
master-reference="s1-simple" />
</repeatable-page-master-alternatives>
</page-sequence-master>
</layout-master-set>
<fo:page-sequence force-page-count="no-force"
id="section_s1" format="" master-reference="s1">
<fo:flow flow-name="xsl-region-body">
<fo:table border-bottom-color="#000000"
border-bottom-style="solid" border-bottom-width="0.5pt"
border-collapse="collapse" border-left-color="#000000"
border-left-style="solid" border-left-width="0.5pt"
border-right-color="#000000" border-right-style="solid"
border-right-width="0.5pt" border-top-color="#000000"
border-top-style="solid" border-top-width="0.5pt"
display-align="before" start-indent="1.12in" table-layout="fixed"
width="3.12in">
<fo:table-column column-number="1"
column-width="3.12in" />
<fo:table-body start-indent="0in">
<fo:table-row height="0.79in"
keep-together.within-page="always">
<fo:table-cell border-bottom-color="#000000"
border-bottom-style="solid" border-bottom-width="0.5pt"
border-left-color="#000000" border-left-style="solid"
border-left-width="0.5pt" border-right-color="#000000"
border-right-style="solid" border-right-width="0.5pt"
border-top-color="#000000" border-top-style="solid"
border-top-width="0.5pt" padding-bottom="0mm"
padding-left="1.91mm" padding-right="1.91mm" padding-top="0mm">
<fo:block-container reference-orientation="90">
<block xmlns="http://www.w3.org/1999/XSL/Format"
font-size="11.0pt" line-height="100%" space-after="0in"
start-indent="2mm">
<inline font-family="Calibri">Bottom up</inline>
</block>
</fo:block-container>
</fo:table-cell>
</fo:table-row>
<fo:table-row height="0.79in"
keep-together.within-page="always">
<fo:table-cell border-bottom-color="#000000"
border-bottom-style="solid" border-bottom-width="0.5pt"
border-left-color="#000000" border-left-style="solid"
border-left-width="0.5pt" border-right-color="#000000"
border-right-style="solid" border-right-width="0.5pt"
border-top-color="#000000" border-top-style="solid"
border-top-width="0.5pt" padding-bottom="0mm"
padding-left="1.91mm" padding-right="1.91mm" padding-top="0mm">
<fo:block-container
reference-orientation="-90">
<block xmlns="http://www.w3.org/1999/XSL/Format"
font-size="11.0pt" line-height="100%" space-after="0in"
start-indent="2mm">
<inline font-family="Calibri">Top down</inline>
</block>
</fo:block-container>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<fo:block font-size="11.0pt" line-height="107%"
space-after="0.11in" white-space-treatment="preserve">
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
the text is rotated as expected, but in one case appears outside the cell.
See also Rotated text in table cell rendered above cell not within
If you explore this further you may conclude some extra fo attributes are required, or that it is a bug in FOP. Please share your findings in a comment here.
As an aside, similar behaviour in XHTML output.