Jump to content
We've recently updated our Privacy Statement, available here. ×
  • How to export an analysis to PDF using IronPython in Spotfire®


    This article provides a code snippet to export an analysis to PDF using IronPython.

    This article provides a code snippet to export an analysis to PDF using IronPython.

    Use the below method:

    Document.Export Method

    It is not straightforward to do this before Spotfire 7.5, because it tries to execute a progress operation inside an existing transaction. Spotfire 7.5 has a checkbox on the IronPython editor that you can uncheck to prevent the script from executing inside a transaction. The script below should work in the versions prior to 7.5 .

    # Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
    
    # 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:datafilestestfile.pdf"
    pdfexpsettings = PdfExportSettings()
    pdfexpsettings.Scope = ExportScope.ActivePage
    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.
     

     

    Changes in Spotfire 7.12

    TIBCO Spotfire® 7.12 has new capabilities for exporting to PDF. See What's New in Spotfire® and TIBCO Spotfire® 7.12 - APIs for exporting and rendering visualizations for details

    The following the APIs has been added:

    A new Action available in Text Area Action Controls, letting the author create a button, link or image and select a corresponding Prepared Report, which will be exported if a user clicks on the control.

    converted-file.png.e870d3a23cd5a7531f9c7390ba345c8b.png

    It is also possible to get the same result with an Action Control that runs a IronPython script:

    # Copyright © 2019. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
    
    from Spotfire.Dxp.Application.Export import Report
    
    # Get the prepared report
    result = Application.Document.TryGetReport("Weekly Sales report")
    
    # Check result
    if result[0] == True:
    
    	# Export the PDF
    	report = result[1]
    	exportResult = report.ExportToPdf("c:Sourcetest.pdf")
    
    	# Check result
    	if exportResult != True:
    		print 'export failed'
     

     

    The TIBCO Spotfire® 7.12 - APIs for exporting and rendering visualizations article has an attached DXP file that illustrates both how to use the "Export Report" action and an IronPython script to export a report saved in the analysis.

    See also

    References

    License:  TIBCO BSD-Style License

    Back to IronPython Scripting in Spotfire Examples


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...