3

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:

enter image description here

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+

Jan Vladimir Mostert
  • 12,380
  • 15
  • 80
  • 137
  • 2
    I guess an iframes is the way to go. Iframe and window are quite limited in Dart. The intention was to clode some security holes. You can work around the limitations using dart-js-interop. – Günter Zöchbauer Aug 13 '15 at 04:14
  • Iframes seem to work fine for normal pages, even if I have an iframe with the javascript on the same page and then use a second iframe to get around cross domain problems, it just won't print PDFs, everything else prints fine. I'm busy looking at https://mozilla.github.io/pdf.js/ – Jan Vladimir Mostert Aug 15 '15 at 07:02

0 Answers0