| View previous topic :: View next topic |
| Author |
Message |
joel Newbie

Joined: 22 Jan 2004 Posts: 1
|
Posted: Fri Jan 23, 2004 12:08 am Post subject: How to print a doc via VB6 with specific printing settings |
|
|
Hello Everybody.
I 've been trying to print a (Oo)document via VB6 using the awful code you can
see below. But it deosn't work. Help me pleeeeeease....
Using the Dispatcher method, you can print the whole document without any problem.
But i can't find a way to specify printing settings programatically through VB6.
What i would like to do is tell the printer to print, for exemple, only the page 1
of the document.(or pages 1 to 3)
My Code :
Dim opt(0)
Set OoFrame = objDesktop.getCurrentFrame()
Set OoDispatcher = objServiceManager.createInstance("com.sun.star.frame.DispatchHelper")
Set opt(0) = objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
opt(0).Name = "Text"
opt(0).Value = "1-3"
OoDispatcher.executeDispatch OoFrame, ".uno:Print", "", 0, opt()
i'm waiting for your feedback.
JOEL |
|
| Back to top |
|
 |
heffalump General User


Joined: 15 Jan 2004 Posts: 21 Location: Germany, Pliezhausen
|
Posted: Fri Jan 23, 2004 1:14 am Post subject: |
|
|
Hi Joel,
here is my VB code for printing (some kind of raw - but it works, I will optimize it later)
| Code: |
'...
Set objDocument = objDesktop.loadComponentFromURL(url, "_blank", 0, args)
...
'Now printing out
Dim args(2) as object
Set args(0) = objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
args(0).name = "Copies"
args(0).Value = 1
Set args(1) = objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
args(1).name = "Collate"
args(1).Value = False
Set args(2) = objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
args(2).Name = "RangeText"
args(2).Value = "2-3"
'Print() wird sonst als VB-eigene Methode verstanden!
CallByName objDocument, "print", VbMethod, args()
|
If you use the print() method of the document model you have to use the VB-function CallByName otherwise VB tries to apply its own bulit-in function print on the objDocument object. This example prints pages 2 to 3.
Regards,
Werner |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Jan 23, 2004 5:02 am Post subject: |
|
|
Thank you so much, Werner.
You simply saved my life.
Now It works wonderfully
Best regards
JOEL |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Jan 23, 2004 7:56 am Post subject: |
|
|
Hello Werner
Your code helped me a lot.
Now I've just one more question.
The problem is right there:
Dim args(2) as object
Set args(0) = objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
args(0).name = "Copies"
args(0).value=5
I would like to be able to print several documents (4 or 5) in one go.
But there is something wrong with the piece of code abode.
I guess something is missing.
I tried "CopyCount" instead of "Copies" but it doesn't seem to change anything
Let me know, if you have an idea.
Thank you
JOEL |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
heffalump General User


Joined: 15 Jan 2004 Posts: 21 Location: Germany, Pliezhausen
|
Posted: Mon Jan 26, 2004 12:12 am Post subject: |
|
|
If you need only one single property to set then you have to dimension the args() array as args(0)
| Quote: | Dim args(0) as object
Set args(0) = objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
args(0).name = "Copies"
args(0).value=5
|
If you need more properties then you have to fit the array dimension to the number of properties you will set. Each array element is an object (instanciated by the Bridge_GetStruct() method) with the properties "name" and "value". |
|
| Back to top |
|
 |
|