简体   繁体   English

在QT中,如何将使用内部调用的javascript的html转换为pdf文件

[英]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. 我的应用程序基于qt quick.So不支持小部件。 I am trying to convert a html file to pdf, which has javascript inside. 我正在尝试将html文件转换为pdf,其中包含javascript。 the html as below: 的HTML如下:

<!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? 有什么办法可以将此HTML文件转换为pdf,而javascript生效?

You will need a web rendering engine to consume the input and execute the script accordingly, then let it print the result. 您将需要一个Web渲染引擎来使用输入并相应地执行脚本,然后让其打印结果。

For example using QWebEnginePage and one if its printToPdf() functions. 例如,使用QWebEnginePage和一个printToPdf()函数。

See this stack question: QWebEngine: print a page? 看到以下堆栈问题: QWebEngine:打印页面?

You will find the correct way to print a webview by using new engine based in Chromium or the older webkit. 通过使用基于Chromium的新引擎或较旧的Webkit,您将找到打印Web视图的正确方法。 The two options are completly compatible with Qt Quick. 这两个选项与Qt Quick完全兼容。

You also could use a QTextView to print the data by loading the HTML inside. 您还可以使用QTextView通过在其中加载HTML来打印数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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