Select to view content in your preferred language

Unable to Generate PDF Reports with Python

111
3
Tuesday
ColtonSnelling1
New Contributor II

I am trying to automate the report generation of a survey123 survey.

I have tried both in my orgs AGOL Notebooks as well as in a dedicated python IDE (PyCharm in this case, changing the GIS parameters accordingly).

The Notebook keeps saying it is generating a zip in a tmp location.  I cannot find that location, and I need it to output PDFs not in a zip file.

 

Here is my code:

import arcgis
from arcgis.gis import GIS
gis = GIS("home")

survey_manager = arcgis.apps.survey123.SurveyManager(gis)
survey_by_id = survey_manager.get("mySurveyID")

template = survey_by_id.report_templates[0]
pdf_report = survey_by_id.generate_report(template, output_format="pdf")
print("Single report as PDF: ", pdf_report)

ColtonSnelling1_0-1721767902594.png

 

 

Tags (4)
0 Kudos
3 Replies
ClayDonaldsonSWCA
Occasional Contributor II

You are missing a couple of parameters to help control the output.

  • Review the SurveyManager.generate_report docs
    • You should specify a `where` parameter, otherwise it will return a zip file of all records
    • You should also use the `save_folder` parameter to specify where it should be saved
0 Kudos
ColtonSnelling1
New Contributor II

If I am always generating/downloading at least 2 reports at a time, is it always going to be a zip file?

0 Kudos
ClayDonaldsonSWCA
Occasional Contributor II

yes if your query is set-up that way. Two solutions to that:

  • Set up another function to query the data and get a list of object ids. Then use a `for` loop to generate a single report per objectid. (doesnt have to be object id, could be any unique value)
  • Use python module zipfile to extract the pdfs
0 Kudos