JxBrowser 6.14.2 Print PDF File with tag "<iframe>"

340 views Asked by At

Currently, I am using JxBrowser 6.14.2 to print a PDF file which is embedded in tag "". However, I can only get a blank PDF file(save as PDF or print). The html code is as follows:

<!DOCTYPE html>
<html>
  <head>
    <title>iframe</title>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8">
  </head>
  <body style="text-align: center" >
    <iframe src="iframe.pdf#toolbar=0" id="myFrame" name="myFrame" width="600"  height="800"></iframe> 
    <input type="button" value="print" onclick="testPrint();">
    <script type="text/javascript">
      function testPrint(){
        var iframe = document.getElementById("myFrame");
        iframe.contentWindow.print(); 
      }
    </script>
  </body>
</html>

And the java:

package com.test.print;

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

public class JxBrowserPrintPdf {
    public static void main(String[] args) {
        Browser browser = new Browser();
        BrowserView browserView = new BrowserView(browser);
        JFrame frame = new JFrame("JxBrowser - PrintPDF");
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame.add(browserView,BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        browser.loadURL("http://localhost:8888/.../iframe.html");
        frame.setVisible(true);
    }
}

The webpage displays the contents of the PDF file, but after clicking the print button "print", I get the blank file. And I can get the correct file in the Google browser.

Hope someone can solve my problem. Thanks.

0

There are 0 answers