OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

print first page to tray 2 and other pages to tray one

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
pbd4499
General User
General User


Joined: 04 Jun 2007
Posts: 23

PostPosted: Tue Nov 20, 2007 1:27 pm    Post subject: print first page to tray 2 and other pages to tray one Reply with quote

-- see code below

Last edited by pbd4499 on Thu Nov 29, 2007 3:53 am; edited 1 time in total
Back to top
View user's profile Send private message
pbd4499
General User
General User


Joined: 04 Jun 2007
Posts: 23

PostPosted: Thu Nov 29, 2007 3:57 am    Post subject: print first page to tray 2 and other pages to tray one Reply with quote

First you need to make your page settings:
Default pages routed to 'First Page'
Create a new one: 'Next Pages' and route First Page to Next Pages. Make in both the definitions you appreciate then you're done. Next step is the code below.

printing problem solved:
'Copy listing as below in a new "BASIC module"

Code:
PUBLIC oDocument AS object, strStandardPrinter as string
DIM oDispatcher AS object, Doc AS Object, StyleFamilies AS Object, PageStyles AS Object, _
DefPage AS Object, Document AS object, Dispatcher AS object, oDialog3

Sub DisplayPrinterProperties()
DIM Props, i%, s$, v, sName$

On Error Resume Next
Props = ThisComponent.getPrinter()

FOR i = 0 To UBound(Props)
sName = props(i).Name
v = props(i).Value
s = s & sName & " = "

if i=0 THEN
strStandardPrinter = v
END IF

IF sName = "PaperOrientation" THEN
REM com.sun.star.view.PaperOrientation.LANDSCAPE also supported
s = s & IIF(v=com.sun.star.view.PaperOrientation.PORTRAIT, "Portrait", "Landscape") & " = " & CStr(v)
ELSEIF sName = "PaperFormat" THEN
Select Case v
Case com.sun.star.view.PaperFormat.A3
s = s & "A3"
Case com.sun.star.view.PaperFormat.A4
s = s & "A4"
Case com.sun.star.view.PaperFormat.A5
s = s & "A5"
Case com.sun.star.view.PaperFormat.B4
s = s & "B4"
Case com.sun.star.view.PaperFormat.B5
s = s & "B5"
Case com.sun.star.view.PaperFormat.LETTER
s = s & "LETTER"
Case com.sun.star.view.PaperFormat.LEGAL
s = s & "LEGAL"
Case com.sun.star.view.PaperFormat.TABLOID
s = s & "TABLOID"
Case com.sun.star.view.PaperFormat.USER
s = s & "USER"
Case ELSE
s = s & "UnkNOWn value"
End Select

s = s & " = " & CStr(v)
ELSEIF sName = "PaperSize" THEN
REM type is com.sun.star.awt.Size
REM The size is in TWIPS and there are 1440 twips per inch
s=s & CDbl(v.Width)/1440.0 & "x" & CDbl(v.Height)/1440.0 & " (inches)"
s=s & (CDbl(v.Width)/1440.0) * 2.54 & "x" & (CDbl(v.Height)/1440.0) * 2.54 & " (cm)"
ELSE
s = s & CStr(v)
END IF

s = s & CHR$(10)
Next

End Sub


Code:
Function PrintOut(iFirstPage as string, iNextPages as string, iCopies as long)
DisplayPrinterProperties
oDocument = StarDesktop.getCurrentComponent
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatcher.executeDispatch(oDocument.getCurrentController().getFrame(),_
".uno:Printer", "", 0,_
Array(MakePropertyValue("Printer", "\\" + strStandardPrinter)))

' "First Page" & "Next Pages" must be setup with functionkey F11 which consist the page policy for the firstpage & next pages
oPageStyle = oDocument.StyleFamilies.GetByName("PageStyles").GetByName("First Page")
oPageStyle.PrinterPaperTray=iFirstPage

oPageStyle = oDocument.StyleFamilies.GetByName("PageStyles").GetByName("Next Pages")
oPageStyle.PrinterPaperTray=iNextPages

