Hello all - I am trying to create a plug in button in Pro that takes the current layout view and exports the layout to the desktop. When I go to press the button the code runs with no problem but I am not receiving any output. If anybody could help - I would really appreciate it. Thank you.
Code below.
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Layouts;
using ArcGIS.Desktop.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ArcGIS.Desktop.Internal.Core.PortalTrafficDataService.PortalDescriptionResponse;
namespace Export_Button
{
internal class Button1 : Button
{
protected override async void OnClick()
{
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout"));
Layout layout = await QueuedTask.Run(() => layoutItem.GetLayout());
String filePath = "//map.pdf";
// cref: ArcGIS.Desktop.Layouts.Layout.Export
// cref: ARCGIS.DESKTOP.MAPPING.PDFFORMAT
// cref: ARCGIS.DESKTOP.MAPPING.EXPORTFORMAT
// cref: ARCGIS.DESKTOP.MAPPING.EXPORTFORMAT.VALIDATEOUTPUTFILEPATH
// cref: ArcGIS.Desktop.Mapping.PDFFormat.ImageCompression
// cref: ARCGIS.DESKTOP.MAPPING.PDFFORMAT.IMAGEQUALITY
// cref: ARCGIS.DESKTOP.MAPPING.PDFFORMAT.LAYERSANDATTRIBUTES
// cref: ARCGIS.DESKTOP.MAPPING.ImageCompression
// cref: ARCGIS.DESKTOP.MAPPING.ImageQuality
// cref: ARCGIS.DESKTOP.MAPPING.LayersAndAttributes
#region Layout_ExportPDF
//Export a layout to PDF
//Create a PDF export format
PDFFormat pdf = new PDFFormat()
{
OutputFileName = filePath,
Resolution = 300,
DoCompressVectorGraphics = true,
DoEmbedFonts = true,
HasGeoRefInfo = true,
ImageCompression = ImageCompression.Adaptive,
ImageQuality = ImageQuality.Best,
LayersAndAttributes = LayersAndAttributes.LayersAndAttributes
};
//Check to see if the path is valid and export
if (pdf.ValidateOutputFilePath())
{
layout.Export(pdf); //Export the PDF
}
#endregion Layout_ExportPDF
}
}
}