Ok so I have the below code for printing. The problem I have is that I have a document which needs to be separated into 2 or more print jobs. The reason is because it needs to print the first page on headed paper for each part of the document.
I’m wondering if it is possible to separate the printing of my doc into 2 or more jobs thus printing the headed paper on first page of each job. I can’t do this by calculating page numbers as they will be different everytime. I was thinking maybe its possible to detect a keyword and make an uno call to tell printer to create a new job for the second part of document. Any help is much appreciated. thanks
/**
* Method printDoc - print the current document to the default printer
*/
public void printDoc()
{
try
{
PropertyValue[] printOpts = new PropertyValue[1];
printOpts[0] = new PropertyValue();
printOpts[0].Name = "Wait";
printOpts[0].Value = new Boolean( true );
System.out.println( "Printing now" );
officeDoc.print( printOpts );
System.out.println( "Printing finished" ); }
catch (Throwable e)
{
System.out.println( "Printing failed" );
e.printStackTrace();
}
}
/**
* Method printDoc - print the current document to a named printer,
* specify the pages to print (e.g. "1, 3, 4-7, 9-")
* @param printerName - the name of the printer to print to
* @param pages - the number of pages to print
*/
public void printDoc(String printerName, String pages)
{
try
{
System.out.println("OODocument - Attempting to print page(s) " + pages + " to " + printerName + " printer.");
PropertyValue[] printerDesc = new PropertyValue[1];
printerDesc[0] = new PropertyValue();
printerDesc[0].Name = "Name";
printerDesc[0].Value = printerName;
System.out.println( "Setting printer to " + printerName );
officeDoc.setPrinter(printerDesc);
PropertyValue[] printOpts = new PropertyValue[2];
printOpts[0] = new PropertyValue();
printOpts[0].Name = "Pages";
printOpts[0].Value = pages;
//set printing to be synchronous
//see http://api.openoffice.org/docs/common/ref/com/sun/star/view/PrintOptions.html
printOpts[1] = new PropertyValue();
printOpts[1].Name = "Wait";
printOpts[1].Value = new Boolean( true );
System.out.println( "Printing now" );
long start = System.currentTimeMillis();
officeDoc.print(printOpts);
long end = System.currentTimeMillis();
System.out.println( "Printed. Took " + (end-start) + "ms" );
}
catch (Throwable e)
{
e.printStackTrace();
}
}