How to save an image of an Extjs4 chart for printing in a report in PDF format?

I have some diagrams in the extjs4application toolbar. I want to create a pdf report using the images of these diagrams for this I use iTextSharp

Is there a way to get images from charts to include them in my report?

The ideal for me is to use it like this: itextsharp

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

my chart will be a chart object

I asked in the forums where they told me that I will generate and display my diagram on the client (already done), and then I will get svg, send it to the server, and the server will use it to generate pdf ... but I I don’t know how to work with svg nor how to send it to the server

EDIT

im trying to use wkhtmltoimage to save my chart to image

but it doesn’t work when I specify mapPath for my .aspx

but it works fine if I provide the website url or localhost (see htem in the comment)

does not work, I mean the lack of error, but not created png!

my code is:

 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(); 

early

+2
source share
3 answers

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

  • Prepare a custom web page containing only the chart to be included in the PDF
  • Use the wkhtmltoimage program to convert it to an image file (on the server).
  • Paste this image into a PDF using iTextSharp

But in this case, I would prefer to rethink the choice of tools or the way to create reports.

+2
source

Use the wkhtmltopdf package (http://code.google.com/p/wkhtmltopdf/) to convert the web page with your diagrams to a pdf file, and then allow users to download this pdf file. To do this, you need to run the wkhtmltopdf server side (pay attention to authentication / user impersonation). Since wkhtmltopdf is based on Safari, it should work with extjs without any problems.

+1
source

I am studying this, I think you first need to convert the chart to an image, and then use the PDF generator library and include this picture in it. To convert a chart to a picture: http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/charts/Area.js

To generate a PDF in C #, if you use it on the server side, it could be a pdfsharp or itext file

0
source

Source: https://habr.com/ru/post/1386321/


All Articles