In addition to printing (or print preview as it turned out) we also wanted users to be able to download the report with a name they provide. It was fairly straightforward to get this done, and just required combining two pieces.
The first thing we wanted to do was allow the user to provide a name. Since this is a pretty common feature (and the how-to is going to vary wildly from one project to the next) I'm going to skip it here. The key piece was using the file-saver (via npm package) to save the file to the user's computer.
To better facilitate unit testing and abstraction I created a FileSaver service that I could inject into my components when necessary:
1: import { Injectable } from '@angular/core';
2: import * as FileSaver from 'file-saver';
3:
4: @Injectable()
5: export class FileSaverService {
6: saveAs(blob: any, name: string): void {
7: const document = new Blob([blob], {
8: type: 'application/pdf'
9: });
10: FileSaver.saveAs(document, name);
11: }
12: }
Once I had that service created I just needed to inject it and use it like this:
1: save(): void {
2: this.fileSaverService.saveAs(new Blob([this.reportBytes.buffer]), this.downloadName);
3: }
That turned out to be pretty much all I needed to do to download my reports. I love the easy parts.
Display a list of all reports in SSRSAllow the user to click on a single report to view the reportAllow the user to print the reportAllow the user to download the report
- SSRS Reports in an Angular App (Part 1 - Showing the Report)
- SSRS Reports in an Angular App (Part 2 - Showing the Report (correctly))
- SSRS Reports in an Angular App (Part 3 - Printing the Report)
- SSRS Reports in an Angular App (Part 4 - Downloading the Report)(this post)
Very cool. I have some questions if your available. I'm doing something similar and could use some ideas.
ReplyDelete