Patrick Grebe
Patrick Grebe

Reputation: 121

jsPDF-AutoTable : Font-style "italic" for a specific row

I am using jsPDF-AutoTable Plugin to create a pdf. I have the following table structure:

<table id="TableTest" class="MainTable">
<tbody>
    <tr>
        <th>Vorgang</th>
        <th></th>
        <th style="width:80px; " >nicht<br/>relevant</th>
        <th>in<br/>ordnung</th>
    </tr>

    <tr>
        <td rowspan="2">1.</td>
        <td>Durchsicht der Schaltgerätekombination</td>
        <td rowspan="2">

        </td>

        <td rowspan="2">

        </td>

    </tr>
    <tr>
      <td>Inspection of the power switchgear and controlgear assemblies</td>
    </tr>
</tbody>

The td with the text "Inspection of the power switchgear and controlgear assemblies" should have the font-style "italic". Therefore I tried the following code:

    doc.autoTable
({
    head: [['Vorgang', ' ', 'Geprüft']],
    body: allelements,
    startY: 60,
    font: 'times',
    styles:
    {
        fontSize: 7,
        minCellHeight: 3,
        cellWidth: 'wrap'
    },
    willDrawCell: function(cell, data)
    {   
        if(cell.row.cells[1].text[0] == "Inspection of the power switchgear and controlgear assemblies"){

            cell.cell.styles.fontStyle = "italic";
            console.log(cell);
        }
    },
    headStyles:
    {
        fillColor: [55,55,55]
    },
    theme: "grid" //plain grid (oder freilassen)
});    

doc.save('EFPruefprotokoll.pdf');

The font-style attribute changes, but the text isn't italic in the pdf. What I am doing wrong?

Upvotes: 2

Views: 3171

Answers (3)

dizad87
dizad87

Reputation: 468

pass italic as the 2nd arg to the .setFont() clause

pdf.setFont('Helvetica', 'italic');

Upvotes: 0

Justin Herrera
Justin Herrera

Reputation: 653

In react, inline styling works. style={{ fontStyle: 'italic' }}

Upvotes: 0

Patrick Grebe
Patrick Grebe

Reputation: 121

You can use doc.setFontStyle('italic');

Upvotes: -1

Related Questions