MxGraph - Export Diagram using JavaScript - mxgraph

In MxGraph when export the diagram we are passing the XML value to server side and convert into image.
Is there any option in Javascript (client side) to export the diagram, means convert the Graph xml to jpeg or png image using front end (Javasript) only.

As you know, mxgraph is rendered as a svg. You can either either us this svg directly or use any library to convert this to png. In react, I have used 'save-svg-as-png' library to convert svg to png

Related

Angular Base64 file upload as JSON

I'm trying to create a reusable directive in my app that allows for files to be encoded as base64 then uploaded via JSON.
I haven't seen my resources on the web talking about this approach. I've mostly only been able to find Angular file uploads via form data.
Can anyone shed some light on this topic?
This link
may prove interesting.
Basically he state that Base64 encoded data is 33% larger and takes longer to process than binary.
htmltrocks has an interesting
article regarding integrating the canvas element into your App.
It shows use of the HTML5 canvas toDataURL() method which converts to Base64.
See also:
How to convert image into base64 string using javascript

Convert html 5 to PDF in MVC 3

I have created an application in asp.net MVC 3, I used highchart.js for rendering chart(stacked column) in view and its output is coming as svg.
I need to convert this chart page into PDF file. I tried iTextSharp but its not showing the chart page content.
Is there anyway to convert html 5 to PDF?
ExpertPDF is a nuget package you can install. For it to work without putting text over your pdf, you'll have to purchase a license. It can handle svg.
http://www.html-to-pdf.net/ExpertPDF-HtmlToPdf-Converter.aspx
You can also use a webkit component such as HTM2PDF to render HTML to PDF - see an explanation here:
Highcharts to PDF with Webkit
If you just want to convert svg to image then you can use PhantomJS (headless webkit browser). With help of PhantomJS you can render svg and make screenshot. Then you can create a PDF and insert that image into it.
Also you can Aspose.Pdf for converting svg into PDF directly. See: http://www.aspose.com/.net/pdf-component.aspx (it's a paid component!)

Converting .doc/docx in to Html

I know that Word have option to save the document into web page, but what is produce as result doesn't suit my needs.
I want my document to be save as web page with separate folder, which include images and .css files. But the Word only include the images not the css file.
How can I achieve this with Word or some other tool (need to be free)?
Given that Java is your preferred language, you could try docx4j [disclaimer: I manage it].
See the CreateHtml sample.
Note: docx4j supports docx only (as opposed to legacy binary .doc; those can be converted using LibreOffice).

How can I show a TGA image in a <img> tga?

I have a TGA image encoded in Base64
https://gist.github.com/984770
But it doesn't show on the browser.
Is there a way to show a TGA image on the browser or it is not supported? Is there any client side technology I could use to achieve this?
It's not supported.
I assume there probably are Java or ActiveX plugins that can do it, but it's going to be complicated, cumbersome, have spotty support, and of course won't work with base64 data.
If it's just a few images, consider converting them to JPG, PNG or GIF manually, depending on what type of image they contain.
If it's many images and you need an automated solution, a good way would be to employ a server-side script that calls e.g. ImageMagick, and creates a JPG thumbnail from the image.
You could easily send the base64 data to the script using Ajax for example, receive the name of the converted file in return, and create an <img> element pointing to it.

HTML Canvas and saving the data on the server

Say I've written a simple app that draws circles in browser. Now I'd like to let people save their pictures. How would I store the data on the server? Which format would be the best option? Should I simply store the relevant html? What would be the case when I would want to make a custom format that is stored on the server and parsed back to html canvas when loaded?
How would I store the data on the server?
Which format would be the best option?
Since they are just circles, you probably just need starting coordinate, size, line thickness, and colour. Sounds like its easy enough to store with SQL.
Should I simply store the relevant html?
What HTML? Drawings on canvas are not exposed in the DOM. That's why canvas is (currently) awful for accessibility (unlike SVG).
What would be the case when I would want to make a custom format that is
stored on the server and parsed back to html canvas when loaded?
I'd transport it as JSON and then loop over the dataset with JS to redraw it.
canvas.toDataURL should allow you to do such things. check out canvaspaint.org's source code to see how to save on local computer and on server.
This might help: Save a <canvas> as a file in a form.
This demo shows how to save locally -- though, for me at least, Save PNG (etc.) work in Firefox but not Chrome.