Convert Visio Drawing to PNG or other format via code

B

BennyEz

I have a c# project that creats a visio drawing from a database and
currently that drawing is displayed in the visio ocx control where the
user can then save the drawing. This was done using windows forms
however now we have the need to make the drawings available through a
web application and we cannot rely on the client having visio
installed. Therefore we cannot use the visio ocx.

What I'd like to do is convert the visio drawing to PNG or another
format that can be viewed in the browser before displaying to the
user. Since the server will have the Visio library to create the
drawing it can be done on the server side. Then it needs to be
converted and displayed to the user.

Any ideas?
 
T

Timothy

If the server has visio installed, then it shall be possible.

To find the code to do it, follow these steps:

- open the visio file
- start record macro
- save the file as png
- stop record macro
- check the code in macro

then u need the perform similar steps in c#. it shall give u what u want.

Hope these helps.

Regards,
Timothy
 
A

Al Edlund

Rather than use the visio drawing control, consider using the visio viewer
control in your web app.
al
 
J

Jacco

This is the way I have done it in VBA:

<code>
Function fdExportPageImg(expPage As Page, screenDirectory As String)
As Boolean

Dim expImgName As String
Dim pageName As String

Set fs = CreateObject("Scripting.FileSystemObject")

pageName = fdGetPageName(expPage.Name)
' create export path & filename
' BuildPath requires path, then adds name to it and additional
' path seperator if necessary
expImgName = fs.BuildPath(screenDirectory, pageName + ".png")
expPage.Export expImgName

fdExportPageImg = fs.fileExists(expImgName)

End Function
</code>

This function exports one single page from a document to a certain
directory. It uses the pagename (with some logic defined in
fdGetPageName) as the filename. If you want more information, fele
free to download the whole swipr stencil, it is free to use. Although
it's all built in VBA, it should give you some hints.

Cheers,

Jacco
(www.swipr.com / swipr.blogspot.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top