Code from the ItemFactory.Create, LayoutProjectItem, Layout.Export API pages. Note that there are several independent calls to QueuedTask that should probably be grouped into a single call. That's bitten me in the butt before. Also note that viewing the layout via CreateLayoutPaneAsync isn't necessary if you're doing a direct export.
//Import a pagx into a project.
//Create a layout project item from importing a pagx file
await QueuedTask.Run(() =>
{
IProjectItem pagx = ItemFactory.Instance.Create(
@"C:\Temp\Layout.pagx") as IProjectItem;
Project.Current.AddItem(pagx);
});
//Open a layout project item in a new view.
//Reference a layout project item by name
LayoutProjectItem someLytItem = Project.Current.GetItems<LayoutProjectItem>()
.FirstOrDefault(item => item.Name.Equals("MyLayout"));
//Get the layout associated with the layout project item
Layout layout = await QueuedTask.Run(() => someLytItem.GetLayout()); //Worker thread
//Create the new pane - call on UI
ILayoutPane iNewLayoutPane = await ProApp.Panes.CreateLayoutPaneAsync(layout); //GUI thread
//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
}