Search code examples
pythondjangoxhtml2pdf

Python xhtml2pdf table cell text display to vertical


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?


Solution

  • 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.