Ng2-pdf-viewer: How to print a pdf?

Created on 12 Jul 2017  路  8Comments  路  Source: VadimDez/ng2-pdf-viewer

I am looking for a solution to print a pdf file.

I found the pdf.js has a web/viewer which supports printing and other features. As ng2-pdf-viewer underneath is using pdf.js. Dose it provide a wrap of the web/viewer? Or does it have a plan to do that?

Most helpful comment

@bhupinderkumarbl - how are you declaring and initializing this.winRef ?

All 8 comments

I did with simply call this function on click

printpdf() {
this.winRef.open(this.pdfSrc).print();
}

Duplicate of #69

@bhupinderkumarbl - how are you declaring and initializing this.winRef ?

Hi @VadimDez , can you please write a small example on how to implement the print ? It would help the beginners a lot.

Convert your blob to URL, and print it. Works for me.
const聽fl聽=聽URL.createObjectURL(this.fileBlob);
window.open(fl).print();

I got it to print using

const聽blobUrl = window.URL.createObjectURL((this.srcBinary);
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = blobUrl;
document.body.appendChild(iframe);
iframe.contentWindow.print();

printpdf() {
this.winRef.open(this.pdfSrc).print();
}

Here explains how to use "winRef", just a bootstrap for nativeWindow.

Simpler approach with example is in https://github.com/intbot/ng2-pdfjs-viewer/issues/7

Was this page helpful?
0 / 5 - 0 ratings