简体   繁体   中英

in QT, how to convert html with javascript called inside to pdf file

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM