Password Property (PDFFormat)
Gets or sets the password to protect the file. The password will need to be entered when the file is opened.
public string Password {get; set;}
Public Property Password As String
ExportPDF_Layout
//This example demonstrates how to export a layout to PDF.
//Added references
using ArcGIS.Desktop.Core; //Project
using ArcGIS.Desktop.Layouts; //Layout classes
using ArcGIS.Desktop.Framework.Threading.Tasks; //QueuedTask
using ArcGIS.Desktop.Mapping; //Export formats
public class ExportLayoutToPDFExample
{
public static Task ExportLayoutToPDFAsync(string LayoutName, string Path)
{
//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
if (layoutItem == null)
return Task.FromResult<Layout>(null);
//Create PDF format with appropriate settings
PDFFormat PDF = new PDFFormat();
PDF.Resolution = 300;
PDF.OutputFileName = Path;
//PDF.Password = "xxx";
return QueuedTask.Run(() =>
{
//Export Layout
Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem
if (PDF.ValidateOutputFilePath())
{
lyt.Export(PDF);
}
});
}
}
ExportPDF_MapFrame
//This example demonstrates how to export an individual map frame on a layout to PDF.
//Added references
using ArcGIS.Desktop.Core; //Project
using ArcGIS.Desktop.Layouts; //Layout classes
using ArcGIS.Desktop.Framework.Threading.Tasks; //QueuedTask
using ArcGIS.Desktop.Mapping; //Export formats
public class ExportMapFrameToPDFExample
{
public static Task ExportMapFrameToPDFAsync(string LayoutName, string MFName, string Path)
{
//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
if (layoutItem == null)
return Task.FromResult<Layout>(null);
//Create PDF format with appropriate settings
PDFFormat PDF = new PDFFormat();
PDF.Resolution = 300;
PDF.OutputFileName = Path;
//PDF.Password = "xxx";
return QueuedTask.Run(() =>
{
//Export MapFrame
Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem
MapFrame mf = lyt.FindElement(MFName) as MapFrame;
PDF.OutputFileName = Path;
if (PDF.ValidateOutputFilePath())
{
mf.Export(PDF);
}
});
}
}
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.