[Solved] Macro to check and change the paper size
-
- Posts: 10
- Joined: Fri Jan 22, 2016 12:11 pm
[Solved] Macro to check and change the paper size
I have some single document containing both portrait and landscape layout of LongBond paper size(216x330mm)or (8.5x13inch),
It means
Page 1 is Portrait
Page 2 is Landscape
Page 3 is Portrait
Page 4 is Landscape
I want to have a "customized button" to make and change the paper size as below during open the documents
Page 1 is Portrait --------------> change to Portrait (8.5 x12.99 inch)
Page 2 is Landscape --------------> change to Landscape (8.5 x12.99 inch)
Page 3 is Portrait --------------> change to Portrait (8.5 x12.99 inch)
Page 4 is Landscape --------------> change to Landscape (8.5 x12.99 inch)
That means the document size will be changed to (8.5 x12.99 inch) automatically by clicking the "customized button".
Could anyone know how to create a macro script for this ?
Thanks a lot !
Best regards
It means
Page 1 is Portrait
Page 2 is Landscape
Page 3 is Portrait
Page 4 is Landscape
I want to have a "customized button" to make and change the paper size as below during open the documents
Page 1 is Portrait --------------> change to Portrait (8.5 x12.99 inch)
Page 2 is Landscape --------------> change to Landscape (8.5 x12.99 inch)
Page 3 is Portrait --------------> change to Portrait (8.5 x12.99 inch)
Page 4 is Landscape --------------> change to Landscape (8.5 x12.99 inch)
That means the document size will be changed to (8.5 x12.99 inch) automatically by clicking the "customized button".
Could anyone know how to create a macro script for this ?
Thanks a lot !
Best regards
- Attachments
-
- Openoffice-Page Orientation 8.5x13.00.odt
- (11.69 KiB) Downloaded 292 times
Last edited by WilsonLeung on Thu Feb 25, 2016 8:10 am, edited 3 times in total.
OpenOffice 4.12 with Win7 64-bit
Re: Macro to check and change the paper size
In this case the document have more tha one PAGE STYLES. You can get the existing page styles by your macro and you can adjust the properties of the page styles. There are some example code in the Andrew Pitonyak' books.I have some single document containing both portrait and landscape layout of LongBond paper size(216x330mm)or (8.5x13inch),
and there are similar examples here:
viewtopic.php?f=20&t=64546
viewtopic.php?f=20&t=31913
and you can find other examples in this Forum...
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.
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.
-
- Posts: 10
- Joined: Fri Jan 22, 2016 12:11 pm
Re: Macro to check and change the paper size
Hi Zizi64,
Thanks for your advice !
Sorry to let you know i'm no any experience for macro script.
i'm still no ideas how to set the macro for " Landscape" and "Portrait" with PAGE STYLES.
On the other hand, is it possible to use "IF then" function with macro script on this case.
Can you provide more related examples for my reference ?
Thanks a lot !
Thanks for your advice !
Sorry to let you know i'm no any experience for macro script.
i'm still no ideas how to set the macro for " Landscape" and "Portrait" with PAGE STYLES.
On the other hand, is it possible to use "IF then" function with macro script on this case.
Can you provide more related examples for my reference ?
Thanks a lot !
OpenOffice 4.12 with Win7 64-bit
Re: Macro to check and change the paper size
Then you will not able to wite a macro for this task... The Macrorecorder can not record the Style modifying activity - as I know it.Sorry to let you know i'm no any experience for macro script.
You need study the API functions, and must use them in your macros.
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.
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.
Re: Macro to check and change the paper size
Using Page Styles is a good thing.
If you create a new pagestyle based on "Default" then you would just need to change the "Default" page style to your desired new pagesize and all other pagestyles would use it.
But if you already have lots of docs with mixed pagestyles you can try this macro.
If you create a new pagestyle based on "Default" then you would just need to change the "Default" page style to your desired new pagesize and all other pagestyles would use it.
But if you already have lots of docs with mixed pagestyles you can try this macro.
Code: Select all
sub changeallpagesizesusedindocument
rem Portrait Sizes:
newpagesizeWidth = 21600
newpagesizeHeight = 33000
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.jumptofirstpage(false)
do
s = oViewCursor.PageStyleName
oStyle = ThisComponent.StyleFamilies.getByName("PageStyles").getByName(s)
if oStyle.IsLandscape=True then
oStyle.Width = newpagesizeHeight
oStyle.Height = newpagesizeWidth
else
oStyle.Width = newpagesizeWidth
oStyle.Height = newpagesizeHeight
end if
loop while oViewCursor.jumptonextpage(false)
oViewCursor.jumptofirstpage(false)
end sub
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
-
- Posts: 10
- Joined: Fri Jan 22, 2016 12:11 pm
Re: Macro to check and change the paper size
Hi musikai ,
Thank you very much for your help !
May i know how to set the below page margins as well with marco script ?
Page margin:
top=12mm
bottom=12mm
left=10mm
right=10mm
Thanks a lot !
Best regards,
Thank you very much for your help !
May i know how to set the below page margins as well with marco script ?
Page margin:
top=12mm
bottom=12mm
left=10mm
right=10mm
Thanks a lot !
Best regards,
Last edited by WilsonLeung on Thu Feb 25, 2016 2:35 am, edited 1 time in total.
OpenOffice 4.12 with Win7 64-bit
Re: Macro to check and change the paper size
Ah no! That's too difficult!!
Code: Select all
oStyle.TopMargin
oStyle.BottomMargin
oStyle.LeftMargin
oStyle.RightMargin
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
-
- Posts: 10
- Joined: Fri Jan 22, 2016 12:11 pm
Re: Macro to check and change the paper size
Hi musikai ,
Sorry that may i know how to input the page margins with your script ?
Page margin:
top=12mm
bottom=12mm
left=10mm
right=10mm
Thanks a lot !
I got an error when run the script below, please advice ...
sub changeallpagesizesusedindocument
rem Portrait Sizes:
newpagesizeWidth = 21590
newpagesizeHeight = 32995
oStyle.TopMargin = 1200
oStyle.BottomMargin = 1200
oStyle.LeftMargin = 1000
oStyle.RightMargin = 1000
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.jumptofirstpage(false)
do
s = oViewCursor.PageStyleName
oStyle = ThisComponent.StyleFamilies.getByName("PageStyles").getByName(s)
if oStyle.IsLandscape=True then
oStyle.Width = newpagesizeHeight
oStyle.Height = newpagesizeWidth
else
oStyle.Width = newpagesizeWidth
oStyle.Height = newpagesizeHeight
end if
loop while oViewCursor.jumptonextpage(false)
oViewCursor.jumptofirstpage(false)
End Sub
Sorry that may i know how to input the page margins with your script ?
Page margin:
top=12mm
bottom=12mm
left=10mm
right=10mm
Thanks a lot !
I got an error when run the script below, please advice ...
sub changeallpagesizesusedindocument
rem Portrait Sizes:
newpagesizeWidth = 21590
newpagesizeHeight = 32995
oStyle.TopMargin = 1200
oStyle.BottomMargin = 1200
oStyle.LeftMargin = 1000
oStyle.RightMargin = 1000
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.jumptofirstpage(false)
do
s = oViewCursor.PageStyleName
oStyle = ThisComponent.StyleFamilies.getByName("PageStyles").getByName(s)
if oStyle.IsLandscape=True then
oStyle.Width = newpagesizeHeight
oStyle.Height = newpagesizeWidth
else
oStyle.Width = newpagesizeWidth
oStyle.Height = newpagesizeHeight
end if
loop while oViewCursor.jumptonextpage(false)
oViewCursor.jumptofirstpage(false)
End Sub
OpenOffice 4.12 with Win7 64-bit
Re: Macro to check and change the paper size
Hi,
yeah, cool that you are trying. You just have to put it at another place.
The settings at the top are only for convenience so you don't have to set everything twice (for portrait and landscape).
As I don't know if you want the margins to be the same on portrait and landscape you might have to correct the code below.
It is set that Landscape is like Portrait rotated 90° right (clockwise).
yeah, cool that you are trying. You just have to put it at another place.
The settings at the top are only for convenience so you don't have to set everything twice (for portrait and landscape).
As I don't know if you want the margins to be the same on portrait and landscape you might have to correct the code below.
It is set that Landscape is like Portrait rotated 90° right (clockwise).
Code: Select all
sub changeallpagesizesusedindocument
rem Portrait Sizes:
newpagesizeWidth = 21590
newpagesizeHeight = 32995
newTopMargin = 1200
newBottomMargin = 1200
newLeftMargin = 1000
newRightMargin = 1000
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.jumptofirstpage(false)
do
s = oViewCursor.PageStyleName
oStyle = ThisComponent.StyleFamilies.getByName("PageStyles").getByName(s)
if oStyle.IsLandscape=True then 'this is for Landscape, the margins as if we rotated portrait 90°right, change as you like
oStyle.Width = newpagesizeHeight
oStyle.Height = newpagesizeWidth
oStyle.TopMargin = newLeftMargin
oStyle.BottomMargin = newRightMargin
oStyle.LeftMargin = newBottomMargin
oStyle.RightMargin = newTopMargin
else 'this is for portrait
oStyle.Width = newpagesizeWidth
oStyle.Height = newpagesizeHeight
oStyle.TopMargin = newTopMargin
oStyle.BottomMargin = newBottomMargin
oStyle.LeftMargin = newLeftMargin
oStyle.RightMargin = newRightMargin
end if
loop while oViewCursor.jumptonextpage(false)
oViewCursor.jumptofirstpage(false)
End Sub
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
-
- Posts: 10
- Joined: Fri Jan 22, 2016 12:11 pm
Re: Macro to check and change the paper size
Hi musikai,
Great ! thank you for your kindness and help !
Best regards,
Great ! thank you for your kindness and help !
Best regards,
OpenOffice 4.12 with Win7 64-bit