Exporting Grid as PDF by using drawDom and drawPDF

1 Answer 22 Views
Grid
lim
Top achievements
Rank 1
lim asked on 27 Jul 2022, 03:42 AM | edited on 27 Jul 2022, 03:44 AM

Dear Team,

I'm currently using drawDom and drawPDF to download the grid as PDF , but i have a problem when exporting the PDF.

if the text is too long for one row, the page doesn't break into the second page.

here is the example: link

Thanks in Advance.

1 Answer, 1 is accepted

Sort by
0
Georgi Denchev
Telerik team
answered on 29 Jul 2022, 11:28 AM

Hello, Lim,

Thank you for the provided Dojo.

The problem is that there is no way to break the <td> elements themselves. You can page break on <tr>(row elements) but not cells.

One potential workaround that comes to my mind is to use a custom row template and split a single row into multiple ones:

    <script id="rowTemplate" type="x/kendo-template">
      <!-- create a new row every 1000 characters -->
       # for (var i = 0; i < FirstName.length; i += 1000) {#
        <tr data-uid="#= uid #"">
         <td>#: FirstName.substr(i, i+1000) #</td>
         # if (i == 0) {#
         <td>#: LastName #</td>
         <td>#: Title #</td>
         <td>#: Country #</td>
         #}#
      	</tr>
        #}#
    </script>

Then the exported pdf will be able to break the pages without trimming the text at the bottom.

Unfortunately, there's no way to guarantee that this won't lead to some unexpected behavior. My advice would be to try and find an alternative way to display columns with long text. Perhaps you could split 1 column into multiple ones?

FirstName Part 1, Part 2, Part 3, and so on.

Dojo

https://dojo.telerik.com/@gdenchev/oFUjIjUC 

Preview

Best Regards,
Georgi Denchev
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.


lim
Top achievements
Rank 1
commented on 30 Jul 2022, 12:11 PM | edited

I have an idea but im not sure is it possible to check if the row height is higher than the PDF, if detected then split all existing data from single row to multiple row until the row is lower than the PDF.
Georgi Denchev
Telerik team
commented on 03 Aug 2022, 04:06 PM

Hi, Lim,

You could set a paperSize in pixels, however there's no way to know what the row height would be before it is rendered in the DOM. While you can access the height of the PDF, there's no way to tell the Grid to create new rows every X pixels.

paperSize: [1000, 500]

The only option would be if you can somehow calculate the row height based on the content of the cell.

Best Regards,

Georgi

Tags
Grid
Asked by
lim
Top achievements
Rank 1
Answers by
Georgi Denchev
Telerik team
Share this question
or