The library is available as an npm package. This library uses Mozilla PDF.js to support IE11. It uses native api in other browsers.
To install the package run:
npm i ng-print-pdf
import PrintPdfModule in target module:
import { PrintPdfModule } from 'ng-print-pdf';
@NgModule({
imports: [PrintPdfModule]
})
export class AppModule {}
and inject PrintPdfService:
export class PdfService {
constructor(private printPdfService: PrintPdfService) {}
public printFile(blob: Blob) {
return this.printPdfService.printDocument(blob, {
printResolution: 144,
scale: 1,
cssUnits: 78.0 / 72.0,
layout: 'portrait',
});
}
}
This solution requires a lot of memory in IE browser. Therefore it's better to add extra check for amount of pages in file.
public async isSafeToPrintPdf(blob: Blob) {
if (!isIE) {
return true;
}
const amountOfPages = await this.printPdfService.getPagesCount(blob)
return amountOfPages < 35;
}