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();
Solved! Go to Solution.
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
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
yes... it was "OutFileName" in quotes instead of the variable. Thanks.