0

My application is based on qt quick.So widget is not supported. I am trying to convert a html file to pdf, which has javascript inside. the html as below:

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>ECharts</title>
</head> 
<body>      
<div id="main" style="width:600px;height:400px;"></div>
**<script src="echarts.js"></script>**
<script type="text/javascript">

    var myChart = echarts.init(document.getElementById('main')); 

is there any way to convert this html file to pdf with javascript taking effect?

LL2012
  • 41
  • 5

2 Answers2

0

You will need a web rendering engine to consume the input and execute the script accordingly, then let it print the result.

For example using QWebEnginePage and one if its printToPdf() functions.

Kevin Krammer
  • 5,159
  • 2
  • 9
  • 22
  • Hi, is it possible to use this under qt quick application? our project is based on this. – LL2012 Mar 13 '17 at 07:55
  • Depends on whether you want to display the HTML content as well as print it. If you want to display it, use a `WebEngineView` element in `QtQuick`. The `QWebEnginePage` class doesn't have or need any UI, so if you are only concerned about interpreting and printing the HTML content, you can still use it in your C++ part of the application – Kevin Krammer Mar 14 '17 at 08:12
0

See this stack question: QWebEngine: print a page?

You will find the correct way to print a webview by using new engine based in Chromium or the older webkit. The two options are completly compatible with Qt Quick.

You also could use a QTextView to print the data by loading the HTML inside.

Community
  • 1
  • 1
mohabouje
  • 3,867
  • 2
  • 14
  • 28