如何保存Extjs4图表图像以pdf报告打印? [英] how to save Extjs4 chart image to print in a pdf report?

查看:157
本文介绍了如何保存Extjs4图表图像以pdf报告打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的extjs4application仪表板中有几个图表。
i想使用这些图表的图像生成pdf报告
,我使用iTextSharp



有没有办法从图表中获取图像,以便将它们包含在我的报告中?



我的理想是使用它与itextsharp

  MyImageStream = new MemoryStream(); 
myChart.SaveImage(MyImageStream);

我的图表将是图表对象



我在论坛上问道,他们告诉我,我会在客户端生成并呈现我的图表(已经完成),然后我会得到svg,将其发送到服务器,服务器将使用它来生成pdf ...
但我不知道如何与svg一起工作既不会将其发送到服务器



编辑



我试图使用wkhtmltoimage将我的图表保存到图像中



但它不工作,我指定一个mapPath到我的.aspx



但是,如果我指定一个网站的url或localhost路径(见注释中的htem),它可以正常工作。



错误,但没有png创建!



我的代码:

  var url = HttpContext.Current.Server.MapPath(〜/ chartImage.aspx); // dosnt work 
// works://google.com; //\"localhost/chartImage.aspx\";//
var fileName =pie13.png;
var wkhtmlDir = HttpContext.Current.Server.MapPath(〜/ wkhtmltopdf / pdf /); //C:\\Program Files\\\wkhtmltopdf\\
var wkhtml = HttpContext.Current.Server.MapPath(〜/ wkhtmltopdf / wkhtmltoimage.exe); //C:\\Program Files\\wkhtmltopdf\\\wwhtmlhtmltopdf.exe ;
var p = new Process();

p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = wkhtml;
p.StartInfo.WorkingDirectory = wkhtmlDir;

string switches =;
// switches + =--print-media-type;
// switch + =--margin-top 10mm - 尺寸下10mm - 右侧10mm - 左右10mm;
// switches + =--page-size Letter;
p.StartInfo.Arguments = switches ++ url ++ fileName;
p.Start();

提前感谢

解决方案好的,在阅读你的评论之后,这是修改后的版本。
Ext JS是一个客户端库,因此您需要在浏览器中运行它来获取图表,这不能被更改。如果您真的需要在服务器上获取这些图表,那么您必须采取一些或多或少的肮脏的黑客。其中一个是:


  1. 准备一个只包含PDF中包含的图表的特殊网页

  2. 使用wkhtmltoimage程序将其转换为图像文件(在服务器上)

  3. 使用iTextSharp



  4. 但在这种情况下,我宁愿重新考虑工具的选择或生成报告的方式。


    i have several charts in my extjs4application dashboard.. i want to generate a pdf report using the images of those charts for that i use iTextSharp

    is there a way to get the images from the charts in order to include them in my report?

    the ideal for me is to use it like this with itextsharp

    MyImageStream = new MemoryStream();
    myChart.SaveImage(MyImageStream);
    

    my chart would be the chart object

    i asked around in the forums they told me i would generate and render my chart at client (already done) and then i would get the svg, send it to the server and server would use it to generate the pdf... but i dont know how to work with svg neither how to send it to server

    EDIT

    im trying to use wkhtmltoimage to save my chart into image

    but its not working whan i specify a mapPath to my .aspx

    but it works fine if i specify a website url or localhost path (see htem in comment)

    by doesnt work i mean no error but no png created!

    my code:

    var url = HttpContext.Current.Server.MapPath("~/chartImage.aspx");//dosnt work
    //works : // "google.com";  //"localhost/chartImage.aspx";//
            var fileName = " pie13.png ";
            var wkhtmlDir = HttpContext.Current.Server.MapPath("~/wkhtmltopdf/pdf/");//"C:\\Program Files\\wkhtmltopdf\\";
            var wkhtml = HttpContext.Current.Server.MapPath("~/wkhtmltopdf/wkhtmltoimage.exe");//"C:\\Program Files\\wkhtmltopdf\\wkhtmltopdf.exe";
            var p = new Process();
    
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.FileName = wkhtml;
            p.StartInfo.WorkingDirectory = wkhtmlDir;
    
            string switches = "";
            //switches += "--print-media-type ";
            //switches += "--margin-top 10mm --margin-bottom 10mm --margin-right 10mm --margin-left 10mm ";
            //switches += "--page-size Letter ";
            p.StartInfo.Arguments = switches + " " + url + " " + fileName;
            p.Start();
    

    thanks in advance

    解决方案

    Ok, here's a revised version after reading your comment above. Ext JS is a client side library so you need to run it in a browser to get your charts and this can't be changed. If you really need to get these charts on the server then you must resort to some more or less dirty hacks. One of them would be:

    1. Prepare a special web page that contains only the chart to be included in the PDF
    2. Use wkhtmltoimage program to convert it into an image file (on the server)
    3. Insert that image into PDF document using iTextSharp

    But in this case I'd rather re-think the choice of tools or the way reports are generated.

    这篇关于如何保存Extjs4图表图像以pdf报告打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