Select to view content in your preferred language

Export Report To PDF

1250
2
Jump to solution
10-15-2021 08:03 AM
MichaelKohler
Frequent Contributor

Developing and ArcPro add in and cant get the ExportToPDF to work for my report. I can export it from Share->ExportReport no problem. But doesn't work in code. No errors or anything. Code runs through just fine but no pdf is ever created. I found the code here:

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Reports#export-report-to-pdf

 

Below is the code being used.

 

private async void CnclReport_Click(object sender, RoutedEventArgs e)
        {            
            System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog1.Filter = "PDF File|*.pdf";
            saveFileDialog1.Title = "Save a PDF File";
            saveFileDialog1.FileName = "CouncilReport.pdf";
            saveFileDialog1.ShowDialog();

            if (saveFileDialog1.FileName != "")
            {
                await QueuedTask.Run(() =>
                {
                    ReportProjectItem reportProjItem = Project.Current.GetItems<ReportProjectItem>().FirstOrDefault(item => item.Name.Equals("CouncilReport"));
                    Report report = reportProjItem?.GetReport();
                    var exportOptions = new ReportExportOptions
                    {
                        ExportPageOption = ExportPageOptions.ExportAllPages,
                        TotalPageNumberOverride = 0
                    };                    
                    PDFFormat pdfFormat = new PDFFormat();
                    pdfFormat.Resolution = 300;
                    pdfFormat.OutputFileName = saveFileDialog1.FileName;
                    report.ExportToPDF("CouncilReport", pdfFormat, exportOptions, false);
                });
            }            
            else
            {
                MessageBox.Show("Please provide a file name");
            }
            MessageBox.Show("exported");
        }

 

-edit

Instead of trying to do it that way, I used a GP Tool. Found this from:

https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Geoprocessing

var progDlg = new ProgressDialog("Exporting Council Report", "Cancel", 100, true);
progDlg.Show();
var progsrc=new CancelableProgressorSource(progDlg);
var parameters = Geoprocessing.MakeValueArray("CouncilReport", saveFileDialog1.FileName);                
await Geoprocessing.ExecuteToolAsync("management.ExportReportToPDF", parameters, null, new CancelableProgressorSource(progDlg).Progressor, GPExecuteToolFlags.Default);
progDlg.Hide();

 

 

 

 

 

 

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi Michael,

As a work around, please specify the full path (including the filename) to the ExportToPDF method.  This works for me.

Looks like "OutFileName" property on the PDFFormat is being ignored. I will follow up on this one with the Report team.

 

Thanks!

Uma

 

report.ExportToPDF($@"C:\Users\UserName\Documents\ArcGIS\reportnew.pdf", pdfFormat, exportOptions, false);

 

Thanks

View solution in original post

0 Kudos
2 Replies
UmaHarano
Esri Regular Contributor

Hi Michael,

As a work around, please specify the full path (including the filename) to the ExportToPDF method.  This works for me.

Looks like "OutFileName" property on the PDFFormat is being ignored. I will follow up on this one with the Report team.

 

Thanks!

Uma

 

report.ExportToPDF($@"C:\Users\UserName\Documents\ArcGIS\reportnew.pdf", pdfFormat, exportOptions, false);

 

Thanks

0 Kudos
MichaelKohler
Frequent Contributor

yes... it was "OutFileName" in quotes instead of the variable. Thanks.

0 Kudos