Recent Spotfire versions include the ability to export visualizations, pages, or the entire analysis into a PDF from the File menu or even with an Action Control button. Finally! Version 7.12 includes extremely user friendly customization options while previous versions require some IronPython code: we will address both here.
The 7.12 version gives the user an interface for customization that we could previously only access via IronPython. Spotfire has delivered what many users for years have clamored for, so check it out after the break…
Version 7.12 (and presumable beyond)
Version 7.12 provides users a very friendly interface to customize Export to PDF options: which visualizations to display, what they will include, how they will appear, etc. Further, users can save the report parameters as a template and produce that exact report with an Action Control button.
To set the report options, go to File > Export > To PDF. You can choose from very straightforward options like whether page numbers should appear, page layout, margins, and image quality. You can either export from that window or select Prepared report in the What to Export section. When You create a new report You have several of the same options as well as the ability to click which visualizations You will export.
Once we export the report, Spotfire will save that report style, which we can then call from an Action Control button. To create the Action Control button, go to any text area and right-click > Edit HTML > click the Insert Action Control icon . You will then get the following window.
See that pretty little Export Report icon?! Select it, type in your report name, select your available report, click OK, then it will ask for your file location to save to. That’s it! It’s that easy!
Now, for those of you with earlier versions still having to toil in IronPython, don’t worry. The script is a fairly simple one and only requires one or two lines of customization…
Pre 7.12 Versions
First, set up the Ironpython button as we did in the 7.12 version. In any text area, right-click > Edit HTML > click the Insert Action Control icon . Of course, you won’t have the Export Report option, so select the Script option. Give the Action Control a name, then click New.
Now, you will see the Script window. Put in a Script name, then copy and paste the code at the bottom of this post, which was first posted by Tibco. We need to customize just a couple of items:
- Change the line that starts with “fileName” to have your file destination within the quotation marks. If you copy and paste, make sure the text uses backslashes (\) and not forward slashes.
- Note the line: pdfexpsettings.Scope = ExportScope.ActivePageOnePagePerVisualization. That dictates that the button will print all visualizations on the current page–one per PDF page. You can replace the text after “ExpertScope.” with ActiveVisualization, ActivePage, AllPages, AllPagesOnePagePerVisualization, or DetailsOnDemand. Luckily, Tibco made these calls pretty self explanatory.
That’s it! Click OK twice and a button should appear in the text area that exports to pdf to the location you chose.
# Import namespaces from Spotfire.Dxp.Framework.ApplicationModel import ApplicationThread from Spotfire.Dxp.Application.Export import PdfExportSettings from Spotfire.Dxp.Application.Export import ExportScope from Spotfire.Dxp.Application.Export import PageOrientation from Spotfire.Dxp.Application.Export import PaperSize from Spotfire.Dxp.Application.Export import ExportScope # Declaring the function which will run async def g(app,fileName,pdfexpsettings): def f(): app.Document.Export(pdfexpsettings,fileName) return f # Set the file name fileName = "C:\Users\JMay\Desktop\\testfile5.pdf" pdfexpsettings = PdfExportSettings() pdfexpsettings.Scope = ExportScope.ActivePageOnePagePerVisualization pdfexpsettings.PageOrientation = PageOrientation.Landscape pdfexpsettings.IncludePageTitles = False pdfexpsettings.IncludeVisualizationTitles = False pdfexpsettings.IncludeVisualizationDescriptions = False pdfexpsettings.PaperSize = PaperSize.A4 pdfexpsettings.PageOrientation = PageOrientation.Landscape # Executing the function on the application thread, and Save the document back to the Library Application.GetService[ApplicationThread]().InvokeAsynchronously(g(Application, fileName,pdfexpsettings)) # Note: # The function g is necessary because the script's scope is cleared after execution, # and therefore Application (or anything else defined in this scope) will not be available # when the code invokes on the application thread.
Jason is a Data Scientist at Ruths.ai with a master’s degree in Predictive Analytics and Data Science from Northwestern University. He has experience with a multitude of machine learning techniques such as Random Forest, Neural Nets, and Support Vector Machines. With a previous Master’s in Creative Writing, Jason is a fervent believer in the Oxford comma.