1

Scenario:

I used selectpdf to convert my MVC view page to PDF. The view contains charts and tables. Export also working as expected except as table width

Problem:

I am having one table created dynamically. I used column width in percentage to set based on view. Here when i export to pdf, the width percentage didn't updated in the pdf.

View Code:

                                <table id="tblData" class="table table-condensed">
                                <thead>
                                    <tr class="active">
                                        <th width="50%">Name</th>
                                        <th width="50%">Count</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var item in MyModel)
                                    {
                                        <tr>
                                            <td width="50%">@item.Name</td>
                                            <td width="50%">@item.Count</td>
                                        </tr>
                                    }
                                </tbody>
                                <tfoot>
                                    <tr class="active">
                                        <th width="50%">Grant Total</th>
                                        <th width="50%">@totalCount</th>
                                    </tr>
                                </tfoot>
                            </table>

If i change that percentage to pixel values, PDF get correctly. So anyway to give width in percentage to update in PDF

Akhil
  • 1,918
  • 5
  • 30
  • 74
  • Can you try applying widths [using CSS and the `col` element](https://stackoverflow.com/a/15884087/265165)? You also shouldn't need to have your widths in every row etc... this should be fine defined just once – thmshd Feb 14 '18 at 13:03
  • yes. Also issue not in the html view only in the exported pdf. I tried with width property and style . If i gave in pixels, its working fine – Akhil Feb 14 '18 at 15:34
  • Well there are countless closed source PDF tools out there, who really know's what they're doing, e.g. how they render HTML. Many answers from [this post](https://stackoverflow.com/q/564650/265165) will give a little overview. Maybe you should report the Problem to SelectPDF Team or switch to another API. – thmshd Feb 14 '18 at 16:52

1 Answers1

0

Make sure you have the width that you need set for the table, otherwise the table will be displayed as small as possible and 50% will not mean what you need.

Run some tests with style "width: 100%" or "width: 800px" on the table and see if those percentages work now.

If you still have problem, try to provide the whole generated html with the associated css.

Tom
  • 285
  • 2
  • 3
  • 1
    hi, i already told that percentage worked in webpage but not in pdf. If i change i gave width in pixel, pdf also work perfectly – Akhil Feb 15 '18 at 09:46