1

Im using xhtml2pdf to generate report in django and i would like to let one of my cells text display vertically but i couldn't make it using css.

Here is some attempt:

.vertical-text {
     writing-mode: tb-rl; 
}

<table>
    <tbody>
        <tr>
            <td class="vertical-text" >V text</td>
        </tr>
    </tbody>
</table>

UPDATE

writing-mode property is missing in the supported css properties. Is there any workaround?

Shift 'n Tab
  • 8,808
  • 12
  • 73
  • 117

1 Answers1

2

There is another work around, where we can use css: JSFiddle

.verical-text {
    width:1px;
    font-family: monospace;
    white-space: pre-wrap; /* this is for displaying whitespaces including Firefox */
}

But, there are couple of downfall's here:

  1. Is there has to be spaces between letters to ensure it's displayed in vertical.
  2. The letters are not rotated, but would be in similar orientation.

I would suggest use some other tool, where you would not be restricted with css properties like:

  • PDFKit
  • PhantomJs - Write a custom nodeJs server in the backend which would do it.
Nagaraj Tantri
  • 5,172
  • 12
  • 54
  • 78
  • That laid back though, it wont be possible in my case but all your suggestion is a nodejs right? is there not any 3rd party python plugins that provide a less css restriction for pdf? what do you think about weasyprint? i havent ask anything about it so far. – Shift 'n Tab Jul 17 '17 at 09:53
  • @ShiftN'Tab There are some python based 3rd party libs as well, as you mentioned, [Weasyprint](http://weasyprint.readthedocs.io/en/latest/features.html#css-transforms-module-level-1) does provide you the option to transfer and rotate the text (which the modern browsers do support). [PDFKit](https://pypi.python.org/pypi/pdfkit) also has a python implementation. – Nagaraj Tantri Jul 17 '17 at 10:04
  • ill try it both – Shift 'n Tab Jul 17 '17 at 10:18
  • does PDFKIT works on windows machine? im developing on win os – Shift 'n Tab Jul 17 '17 at 10:26
  • It seems like, they do support, in a different manner: https://stackoverflow.com/questions/44661876/python-configure-pdfkit-on-windows – Nagaraj Tantri Jul 17 '17 at 10:58
  • hi there i use PDFKIT it was easy and smooth – Shift 'n Tab Jul 18 '17 at 11:47
  • It helps me a lot with PDFKIT and If you add a PDFKIT installation and usage approach ill reward it with my bounty. – Shift 'n Tab Jul 18 '17 at 12:14
  • I don't have windows machine, due which I can't vouch for the installation as I am guessing it's `pip install pdfkit` and need to install [wkhtmltopdf](https://wkhtmltopdf.org/downloads.html) would do. With that said, the usage is very simple and written in [here](https://pypi.python.org/pypi/pdfkit) – Nagaraj Tantri Jul 18 '17 at 15:59