Business Intelligence Tools / Developers Corner

Exporting Spotfire to PDF with Action Control Button

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:

  1. 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.
  2. 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.


3 thoughts on “Exporting Spotfire to PDF with Action Control Button

  1. chelsea Reply

    If I wanted an action button that exported to PPT instead of PDF, could I use the “pre-7.12 version” script instructions for PDF export but change the syntax a little? If so, what would the syntax be for PPT? For instance, would it just be replacing PdfExportSettings with something like PptExportSettings?

  2. Katya Huster Reply

    Our company is using 7.11
    We have a request to have one click functionality to export to pdf to fit the entire cross table into one page.
    Manually the procedure is Export >to PDF >Active Visualization > Export the entire table.
    I could not find the correct methods and properties for this.
    Could you advise please?

    Thanks,
    Katya

Leave a Reply

Your email address will not be published. Required fields are marked *