Articles in this section
Category / Section

How to export the Diagram as a PDF in the WPF Diagram (SfDiagram)?

3 mins read

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);        
}

 

View Sample in GitHub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied