Diagram / Import and Export / Export / Drawing Vector Image Export
Drawing Vector Image Export

The NDrawingVectorImageExporter lets you export the content of the active page (or portions of it) to a vector image. The currently supported vector image formats are:

 Saving with Dialog

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

Showing the default vector image export dialog
Copy Code
NDrawingVectorImageExporter imageExporter = new NDrawingVectorImageExporter(drawingView.Content);
imageExporter.ShowDialog(DisplayWindow, true);

The following code shows a save image file dialog that allows the user to create a vector image from the active page content:

Saving with a save file dialog
Copy Code
NDrawingVectorImageExporter imageExporter = new NDrawingVectorImageExporter(drawingView.Content);
imageExporter.SaveAsImage(ENVectorImageFormat.Svg); // Save to image with SVG file format selected by default
 Saving to File or Stream

To export the active page of a drawing to a vector image and save it directly to a file, without showing a save file dialog, use the SaveToFile method. Note that the saving to a file is an asynchronous (async) operation, so if you are interested in its completion, you should call the Then method of the promise it returns and handle the completion of the export in the passed delegate. The following is a code example:

Saving to a file
Copy Code
NDrawingVectorImageExporter imageExporter = new NDrawingVectorImageExporter(drawingView.Content);
imageExporter.SaveToFileAsync("C:\\ExportedImage.svg").Then(
    delegate (NUndefined ud)
    {
        // Export to SVG completed
    }
);
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 vector image stream, use the SaveToStream method. Unlike the SaveToFile method, the SaveToStream method runs synchronously and blocks code execution until it completes. Exporting drawings to stream is useful when you wish to generate images 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:

Saving to a stream
Copy Code
NDrawingVectorImageExporter imageExporter = new NDrawingVectorImageExporter(drawingView.Content);
imageExporter.SaveToStream(stream, ENVectorImageFormat.Svg);
       
 Generating a Vector Image

To generate an SVG document on the fly without saving it, you should use the CreateSvg method:

Generating image
Copy Code
NDrawingVectorImageExporter imageExporter = new NDrawingVectorImageExporter(drawingView.Content);
NSvgDocument svgDocument = imageExporter.CreateSvg();

You can use the CreateEmf and CreateDxf methods to create EMF byte arrays and DXF documents, respectively.

 Copying to Clipboard

To copy the vector image to the clipboard, you should use the CopyToClipboard method:

Generating image
Copy Code
NDrawingVectorImageExporter imageExporter = new NDrawingVectorImageExporter(drawingView.Content);
imageExporter.CopyToClipboard(ENVectorImageFormat.Svg);

The CopyToClipboard method in the case of EMF, places it in the clipboard and for SVG and AutoCAD DXF places their source code in the clipboard.

See Also