Diagram / Import and Export / Export / Drawing PDF Export
In This Topic
    Drawing PDF Export
    In This Topic

    The NDrawingPdfExporter can be used to export the active page of a drawing to PDF.

     Configuring the Print Layout

    To configure how a drawing page should be printed or exported to PDF use the PrintLayout property of the page. The following code demonstrates how to configure export of the whole drawing page to a single page of size A4:

    Configuring Print Layout
    Copy Code
    NPagePrintLayout printLayout = drawingView.ActivePage.PrintLayout;
    printLayout.PageSize = new NPaperSize(ENPaperKind.A4);
    printLayout.PageColumns = 1;
    printLayout.PageRows = 1;
    

    Explore the other properties of the page's PrintLayout if you want to further customize the printing / export to PDF.

     Saving with a Dialog

    The following code shows how to display the default PDF export dialog provided by NOV:

    Showing the default PDF Export dialog
    Copy Code
    NDrawingPdfExporter imageExporter = new NDrawingPdfExporter(drawingView.Content);
    imageExporter.ShowDialog(DisplayWindow, true);
    

    The following code shows a save PDF file dialog, which allows the user to export the active page of a drawing to the selected PDF file:

    Exporting the active page of a drawing directly to a file selected from a Save File dialog
    Copy Code
    NDrawingPdfExporter pdfExporter = new NDrawingPdfExporter(drawingView.Content);
    pdfExporter.SaveAsPdf();
    
     Saving to File or Stream

    To export the active page of a drawing to PDF and save it directly to a file, without showing a save file dialog, use the SaveToFileAsync method. The following is a code example:

    Saving the active page of a drawing to a PDF file
    Copy Code
    NDrawingPdfExporter pdfExporter = new NDrawingPdfExporter(drawingView.Content);
    pdfExporter.SaveToFileAsync(@"C:\ExportedDiagram.pdf");
    
    Exporting a drawing to an arbitrary file works only on non-sandboxed platforms like WinForms, WPF and Xamarin.Mac.

    To export the active page of the drawing to a PDF stream, use the SaveToStream method. Unlike the SaveToFileAsync method, the SaveToStream method runs synchronously and blocks code execution until it completes. Exporting drawings to PDF is useful when you wish to generate PDF documents in memory instead of saving them to the disc. The following code snippet shows how to export the active page of a drawing to a stream:

    Export the active page of a drawing to a PDF stream
    Copy Code
    NDrawingPdfExporter pdfExporter = new NDrawingPdfExporter(drawingView.Content);
    pdfExporter.SaveToStream(stream);
    

     

    See Also