简体   繁体   English

在离线TideSDK webapp中将SVG导出为PDF

[英]Exporting SVG to PDF in a offline TideSDK webapp

I have an offline HTML5/CSS/JS app built with TideSDK in which a bar chart is drawn with Highcharts as an SVG "tag" using data entered by the user. 我有一个使用TideSDK构建的离线HTML5 / CSS / JS应用程序,其中使用Highcharts使用用户输入的数据绘制条形图作为SVG“标记”。 I need to export this chart in a PDF document, which will also contain text and tables. 我需要在PDF文档中导出此图表,该文档还包含文本和表格。

As it is an offline app I can't use the export module included in Highcharts (except the getSVG() method) or other solutions like DocRaptor. 由于它是一个离线应用程序,我不能使用Highcharts中包含的导出模块(getSVG()方法除外)或其他解决方案,如DocRaptor。

I'm open to use another JS plugin for drawing the chart, but I really love the "look and feel" and the features of Highcharts graphs. 我愿意使用另一个JS插件绘制图表,但我真的很喜欢“外观和感觉”以及Highcharts图的功能。

As you may know, with TideSDK I can embed Python, PHP or Perl scripts/modules in my app (I prefer avoid Perl as I've never used it). 您可能知道,使用TideSDK,我可以在我的应用程序中嵌入Python,PHP或Perl脚本/模块(我更喜欢避免使用Perl,因为我从未使用它)。

The other limitation is that I cannot ask to the final users to install another software than mine, so I can't use wkhtmltopdf with PHP. 另一个限制是我不能要求最终用户安装另一个软件而不是我的,所以我不能使用wkhtmltopdf和PHP。 Except if I manage to install it through my app in a transparent process (not sure it is particularly easy to do). 除非我设法通过我的应用程序在透明的过程中安装它(不确定它是否特别容易)。

After having search for several days, my final idea is to use the CairoSVG Python module to export the graph in a first PDF. 在搜索了几天后,我的最终想法是使用CairoSVG Python模块在第一个PDF中导出图形。 Then I will find a JS (jsPDF) or Python tool to include this PDF in the final PDF containing text and tables. 然后我会找到一个JS(jsPDF)或Python工具,将这个PDF包含在包含文本和表格的最终PDF中。

I will start to test this solution soon and let you know if I managed it. 我将很快开始测试这个解决方案,让你知道我是否管理过它。 Nevertheless, if some of you already have to manage a similar problem, I will be very happy to hear your solutions. 然而,如果你们中的一些人已经要处理类似的问题,我将很高兴听到你的解决方案。

The app will run, in a first time, on Windows platform and should be adapted to MacOS, Linux, Android and iOS in later phases. 该应用程序将首次在Windows平台上运行,并应在后期阶段适应MacOS,Linux,Android和iOS。

There is simple command line tool (wkhtml to pdf), that lets you convert html pages to pdf files. 有简单的命令行工具(wkhtml到pdf),它允许您将html页面转换为pdf文件。 Its not strictly python/js solution, but you can call os.system() or something similar from python to use it. 它不是严格的python / js解决方案,但你可以从python中调用os.system()或类似的东西来使用它。 It helped me with my python program and it is very simple to use. 它帮助我使用我的python程序,它使用起来非常简单。 Command is "wkhtmltopdf.exe inputname outputname" and you get what you want. 命令是“wkhtmltopdf.exe inputname outputname”,你得到你想要的。 And its free software. 它的免费软件。 Site: https://code.google.com/p/wkhtmltopdf/ 网站: https//code.google.com/p/wkhtmltopdf/

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

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