mxgraph : svg image not exported in pdf or png - mxgraph

I am working with the very good mxgraph library. I base my application on the GraphEditor example.
I have used my own PNG icons. Everything works well. For a better rendering I want to use SVG images. I have tried to remplace PNG image by SVG image, it's working well in the javascript : I can drag and drop, then resize ... I can save and open correctly.
But if I try to export in PNG or PDF, the SVG images or not exported (the rest of the diagram is OK).
I tested SVG images on draw.io and it is correctly exported.
Is there any option or parameter to fix that ?
I looked to another request : SVG shapes instead of stencils
The solution might be with mxImage but I can't find how to use it.
Any help welcome.

Related

Q: ThreeJS Repeat Texture in threejs Editor Strange Behaviour

enter link description hereAs you can see in the attached images, the materials, doesn't repeat in all the area but only in a partial part (upper left). Any suggestion is very appreciated.
I'm using three js editor r.85
Image of the rendered file in threejs editor.
Image of the rendered file open by normal html file.
Json file used (updated 05/28/2017)
Image (512x512)

How to include png as backgound image without downloading anything else than HTML?

I am generating one html file. The file should display 3 divs. Each div will have:
background-image: url("something.png");
Now, when user will download the file (e.g. chooses "save page as"), he will only get the HTML - without the actual png file.
How can I make sure that he is able to see them, without making him download them?
I've tried converting to SVG, but this pictures have multiple colors, and it totally failed.
You could just make it data-based, i.e.
background:url(data:image/png;base64,base64-encoded-image-goes-here)
It is possible to have jpg, gif, etc.
You can get the base64 image by using an image-to-base64 converter.

SVG map copied but not showing

I copied an SVG map at the end of this page, that is map of Iran and I want to use it in my website.
I copied its code and paste it in a file what named map.svg and when I open it by Firefox that just show me the svg source!
How to copy that source that show me the map?
I cannot post a comment because of my reputation level, but the svg you're trying to copy is working perfectly for me
make sure you copy everything between and including the tags <svg> .. </svg>
you will not get the styling and events, just a black SVG map

Convert rendered HTML 5 display (visible and invisible) to image when using HTML 5 canvas

Is there source code (or a browser plugin) to convert the contents of an HTML 5 web page to an image file? This would not just include the visible contents, but the hidden contents as well (assuming there were scroll bars in the page). If there isn't, any advice on how to approach this particular functionality would be appreciated, and I can look into it.
I found this...
html to jpg with c#
However...
I think they just had text in the page, so it doesn't have any dynamic images on the page. My page specifically uses the HTML 5 canvas functionality to draw images. So that must be part of the image file.
It looks like you should be able to do it using javascript with this technique:
http://www.html5canvastutorials.com/advanced/html5-canvas-save-drawing-as-an-image/
Make sure to take note of the following caveat however:
Note: The toDataURL() method requires that any images drawn onto the canvas are hosted on a web server with the same domain as the code executing it. If this condition is not met, a SECURITY_ERR exception is thrown.
EDIT: You may also want to check out these related questions:
Save HTML5 canvas contents, including dragged-upon images
How to save a HTML5 Canvas as Image on a server

Copy SVG Images from Browser to Clipboard

I am developing a web application which takes user inputs, does engineering calculations and then shows a formatted report or graphic. The graphics are engineering diagrams and not always standard graphs like Pie charts. The primary function of the application is to enable the user to copy these diagrams from the browser to a Word or Excel document.
I have to make a choice on using SVG generated in the client, or bitmaps generated on the server side. I prefer the SVG approach and the prototyping looks good, however, copying the SVG graph seems to be inconsistently supported across browsers, especially if the graph is shown in a div (i.e. the entire page is not .svg). For example, IE shows a "copy" on the dropdown, but copies only part of the SVG graphic to the clipboard. Chrome gives no copy option if I right click on the SVG graphic.
If I Google around, I am surprised to see how little information there is on the problem of getting an SVG image from a web application onto the clipboard.
My question for readers who have worked through this problem:
Is there a consistent way to get an SVG element that is part of a
larger DOM onto the clipboard, preferably using JavaScript;
Any other recommendations given my requirement of getting graphics
from browser onto clipboard?
Instead of displaying the svg as an svg element display it with the img tag. This has some limitations (you can't display custom fonts or embed scripts, but it seems this is not your use case). The upside is that is behaves exactly as you would expect from an image (you can drag and drop, right click and copy, etc).
To do this you need to encode it with base64. You can do it server side or client side with js. Your image tag ends up looking something like...
<img src="data:image/svg;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolf" width="..." height="..." alt="diagram" />
Where R0lGODlhEAAQAMQ... is your base64 encoded svg.
Javascript and the Clipboard is a pain in the a**.
There is one workaround for your situation that I know of:
If it is a true SVG file, in Chrome, right click on the image, and select "Inspect Element".
The browser console will open, and should open to an SVG element that you can select in the inspector.
Right click the svg tag in the inspector, and select 'Copy' or 'Copy as HTML' (I can't recall the choices exactly)
Paste that text into a text file and then save the file with an SVG extension. It can then be opened in any browser or SVG editing program. Inkscape is a good choice for editing and debugging, as you can view and edit the entire SVG file in an XML style editor.
**Sorry - I missed the first part of your request. That will be tricky. I'm afraid I can't help with that part. Copy and paste probably isn't your best option though. There are PHP classes to both manipulate SVG and Excel files, and that will likely be the way to go.
I managed to copy SVG content to clipboard as plain XML text, but it appeared useless for me, because Inkscape (which I use to work with SVG), doesn't recognize the text in clipboard as SVG. It appears that copying text of SVG is not enough and the browser should also set the mime-type to image/svg+xml.
I tried several tricks with HTML5 Clipboard API, but ended with the problem that Chrome is unable to export the mime-type into system clipboard. The relevant bug report and jsfiddle link for it is here https://code.google.com/p/chromium/issues/detail?id=504700
I faced the same problem in a project. The customer wanted to have a rather complicated chart. We decided to develop it using svg. Worked perfect, but the customer wanted to be able to download the graph as a picture. After a search on the internet, we found saveSvgAsPng (https://www.npmjs.com/package/save-svg-as-png). That did the trick for us.
The graph is in the page like this:
<svg id="graph1" style="width: 700px; height: 700px">
....
.....
...
</svg>
The graph is shown, but can't be downloaded or copied. So, here are the steps I took:
I installed the package mentioned above.
<script src="/path/to/lib/save-svg-as-png/lib/saveSvgAsPng.js"></script>
Added "display: none:" to the svg code, otherwise we will have two instances of the same image:
<svg id="graph1" style="width: 700px; height: 700px; display: none">
<!-- // code goes here -->
</svg>
Directly after the declaration of the svg graph, I added a new image. This image, is the placeholder for the new png image representation for the svg image. I hide it on first, to prevent the image from flickering while loading. The source is initially not specified:
<img id="graph1_as_png" src="" width="700" height="700" style="display: none">
After the newly added image, I added some lines of code, that to the conversion trick:
<script>
svgAsPngUri(document.getElementById("graph1")).then(uri => {
$("#graph1_as_png").attr('src', uri).show();
});
</script>
The source of the second image is filled up with a BASE64 encoded version of the svg. After the conversion, the image is shown. Now we have exactly the same image as our svg image, but with the possibility to download or to copy the image.
I hope this will help you as wel..