| View previous topic :: View next topic |
| Author |
Message |
Crusty General User

Joined: 11 Mar 2004 Posts: 8
|
Posted: Thu May 20, 2004 11:33 pm Post subject: Set PrinterName |
|
|
Hello@all
I'm on the way to programm an interface to OO and I want to set a specific printer (to print a document). In the "Basic Programmers Guide" I fond an example for this problem but I can't "translate" it into my Visual FoxPro Code. My problem is the last code-line of the sample and I think in the last sentence of the explanation justifies this... Have anyone an idea to set the printername in another way?
Here is the sample and the explanation of the guide:
| Code: |
Dim Doc As Object
Dim PrinterProperties(1) As New com.sun.star.beans.PropertyValue
Dim PaperSize As New com.sun.star.awt.Size
PaperSize.Width = 20000 ' corresponds to 20 cm
PaperSize.Height = 20000 ' corresponds to 20 cm
PrinterProperties (0).Name="Name"
PrinterProperties (0).Value="My HP Laserjet"
PrinterProperties (1).Name="PaperSize"
PrinterProperties (1).Value=PaperSize
Doc.Printer = PrinterProperties()
|
The example defines an object named PaperSize with the com.sun.star.awt.Size type. This is needed to specify the paper size. Furthermore, it creates a data field for two PropertyValue entries named PrinterProperties. This data field is then initialized with the values to be set and assigned the Printer property. From the standpoint of UNO, the printer is not a real property but an imitated one. |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Fri May 21, 2004 5:36 am Post subject: |
|
|
| Crusty wrote: | Dim Doc As Object
Dim PrinterProperties(1) As New com.sun.star.beans.PropertyValue
.....
.....
Doc.Printer = PrinterProperties() |
I am assuming that "Doc" is a variable containing a document model. Therefore, it would include the OfficeDocument service.
The OfficeDocument service, has the XPrintable interface.
The XPrintable interface has the setPrinter() method and the getPrinter() method.
OOo's Basic allows a practice where the Basic programmer can treat a pair of set/get methods as if they were a property. So while in reality, the document object has a pair of methods setPrinter() and getPrinter(), a Basic programmer can pretend as if there is a single "Printer" property. When they assign to Printer, the setPrinter() method is called. When they access the value of Printer, the getPrinter() methjod is called.
In Visual FoxPro, you should be able to just call setPrinter(), passing it your array of property values. (Be sure to pass them by reference, and do VFP's awkward COMARRAY() dance on the Doc variable.)
Code, not tested.
| Code: | LOCAL oDoc
oDoc = ....something to get document....
LOCAL ARRAY aPrinterProperties[ 2 ]
aPrinterProperties[1] = OOoMakePropertyValue( "Name", "My Apple LaserWriter" )
aPrinterProperties[2] = OOoMakePropertyValue( "PaperSize", OOoSize( 20000, 20000 ) )
oDoc.setPrinter( @ aPrinterProperties )
* Create and return a Size struct.
FUNCTION OOoSize( nWidth, nHeight )
LOCAL oSize
oSize = OOoCreateStruct( "com.sun.star.awt.Size" )
oSize.Width = nWidth
oSize.Height = nHeight
RETURN oSize
ENDFUNC
|
See this message
http://www.oooforum.org/forum/viewtopic.php?p=28389#28389
for some of the functions I use with VFP, and an example of the COMARRAY() business. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
Crusty General User

Joined: 11 Mar 2004 Posts: 8
|
Posted: Tue Jun 01, 2004 1:01 am Post subject: |
|
|
Hello DannyB,
thank you very much! Your solution runs directly by the first test.
I think, I say this in the name of all oooforum.org members:
You do a very good job here in this forum.... thanks!
bye Crusty |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|