|
|
|
How to Set Printer Properties with a MacroUse an OpenOffice Macro to Change Printer Options
Rather than waste masses of incorrectly printed paper use a single OpenOffice macro to set up the printer correctly.
Every year there are thousands of sheets of paper wasted because of reports being printed:
Fortunately all of that paper can be saved just by using OpenOffice.org Calc and a single macro - a macro that can:
Setting the Page SizeThe page size can be set very easily by:
Sub FormatPrinter
pageStyles = thisComponent.StyleFamilies.getByName("PageStyles")
page = pageStyles.getByName("Default")
page.width = 21000
page.height = 29700
Setting the Page OrientationThe page orientation is handled a little differently to the page size - for that an OpenOffice property value for the printer must be set: Dim printerOption(0) As New com.sun.star.beans.PropertyValue
printerOption(0).Name = "PaperOrientation"
printerOption(0).Value = com.sun.star.view.PaperOrientation.LANDSCAPE
thisComponent.Printer = printerOption()
Choosing the paper trayChanging the paper tray is very simple: page.PrinterPaperTray = "Tray Two"
It's worth noting that an error will occur at this point if the wrong printer tray name is entered. Adding a HeaderAdding the header is the most complicated part of the process seen so far, but is by no means difficult - the macro must:
page.HeaderIsOn = True
header = page.RightPageHeaderContent
header.LeftText.String = Date()
header.CenterText.String = "My Report"
header.RightText.String = "Author: Mark Alexander Bain"
page.RightPageHeaderContent = header
Adding a FooterThe footer is handled in exactly the way as the header: page.FooterIsOn = True
footer = page.RightPageFooterContent
footer.CenterText.String = "~*~ OpenOffice Secrets ~*~"
page.RightPageFooterContent = footer
Adding a Page Number and Page CountThe page numbering and page count functionality is, of course, built into OpenOffice - the only difficult thing is knowing how to access it and, most importantly, how to update the header or the footer with the information: pageNumber = _
thisComponent.createInstance ("com.sun.star.text.TextField.PageNumber")
textCursor = footer.RightText.createTextCursor
textCursor.gotoEnd (False)
textCursor.String = "Page "
textCursor.gotoEnd (False)
footer.RightText.insertTextContent (textCursor, pageNumber, True)
pageCount = _
thisComponent.createInstance ("com.sun.star.text.TextField.PageCount")
textCursor.gotoEnd (False)
textCursor.String = " of "
textCursor.gotoEnd (False)
footer.RightText.insertTextContent (textCursor, pageCount, True)
page.RightPageFooterContent = footer
End Sub
SummaryFormatting printer outputs by using a macro in OpenOffice Calc is only difficult because a few different techniques have to be used:
However, combining them into a single macro means that a document can always be printed correctly - with no waste of paper.
The copyright of the article How to Set Printer Properties with a Macro in Computer Programming Tutorials is owned by Mark Alexander Bain. Permission to republish How to Set Printer Properties with a Macro in print or online must be granted by the author in writing.
|
|
|
|
|
|
|
|