# Saving a Report on Button Press

**URL:** <https://forum.inductiveautomation.com/t/saving-a-report-on-button-press/81347>\
**Category:** Ignition\
**Tags:** ignition81, scripting, vision, reporting\
**Created:** [November 2, 2023, 4:33am UTC](https://forum.inductiveautomation.com/t/saving-a-report-on-button-press/81347 "2023-11-02T04:33:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ASG\_Nic](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@ASG\_Nic](https://forum.inductiveautomation.com/u/ASG_Nic)\
**Post date:** [November 2, 2023, 4:33am UTC](https://forum.inductiveautomation.com/t/saving-a-report-on-button-press/81347/1 "2023-11-02T04:33:23Z")

</div>

I'm trying to create a button in Vision that functions like a 'save as' for PDF reports.  
My report is correctly configured and I can get it to generate and save on button press to a static location, but I want it to prompt the user for a file name, and location to save the report. I have this functionality for CSV files from a table and am trying to replicate this as a PDF. I'm sure it is something simple that i am missing.

im hoping to use [system.file.saveFile](https://docs.inductiveautomation.com/display/DOC81/system.file.saveFile) or even [JFileChooser](https://docs.oracle.com/javase/8/docs/api/javax/swing/JFileChooser.html) but i get stuck at the same point with both options. I can successfully prompt the user for a location but it saves the PDF within another folder rather than the straight PDF.

```auto
# Get the current date
today = system.date.now()

# Define the fileDate based on the current date
fileDate = system.date.format(today, "yyyy-MM-dd")
reportName = "Alarm_History_" + fileDate + ".pdf"

# Display a file dialog to save the PDF report
filePath = system.file.saveFile(reportName, ".pdf", "PDF Files")

if filePath:
    reportParameters = {"StartDate": system.date.addHours(system.date.now(), -24), "EndDate": system.date.now()}
    settings = {"path": filePath, "format": "pdf"}

    # Execute and distribute the report to the specified path
    result = system.report.executeAndDistribute(path="Alarm_History", project="DEV_RPF2_MKVI", parameters=reportParameters, action="save", actionSettings=settings)

    # Check if the report execution was successful
    if result:
        print("PDF report saved to: " + filePath)
    else:
        print("Report generation and distribution failed.")
else:
    print("User canceled the file selection. Report generation and distribution canceled.")

```

any assistance would be greatly appreciated.

on a side note is it possible to restrict the system.save.file window so files can't be deleted?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 2, 2023, 11:46am UTC](https://forum.inductiveautomation.com/t/saving-a-report-on-button-press/81347/2 "2023-11-02T11:46:58Z")

</div>

Don't use `executeAndDistribute()`. Use `system.report.execute()` to return the PDF bytes, and save the file yourself (because it is Vision).
