Draw page size in pixel

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
kurlukuku
Posts: 4
Joined: Sat Sep 02, 2017 1:19 pm

Draw page size in pixel

Post by kurlukuku »

Hello,

i need something like Page.width but giving the results in pixel (and not in 1/100 millimetters)

my final purpose is to get the position of a mouse click in 1/100 millimetters (and not in pixel) under open office draw

thanks for the help
Open office 4.1.2
Windows 8
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: page size in pixel

Post by Zizi64 »

The Draw is a vectorgraphic software. The pixel size of the actual view of the drawing depends on the Zoom value and the pixel resolution of the screen.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
kurlukuku
Posts: 4
Joined: Sat Sep 02, 2017 1:19 pm

Re: page size in pixel

Post by kurlukuku »

Yes i figure that when my macro doing strange things after i change the zoom
I was guessing some uno service can tell how much pixel are use to display the page on the screen with the current zoom
Open office 4.1.2
Windows 8
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: page size in pixel

Post by Zizi64 »

I think, the API not support such pixel unit related functions. (API = Application Programming Interface)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: page size in pixel

Post by JeJe »

Don't know if this will help you but for Pixel/mm conversion

Code: Select all


	Dim FF,ComponentW,Desktop,pixpermmmx,pixpermmmy
	Desktop = createUnoService("com.sun.star.frame.Desktop")
	FF = Desktop.getActiveFrame()
	ComponentW = FF.getComponentWindow()
	pixpermmmx =ComponentW.getInfo().PixelPerMeterX/1000
	pixpermmmy =ComponentW.getInfo().PixelPerMeterY/1000


Link for Getinfo:

https://www.openoffice.org/api/docs/com ... ml#getInfo
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
kurlukuku
Posts: 4
Joined: Sat Sep 02, 2017 1:19 pm

Re: page size in pixel

Post by kurlukuku »

Thanks for this i progress a lot and i almost solved my problem

with your code i write a code that give the width of the page in pixel but that only works for a zoomvalue of 100

Code: Select all

Dim Doc As Object
Dim Page As Object
Doc = StarDesktop.CurrentComponent
Page = Doc.drawPages(0)
  
Dim FF,ComponentW,Desktop,pixpermmmx
Desktop = createUnoService("com.sun.star.frame.Desktop")
FF = Desktop.getActiveFrame()
ComponentW = FF.getComponentWindow()
pixpermmmx =ComponentW.getInfo().PixelPerMeterX/100000

MsgBox(Page.width*pixpermmmx)
I just need to replace Page.width*pixpermmmx by Page.width*pixpermmmx*ZoomValue/100
i find this https://wiki.openoffice.org/wiki/Docume ... gs/Zooming, but i don't figure how to use it in order to get the Zoom Value
Open office 4.1.2
Windows 8
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: page size in pixel

Post by JeJe »

try

Thiscomponent.currentController.ViewSettings.ZoomValue
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
kurlukuku
Posts: 4
Joined: Sat Sep 02, 2017 1:19 pm

Re: page size in pixel

Post by kurlukuku »

Thiscomponent.currentController.ViewSettings.ZoomValue works fine for open office writter but not for draw (under draw he doesnt recognise viewsettings)
Open office 4.1.2
Windows 8
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: page size in pixel

Post by JeJe »

I tried using getViewdata to set the scroll position in Writer... if that works in draw you might be able to work out how to get the zoom. See my post at the bottom here to start you off - its as much as I know:

viewtopic.php?f=20&t=84963
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: page size in pixel

Post by John_Ha »

The page size is measured in real units (inches, mm, points etc) and not in pixels.

See Where is the Display Cursor? in [Solved] Macro to measure the length of text in a .odt file for ideas.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Post Reply