Skip to main content

Office 365: Developer Blog

Visio 2010 API for configuring raster export

When we talk to developers to get their feedback on the Visio development platform, a common request we hear is the ability, through the API, to control the settings used when exporting a diagram as a raster image in the PNG, JPG, BMP, or TIFF format. Typically, they want to automate the export of the pages in a document as images for use in a web page or other application that requires certain settings. In this post, we’ll talk about the additions to the Visio 2010 object model that let developers configure each of these raster export settings.

When you save a diagram in one of the raster formats, a dialog box appears to let you configure various settings, such as the color format, resolution, or size of the image. For example, this is the dialog for the PNG format:

image

Until now, there hasn’t been a way to automate the settings in this dialog via the API. In Visio 2010, we’ve enhanced the object model to make it possible to drive these settings programmatically using a set of new methods and properties on the ApplicationSettings object. You can use the methods to get and set the raster-export resolution and size, and you can use the properties to get and set raster export attributes such as data format, data compression, color reduction, color format, background color, transparency, and quality. You can use these methods and properties with the existing Page.Export and Selection.Export methods to export a diagram in a raster file format.

Here is the complete list of new raster export methods and properties on ApplicationSettings:

Methods

Name Description
GetRasterExportResolution Returns the raster export resolution settings.
GetRasterExportSize Gets the raster export size.
SetRasterExportResolution Specifies the raster export resolution settings.
SetRasterExportSize Sets the raster export size.

Properties

Name Description
RasterExportBackgroundColor Determines the background color that is applied to the exported image.
RasterExportColorFormat Determines the color format that is applied to the exported image.
RasterExportColorReduction Determines the color reduction that is applied to the exported image.
RasterExportDataCompression Determines the data compression algorithm that is applied to the exported image (BMP, TIFF).
RasterExportDataFormat Determines whether the exported image is interlaced or non-interlaced (PNG, GIF).
RasterExportFlip Determines the flip that is applied to the exported image.
RasterExportOperation Determines the export operation that is applied to the exported image (JPG only).
RasterExportQuality Determines the export quality that is applied to the exported image (JPG only).
RasterExportRotation Determines the rotation that is applied to the exported image.
RasterExportTransparencyColor Determines the transparency color that is applied to the exported image (PNG, GIF).
RasterExportUseTransparencyColor Determines whether Visio applies, to the exported image, the transparency color that is specified in the RasterExportTransparencyColor property (PNG, GIF).

For more details on these methods and properties, such as their parameters and constants, see the Visio Developer Reference in the Visio 2010 Beta.

Example

This VBA code executes the settings in the PNG Output Options dialog box as shown above and exports the diagram as a PNG:

‘Set the export resolution to the printer resolution at 600 x 600 pixels/inch
Application.Settings.SetRasterExportResolution visRasterUsePrinterResolution, 600#, 600#, visRasterPixelsPerInch

‘Set the export size to custom 8 x 5 inches
Application.Settings.SetRasterExportSize visRasterFitToCustomSize, 8#, 5#, visRasterInch

‘Set the data format to Interlace
Application.Settings.RasterExportDataFormat = visRasterInterlace

‘Set the color format to 24-bit color
Application.Settings.RasterExportColorFormat = visRaster24Bit

‘Rotate the image to the left
Application.Settings.RasterExportRotation = visRasterRotateLeft

‘Don’t flip the image
Application.Settings.RasterExportFlip = visRasterNoFlip

‘Set the background color
Application.Settings.RasterExportBackgroundColor = 14798527

‘Set the transparency color
Application.Settings.RasterExportTransparencyColor = 13269045

‘Use the transparency color
Application.Settings.RasterExportUseTransparencyColor = True

‘Export the active page as a PNG to the specified path
Application.ActiveWindow.Page.Export “<drive>:\<path>\Network Diagram.png”

We hope these additions to the API for raster export open up some new possibilities for Visio developers, or at least make it easier and more efficient to build automated solutions. Let us know what you think by commenting on the blog or using Send a Smile.

filter-icon