2

I'm trying to set the zoom level of a Visio document which is shown through the Visio Web Service.

http://mysite/_layouts/VisioWebAccess/VisioWebAccess.aspx?id=/Shared%20Documents/MyDiagram.vdw

I want to use the 'fit to page' zoom level which is achieved by pressing the button on the right of the toolbar. My first thought was click the button via javascript, but didn't get immediate success and also stumbled across MSDN articles on Objects in the Visio Services JavaScript API, the Vwa.VwaControl.getActivePage Method and the Vwa.Page.setZoom Method.

I can successfully construct a VwaControl object

vwaControl = new Vwa.VwaControl("ctl00_PlaceHolderMain_VisioWebAccess");

but I get null when I call getActivePage() on this control.

I've tried constructing other VwaControl using other ids from the page but none of them are valid - I get an error like "VwaControl does not exist for id {0}". I've tried traversing down the tree from vwaControl._control._zoomControl._fitButton._clickDelegate but I don't know how to fire that delegate.

Has anyone implemented an 'auto zoom to fit' feature in the VisioWebAccess.aspx page?

1

I've given up trying to modify the ASPX to auto-fit the Visio document, but have instead found another solution.

Select 'Fit to Window' in Visio before saving the file. This View preference is saved with the file, and when opened using Visio Web Services the file will be opened in 'Fit to Window' mode.

In the same way, zooming in on a particular part of a drawing and saving will cause it to load with that same zoom.

0

From StackOverflow Add a handler to 'diagramComplete' then try ad get the active page.

function zoomVWAControl()
{

    vwaControl= new Vwa.VwaControl("WebPartWPQ2");  
    vwaControl.addHandler("diagramcomplete", onDiagramComplete);
}

function onDiagramComplete()
{

 try{
        vwaPage = vwaControl.getActivePage();
        var zoomLevel = vwaPage.getZoom();
        vwaPage.setZoom(Number(200));
    }
    catch(err){
        alert(err);
    }
}
0

I have set the Zoom Level to 21% and passed the Visio webpart id("WebPartWPQ3") to get the vwaControl. Its working as expected and setting the zoom level as 21 on page load.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
var vwaControl; 
var vwaPage;
$(document).ready(function(){
vwaControl= new Vwa.VwaControl("WebPartWPQ3"); 
vwaControl.addHandler("diagramcomplete", onDiagramComplete);
});
function onDiagramComplete(){ 
    try{ 
        vwaPage = vwaControl.getActivePage();         
        var zoomLevel = '21';  
        vwaPage.setZoom(Number(zoomLevel)); 
    } 
    catch(err){ 
        alert(err); 
    } 
} 
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.