Printing documents from BASIC

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
dstockman12
Posts: 39
Joined: Thu Dec 13, 2007 6:32 pm

Printing documents from BASIC

Post by dstockman12 »

I need to control printer output using BASIC code. I have found some documentation about controlling printers in the SDK/Wiki, but am not sure how to implement in BASIC. I need a fair amount of control for printing. Some of the things I need to do are listed below. Can anyone give me an idea of how to send a form and a report to a printer using BASIC code?

Parameters I need to control
Which printer is selected
Which tray I use
When selecting the Windows “Fax” printer, I need to supply the number to call, coversheet, etc.

Any help is greatly appreciated.

Doug
zenlord
Posts: 51
Joined: Tue Dec 22, 2009 5:50 pm

Re: Printing documents from BASIC

Post by zenlord »

Well, I have been struggling with this also. I think my needs are partially what you need, and I have found the solution for my problem, so it might help you:

http://user.services.openoffice.org/en/ ... 40#p120146

Zl.
LibreOffice 4.1 on Linux (Debian Wheezy backports)
dstockman12
Posts: 39
Joined: Thu Dec 13, 2007 6:32 pm

Re: Printing documents from BASIC

Post by dstockman12 »

zenlord:

Thanks loads! This really helped. The code snippet below allows me to select which printer to print to and then allows me to make some basic choices on output. The next step for me to fully answer my question is to figure out how to pass information to the "Fax" printer server - things like fax number and which cover page to use, if any. I am not sure where to look for that information. Anyone have ideas?

Parameters that can be set
' **** use the following when printing (Print) - see below
CopyCount
FileName 'Use if you want to print a file, instead of printing the current document/form
Collate 'Use instead of Sort, and collates output
Pages, 'This range is given as at the user interface. For example: "1-4;10" to print the pages 1 to 4 and 10.
Wait

' *** use the following in setPrinter - see below
Name ' name of print queue to use
PaperOrientation
PaperFormat
PaperSize

Code: Select all

' *****************************************************************************************************
' **** Sub to print current document/form ****
Sub PrintDoc
DIM oPropertyValue(0) AS New com.sun.star.beans.PropertyValue
Dim oPrinterSettings(0) As New com.sun.star.beans.PropertyValue
DIM oDoc As Object
'DIM oSettings As Object, not needed for basic printing

oDoc = ThisComponent

' *** This works to set which printer I will send output to, in this case, the Fax printer server ***
' ***  I do not yet know how to pass arguments to the Fax server: number to call, cover page info, etc ***
oPrinterSettings(0).Name = "Name"
oPrinterSettings(0).Value = "Fax"
oDoc.setPrinter(oPrinterSettings)

' *** I do not think oSettings is needed for basic printing.  It looks like it pertains to the document ****
'oSettings = oDoc.createInstance("com.sun.star.text.DocumentSettings")
'   oSettings.PrintPageBackground = False

REM Set some print options
oPropertyValue(0).Name = "CopyCount"
oPropertyValue(0).Value = 1
oDoc.Print(oPropertyValue())
End Sub 
Doug
Post Reply