Hi
I have a web service that needs to generate and return an svg image.
What’s the best way to generate the contents of a WebContainer as svg and return it from handleURL?
The container has labels, rectangles and imageviewers with bootstrap icons and a webchart.
Can I do it with Xojo? Do I need a plugin?
You might be able to get close to what you need with a foreignobject, but it’s not going to be as simple as just cloning a WebContainer’s DIV
element on the page, putting it in an SVG element definition, and having it appear identical outside the web app’s DOM. You’d also need all of the CSS that makes it appear the way it does within the context of a Xojo application. You’re also not going to have anything to return in HandleURL as it’s session-less.
What is your end goal? Why SVG? You could generate a PDF and return that, if you’re looking for high resolution embeddable object, or create a Picture and return that.
Thanks for that information!
.
I really was expecting to be able to get the container to draw itself, but I realised web containers don’t support drawinto.
I thought an svg would be the way to go, but maybe not.
A picture could work if I convert the bootstrap icons and store locally, but can I generate a picture of a web chart?
Do I need to have a session? There’s no state.
The web service is an API to generate a one off request from an 3rd party website, to display in a block, so PDF isn’t an option.
A picture could work if I convert the bootstrap icons and store locally, but can I generate a picture of a web chart?
Yeah, not really. I mean, it can be done, but you’d render the chart in the browser then there’s ways to export it as an image to send back, then you’d draw it and send the picture. It’s not going to work for what you’re trying to do. All asynchronous and would take a long time.
Do I need to have a session? There’s no state.
In order to have a WebContainer rendered in a meaningful way, yes.
The web service is an API to generate a one off request from an 3rd party website, to display in a block, so PDF isn’t an option.
I’m wondering if Web is the right path since you need to do some heavy drawing. It can be done, but you’re not going to easily get the image of the chart without drawing it yourself. You could create a Desktop application that your Web app shells out to for creating a chart image using the DesktopChart, but that’s pretty messy and again would take time that the other endpoint might not wait for. Plus it would require a desktop be available on the server.
Thanks Anthony, I appreciate your help! I’ll look for another solution.
Michelle,
For generating a return file of substantial size, what Anthony s suggesting should be considered. You can further detail it as follows:
-
Step 1 : User request the creation of the SVG through web service. assign a unique id for this request. Store this in a database at the server. Say this request as Rx.
-
A desktop applications will run continuously at the server, browsing through the database table entry looking for an SVG creation request. When it found a request which has not been fulfilled ( in this case Rx), the desktop app will fulfill it. This can be further detailed as either the desktop app it self will draw or it will launch helper apps to create the SVG. The file is then created and stored ( either directly in the database or is stored in the server with the location stored in the database)/ The status for the request Rx is then updated with the status completed.
-
Web user, after certain time, request for the status of Rx. If it has been completed, then the user should request to pull the file via webservice by giving the request id Rx.
Many more improvement can then be explored ( eg: notification to the requesting user via email or notification services ) to inform them that the SVG file creation request is completed.
Hi Hanif, thanks for your suggestions. That’s really useful!
I’ll go back to the client and discuss possible scenarios and work out a plan.