Document = ThisComponent.CurrentController.Frame
Dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
DIM args1(2) AS new com.sun.star.beans.PropertyValue

args1(0).Name = "Copies"
args1(0).Value = iCopies
args1(1).Name = "RangeText"
args1(1).Value = iPage
args1(2).Name = "Collate"
args1(2).Value = false

dispatcher.executeDispatch(Document, ".uno:Print", "", 0, args1())
End Function

Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
Dim oPropertyValue As New com.sun.star.beans.PropertyValue

If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf

If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf

MakePropertyValue() = oPropertyValue
End Function


'call this line to print all to tray 1: NOTE: "Tray" = printer independent!!!(lookup the right tray names with your printerconfig settings, they're different from XP & OOo)
Code:
PrintOut("Tray 1", "Tray 1", cInt(oDialog3.Model.txtCopies.text))
'call this line to print all to tray 2:
Code:
PrintOut("Tray 2", "Tray 2", cInt(oDialog3.Model.txtCopies.text))

'call this line to print all to tray 3:
Code:
PrintOut("Tray 3", "Tray 3", cInt(oDialog3.Model.txtCopies.text))

'call this line to print 1st page to Tray2 and next pages to Tray1:
Code:
PrintOut("Tray 2", "Tray 1", cInt(oDialog3.Model.txtCopies.text))
Back to top
View user's profile Send private message
groverblue
General User
General User


Joined: 13 Jul 2007
Posts: 48

PostPosted: Mon Mar 24, 2008 7:47 am    Post subject: Reply with quote

I'm using similar code in Java, but PrinterPaperTray is being used as the input tray. How can you be using it as the output tray?

These are my defined trays:

Code:
INPUT TRAYS:
Bypass Tray
Tray 1
Tray 2

OUTPUT TRAYS
Inner Tray 1 (Lower)


This is the code I use to set the input tray.

Code:

/**
* 1. Get the Text of the Document
* 2. Create a text cursor from the cells XText interface
* 3. Get the property set of the cell's TextCursor
* 4. Get teh "PageStyleName" of the Document
* 5. Get the StyleFamiliesSupplier interface of the document
* 6. Use the StyleFamiliesSupplier interface to get the XNameAccess interface of the actual style families
* 7. Access the 'PageStyles' Family
* 8. Get the property set of the cell's TextCursor
*/
XTextDocument aTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xcomp);
XText xText = aTextDocument.getText();
XTextCursor xTextCursor = xText.createTextCursor();
XPropertySet xTextCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
String pageStyleName = xTextCursorProps.getPropertyValue("PageStyleName").toString();
XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, aTextDocument);
XNameAccess xFamilies = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xSupplier.getStyleFamilies());
XNameContainer xFamily = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xFamilies.getByName("PageStyles"));
XStyle xStyle = (XStyle) UnoRuntime.queryInterface(XStyle.class, xFamily.getByName(pageStyleName));
XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStyle);

// my PageStyleSetting ...
//"PrinterPaperTray"
xStyleProps.setPropertyValue("PrinterPaperTray","Tray 1");
Back to top
View user's profile Send private message Visit poster's website AIM Address
groverblue
General User
General User


Joined: 13 Jul 2007
Posts: 48

PostPosted: Mon Mar 24, 2008 10:52 am    Post subject: Reply with quote

I checked out the following, but all of OOo source is too much for me to go through at the moment. It seems as though any extra output setting are not accessible. Anyone have any ideas? Aren't there any OOo developers in these forums?

Code:
svtools\source\dialogs\prnsetup.cxx
svtools\source\dialogs\printdlg.cxx
vcl\source\gdi\print.cxx
Back to top
View user's profile Send private message Visit poster's website AIM Address
groverblue
General User
General User


Joined: 13 Jul 2007
Posts: 48

PostPosted: Wed Feb 03, 2010 9:26 am    Post subject: I just wanted to follow up on this post. Reply with quote

Summary: Extend service PrinterDescriptor with properties for paperbin(s)
Resolution: FIXED
Issue type: ENHANCEMENT
Target milestone: OOo 3.2
http://www.openoffice.org/issues/show_bug.cgi?id=87495
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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