I'm trying to print out a PDF I'm generating in Java using a Dart frontend. I can perfectly display the PDF in an iFrame, trigger a download on the PDF, but now I need to be able to print the PDF.
This is what I've tried so far, but got stuck:
This is the div on my index.html which I'm using to put iframes in:
<div class="iframe">
</div>
This dart code loads a URL into an iframe and places the iframe on the page (the url for the PDF is on a different domain, but I have a CORS filter in place to allow cross-domain requests)
void printPDF(String url){
querySelectorAll("div.iframe").forEach((DivElement div){
div.nodes.clear();
div.nodes.add(
new IFrameElement()
..src = url
..focus()
//..no print method print ??
);
});
}
This is the iframe containing the PDF:
I've seen code like this in several places where this is done using JavaScript: window.frames.myPdfFrame.print();
, but I can't call print()
on my IframeElement
.
If there's a cleaner way that doesn't need iframes, I would prefer that, if not, whatever way works in the latest Firefox, Chrome or IE11+