How export JavaScript visualizations to PNG properly? 

Hi everyone! I have had some troubles when exporting visualizations type JsViz. 

Apparently, it exports the visualization without rendering the js script first, and the result only shows the canvas with the initial HTML/CSS structure. In the image exported, the visualizations look the same as when I click the option 'Suspend Rendering' in the tab 'Rendering' from JS Visualization Properties. 

Besides, I incremented the 'Export Delay' just in case, but it doesn't work either.

 

I am using other libraries in addition to JSViz, like Chart.js; I don't know if the problem could come from that. 

 

I tried to do this via File/Export/... and also via IronPython scripting with the code below, but the problem persists in both cases.  

import sys
from System.IO import *
from Spotfire.Dxp.Application.Visuals import *
from System.Drawing import Size, Image
from System.Drawing.Imaging import ImageFormat
from System.Threading import CancellationToken 
from System.Threading import Thread
from Spotfire.Dxp.Framework.ApplicationModel import ApplicationThread


app = Application.GetService[ApplicationThread]()
pages=Document.Pages

# RenderResultSettings
rsettings=RenderResultSettings(Size(1225,700))
rsettings.Resolution=ImageResolution.High


#VisualRenderSettings
vsettings=VisualRenderSettings()
vsettings.ShowTitle=Visibility.Visible


#PageRenderSettings
psettings=PageRenderSettings()
psettings.ShowTitle=Visibility.Visible
psettings.VisualRenderSettings=vsettings

def asyncshot(pages):

	def f():

		for page in pages:
			#print page.Title
			Document.ActivePageReference = page
			for visual in page.Visuals:
				try:

					renderResult=visual.RenderAsync(rsettings,vsettings,CancellationToken(False))
					if renderResult.Result.IsValid:
						image=renderResult.Result.AsImage()
						#print type(image)
						#image.Dispose()
		
						tempFolder = Path.GetTempPath()

						print tempFolder

						image.Save(tempFolder+page.Title+visual.Title+".bmp")
		
				except Exception , e:
					print 'Error: ' + e.ToString()

		
	return f()
	

app.InvokeAsynchronously(asyncshot(pages))

Also, I tried this code (with 'Render' method which is deprecated), but it gave me a similar result. 

from System.IO import *
from Spotfire.Dxp.Application.Visuals import VisualContent
from System.Drawing import Bitmap, Graphics, Rectangle, Point

for visual in Document.ActivePageReference.Visuals:
    #print visual.Title

    #export graphic to temp file
    vc = visual.As[VisualContent]()
    bm = Bitmap(2000, 1200)
    g = Graphics.FromImage(bm)
    r = Rectangle(Point(0,0), bm.Size)
    vc.Render(g, r)
    file = Path.GetTempFileName()
    print(file)
    bm.Save(file)



 

1 Comment

Did you ever find an answer to this?

colt.street - Jun 13, 2019 - 11:23am ::
+ Add a Comment
Login