This is a migrated thread and some comments may be shown as answers.

Print table to multi-page pdf

4 Answers 59 Views
Drawing API
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 20 Jul 2015, 08:17 AM

I'm printing a table containing an unknown number of rows to pdf - the output is printing to multiple pages automatically. However, the width of the columns on each page varies and I would like to overcome this, if possible.

Ideally, I would be able to repeat the header row on each page using a template, but I suspect this wouldn't affect the cell widths of subsequent rows.

I don't want to fix the cell widths on the table when the page is rendered, but I have tried to fix the width of all the cells using javascript immediately before printing. This had no affect, however.

What is the best way to deal with this?

4 Answers, 1 is accepted

Sort by
0
Mihai
Telerik team
answered on 21 Jul 2015, 08:04 AM
Hi Paul,

Unfortunately, this isn't doable at the moment.  The way automatic page breaking works is by physically splitting a copy of the DOM nodes, so for example:

    <table>
      <tr>...</tr>
      <tr>...</tr>
      ...
    </table>

becomes:

    <!-- page 1 -->
    <table>
      <tr>..</tr>
      ...
    </table>
    
    <!-- page 2 -->
    <table>
      <tr>..</tr>
      ...
    </table>

When the width of each cell is determined by content, then obviously they will not match from a page to another.  The only thing I can recommend for now is to assign fixed widths to <td> elements.

Also, repeating the header is not supported.  Please feel free to post a feature request for this at our User Voice Forum.

Regards,
Mihai
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Paul
Top achievements
Rank 1
answered on 21 Jul 2015, 08:28 AM

Thanks for your reply Mihai,

I tried fixing the width of all <td> elements immediately before printing, using javascript and inline styles, but this had no effect. Is this the right approach, or do the widths have to be assigned via a stylesheet/class?

Paul

0
Mihai
Telerik team
answered on 21 Jul 2015, 03:05 PM
Hi Paul,

That should work, I don't think doing it via classes/stylesheets is going to do any better.  Can you please post an example on http://dojo.telerik.com/ so I can investigate?

Regards,
Mihai
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Paul
Top achievements
Rank 1
answered on 22 Jul 2015, 09:10 AM

Hi Mihai,

I realised that the class assigned to the cell had a max-width property to keep the cells narrow. When I assign both 'width' and 'min-width' inline styles to the cells, it works a lot better. For some reason it isn't perfect - there is still some small variation in width - but it's much better.

Thanks for your help.

Paul

 

Tags
Drawing API
Asked by
Paul
Top achievements
Rank 1
Answers by
Mihai
Telerik team
Paul
Top achievements
Rank 1
Share this question
or