How to export the Diagram as a PDF in the WPF Diagram?
WPF Diagram (SfDiagram) does not have the built-in support to convert the diagram to PDF file, but it can be achieved by exporting the diagram as an XPS file and then, convert the exported XPS file to PDF using the Syncfusion.XPS.XPSToPdfConverter.
Exporting XPS
To export the diagram as an XPS file, enable the IsSaveToXps property of the ExportSettings class and specify the file name with the “.xps” extension.
Exporting XPS to PDF
The XPS document can be converted into PDF file using the XPSToPdfConverter class of PDF library.
XAML
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="100"/> </Grid.ColumnDefinitions> <syncfusion:SfDiagram x:Name="diagram" Grid.Column="0"> <syncfusion:SfDiagram.Nodes> <syncfusion:NodeCollection> <syncfusion:NodeViewModel OffsetX="100" OffsetY="100" UnitHeight="100" UnitWidth="100"/> </syncfusion:NodeCollection> </syncfusion:SfDiagram.Nodes> <syncfusion:SfDiagram.Connectors> <syncfusion:ConnectorCollection> <syncfusion:ConnectorViewModel SourcePoint="100,100" TargetPoint="200,200" /> </syncfusion:ConnectorCollection> </syncfusion:SfDiagram.Connectors> </syncfusion:SfDiagram> <Button x:Name="Export" Grid.Column="1" Click="Export _Click" Content="Export"/> </Grid>
C#
private void Export _Click(object sender, RoutedEventArgs e) { diagram.ExportSettings = new ExportSettings() { IsSaveToXps = true, FileName = "export.xps", }; (diagram.Info as IGraphInfo).Export(); var converter = new XPSToPdfConverter { }; var document = new PdfDocument(); document = converter.Convert("export.xps"); document.Save("export.pdf"); document.Close(true); }
I hope you enjoyed learning about how export the Diagram as a PDF in the WPF Diagram (SfDiagram).
You can refer to our WPF Diagram feature tour page to know about its other groundbreaking feature representations and documentation. You can also explore our WPF Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!