[Solved] Setting "Optimal zoom" in Writer

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
pitonyak
Volunteer
Posts: 186
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

[Solved] Setting "Optimal zoom" in Writer

Post by pitonyak »

In Writer, I can use View | Zoom and then I have choices such as "Entire Page", "Page Width", and "Optimal View". Anyone know how to access these?

Thanks to Zizi64 (see viewtopic.php?f=20&t=43418). I know how to set the "zoom percentage", this macro sets to 120% in both Calc and in Write (the only two I tested)

Code: Select all

    sub zoom2
    rem ----------------------------------------------------------------------
    rem define variables
    dim document   as object
    dim dispatcher as object
    rem ----------------------------------------------------------------------
    rem get access to the document
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

    rem ----------------------------------------------------------------------
    dim args1(2) as new com.sun.star.beans.PropertyValue
    args1(0).Name = "Zoom.Value"
    args1(0).Value = 120
    args1(1).Name = "Zoom.ValueSet"
    args1(1).Value = 28703
    args1(2).Name = "Zoom.Type"
    args1(2).Value = 0

    dispatcher.executeDispatch(document, ".uno:Zoom", "", 0, args1())
    end sub
Something I have never done, but have considered.... is there any easy way for me to understand what the parameters do? For example, "Zoom.Type" and "Zoom.ValueSet"?

I suppose that what I really need to do is just grab the latest source and start searching it.
Last edited by pitonyak on Wed Apr 22, 2015 5:02 pm, edited 1 time in total.
Andrew Pitonyak
http://www.pitonyak.org/oo.php
LO and AOO on Fedora
User avatar
RoryOF
Moderator
Posts: 35066
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Setting "Optimal zoom" in Write

Post by RoryOF »

A quick search found this, Andrew
I tried Thiscomponent.currentController.ViewSettings, I Found a
property to change the zoom factor , but nothing to show 2 page side by
side on the screen
It may be helpful.

I'm also finding
http://www.openoffice.org/api/docs/comm ... tings.html
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
pitonyak
Volunteer
Posts: 186
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

Re: Setting "Optimal zoom" in Write

Post by pitonyak »

And that is exactly what I was looking for!

http://www.openoffice.org/api/docs/comm ... mType.html

Code: Select all

Thiscomponent.currentController.ViewSettings.ZoomType = com.sun.star.view.DocumentZoomType.OPTIMAL
If I want to set a specific manual value, I can set:

Code: Select all

  Thiscomponent.currentController.ViewSettings.ZoomType = com.sun.star.view.DocumentZoomType.BY_VALUE
  Thiscomponent.currentController.ViewSettings.ZoomValue = 100

Finally, I can set the view modes using a dispatch:

Code: Select all

sub PageViews
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

REM -- Set to Book View
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ViewLayout.Columns"
args2(0).Value = 2
args2(1).Name = "ViewLayout.BookMode"
args2(1).Value = true

dispatcher.executeDispatch(document, ".uno:ViewLayout", "", 0, args2())

REM -- Set to Two Page view
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "ViewLayout.Columns"
args4(0).Value = 0
args4(1).Name = "ViewLayout.BookMode"
args4(1).Value = false

dispatcher.executeDispatch(document, ".uno:ViewLayout", "", 0, args4())

REM -- Set to Single-Page view
dim args6(1) as new com.sun.star.beans.PropertyValue
args6(0).Name = "ViewLayout.Columns"
args6(0).Value = 1
args6(1).Name = "ViewLayout.BookMode"
args6(1).Value = false

dispatcher.executeDispatch(document, ".uno:ViewLayout", "", 0, args6())

end sub
Andrew Pitonyak
http://www.pitonyak.org/oo.php
LO and AOO on Fedora
Post Reply