Is there possible to achieve writing text direction bottom-up in xmlworker? I would like to use it in table. My code is
<table border=1>
<tr>
<td style="padding-right:18px">
<p style="writing-mode:sideways-lr;text-align:center">First</p</td>
<td style="padding-right:18px">
<p style="writing-mode:sideways-lr;text-align:center">Second</p></td></tr>
<tr><td><p style="text-align:center">1</p> </td>
<td><p style="text-align:center">2</p></td>
</tr>
</table>
But it it doesn't work after conversion from html to pdf. Text FIRST and SECOND are not in direction bottom-to-up.
Alternative with utf8:
This was a pretty interesting problem, so +1 to the question.
The first step was to lookup whether or not iTextSharp XML Worker supports the
HTML
td
tag. The mappings can be found in the source in iTextSharp.tool.xml.html.Tags. There you findtd
is mapped to iTextSharp.tool.xml.html.table.TableData, which makes the job of implementing a custom tag processor a little easier. I.e. all we need to do inherit from the class and overrideEnd()
:As noted in the inline comments, this is a very simple implementation for your specific needs. You'll need to add extra logic to support any other writing-mode
CSS
property value, and include any sanity checks.UPDATE
Based on the comment left by @Daniel, it's not clear how to add custom
CSS
when converting theHTML
toPDF
. First the updated HTML:Then a small snippet of custom CSS:
The slightly difficult part is the extra setup - you can't use the simple out of the box
XMLWorkerHelper.GetInstance().ParseXHtml()
commonly seen here at SO. Here's a simple helper method that should get you started:Instead of rehashing an explanation of the example code above, see the documentation (iText removed documentation, linked to Wayback Machine) to get a better idea of why you need to setup the parser that way.
Also note:
HTML
snippet removed thep
tag, since the style can be applied directly to thetd
tag.width
property. If omitted the columns will be variable widths that match if the text had been rendered horizontally.Tested with iTextSharp and XML Worker versions 5.5.9 Here's the updated result:
how to render the image tags inside the table in pdf as per their table location? - @kuujinbo