AutoPrint Grid With Button Not

2 Answers 102 Views
Grid PDF Export
John
Top achievements
Rank 1
Iron
John asked on 30 Jan 2024, 02:26 PM

https://www.telerik.com/kendo-angular-ui/components/pdf-export/auto-print/

In this scenario you have to use the checkbox.  However, I would like to use 2 buttons.  One for Download only and one for Download with auto print.  The problem I'm having is that setting the autoPrint = true in code does not work in Angular until the second time.  So it appears that Kendo does not pick up the change in value.  

Does anyone know a way to make this happen without using a checkbox?

2 Answers, 1 is accepted

Sort by
0
Accepted
John
Top achievements
Rank 1
Iron
answered on 30 Jan 2024, 03:24 PM | edited on 30 Jan 2024, 03:25 PM

Thanks for the reply.  We are not allowed to use setTimeout() in our application.  However, I just found this option in Angular that accomplishes what we need.  https://angular.io/guide/zone#ngzone-run-and-runoutsideofangular

public download(value, pdf, filename) {        
    this.autoPrint = value;

    this.ngZone.runOutsideAngular(() => {
        pdf.saveAs(filename);
    });
}

 Thank you for the response.  This is now resolved.
0
Hetali
Telerik team
answered on 30 Jan 2024, 03:18 PM

Hello John,

In order to use two buttons to Download only and Download with Auto Print, use the setTimeout method in the click event to save the PDF using the saveAs method. This way the updated autoPrint value will be considered. For example:

<button kendoButton (click)="download(pdf, false)">
  Download
</button>
public download(pdf, autoprint) {
  this.autoPrint = autoprint;
  setTimeout(() => pdf.saveAs('image-resolution.pdf'));
}

I have created a StackBlitz example demonstrating the snippet shared above.

Let me know if this helps or if I can further assist you.

Regards,
Hetali
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
John
Top achievements
Rank 1
Iron
commented on 30 Jan 2024, 03:23 PM | edited

...
Tags
Grid PDF Export
Asked by
John
Top achievements
Rank 1
Iron
Answers by
John
Top achievements
Rank 1
Iron
Hetali
Telerik team
Share this question
or