We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WPF |
Control: SfDiagram |
Published Date: February 27, 2018 |
Last Revised Date: April 21, 2020

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

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon