Grid SaveAsPdf with auto paper size

1 Answer 47 Views
Grid
Krzysztof
Top achievements
Rank 1
Krzysztof asked on 28 Jan 2025, 01:19 PM | edited on 28 Jan 2025, 01:19 PM

Hi
I would like to use SaveAsPdf export in my application. I need to place the export button somewhere other than on the tollbar.
Is there a way to make such export in the background without auto clicking through each page in the gui, like in the case of using toolbar: ["pdf"]?

It must have the ability to export all pages and auto paper size.

Example:

https://dojo.telerik.com/PUvxeVje

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 31 Jan 2025, 09:32 AM

Hello, Krzysztof,

From what I can see in the provided example, you have achieved the requirement as I understand it - you are using a custom button to export all of the Grid pages. Could you please let me know if I am missing something from the requirement?

Looking forward to your reply.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Krzysztof
Top achievements
Rank 1
commented on 31 Jan 2025, 09:38 AM

Hello Martin

Thanks for your reply.

Yes, I use custom button because I have to place it under the grid. Additionally, the requirement is to export all pages and set paperSize to auto because the solution will be used in a grid that has a different number of columns in different scenarios and setting a specific page size causes it to look bad in PDF.

Regards

Martin
Telerik team
commented on 05 Feb 2025, 07:21 AM

Hello, Krzysztof,

Thank you for the additional information, but it still seems to be that you have managed to achieve the requirement by yourself in the Dojo example you provided. All of the Grid records are being exported, and the paperSize is set to auto. Could you please let me know what is the issue you are experiencing with in the example you provided?

Krzysztof
Top achievements
Rank 1
commented on 05 Feb 2025, 10:19 AM | edited

Hi

Yes, export works correctly, it export what I want. The problem is that on the gui the user sees that the pages change during this export (in this case it happens very quickly). There is no such thing when we use export to pdf from the toolbar (toolbar: ["pdf"]).

I hope I explained the problem.

Updated example:
https://dojo.telerik.com/buemsOwD

Martin
Telerik team
commented on 10 Feb 2025, 09:19 AM

Hello,

Thank you for the additional details. I have modified the example with some of the internal logic that is used for the default export button. Let me know how that works for you.

Krzysztof
Top achievements
Rank 1
commented on 10 Feb 2025, 10:51 AM

Hello.
It works as I needed.

Thank you very much.

Krzysztof
Top achievements
Rank 1
commented on 24 Feb 2025, 09:28 AM

Hello again
I have noticed one problem and there is a risk that users may also see it.
The thing is that exporting my grid may take a few seconds. The user can open a small browser window and during the export enlarge it and then you will see two grids. The blocked one and the one underneath where the export is taking place.
Is there any way to solve this?
Martin
Telerik team
commented on 27 Feb 2025, 08:30 AM

Hello, Krzysztof,

I am not sure how to observe the behaviour you have stumbled upon. Could you please provide the steps I need to make, and modify the Dojo example if necessary? I will then be happy to investigate for a solution. Thank you in advance for the cooperation.

 

Krzysztof
Top achievements
Rank 1
commented on 27 Feb 2025, 09:37 AM

Hi Martin
I added a timeout to the example https://dojo.telerik.com/UBdrxGPa
To reproduce the problem, you need to run the example in a small window and after starting the export enlarge it. After that you should get an effect like the one I attached on the screen.

 

Nikolay
Telerik team
commented on 04 Mar 2025, 07:03 AM

Hi Krzysztof,

The internal logic that Martin added is not supported for eternal usage and as you can see, it might lead to unexpected side effects.

I can suggest another approach to avoiding the traversal of pages.

 - Temporarily load all data

 - Export the Grid

- Return the page size to the previous one.

      $("#export").click(function(e) {
       	var grid = $("#grid").data("kendoGrid");
        let pageSize = grid.dataSource.pageSize();
        console.log(pageSize)
        grid.dataSource.pageSize(grid.dataSource.total());
    
   		 // Fetch all data without changing pages
    	grid.dataSource.fetch().then(function () {
        grid.saveAsPDF();
        setTimeout(function() {
          grid.dataSource.pageSize(pageSize);
        }, 100)
        });
        
      });

Dojo demo: https://dojo.telerik.com/LmMURdVV

Regards,

Nikolay

Tags
Grid
Asked by
Krzysztof
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or