// System.out.println("Document loaded.");
// Change Pagesettings to DIN A4
GlobalLogWriter.get().println(DateHelper.getDateTimeForHumanreadableLog() + " Print document.");
XPrintable aPrintable = UnoRuntime.queryInterface( XPrintable.class, _aDoc);
if (aPrintable != null)
{
// System.out.println(" Set PaperFormat to DIN A4");
// {
// PropertyValue[] aPrinterProps = aPrintable.getPrinter();
// System.out.println("PrinterProps size: " + String.valueOf(aPrinterProps.length));
// int nPropIndex = 0;
// while (!"PaperFormat".equals(aPrinterProps[nPropIndex].Name))
// {
// // System.out.println(aPrinterProps[nPropIndex].Name);
// nPropIndex++;
// }
// aPrinterProps[nPropIndex].Value = com.sun.star.view.PaperFormat.A4;
// aPrintable.setPrinter(aPrinterProps);
// }
// configure Office to allow to execute macos
// TODO: We need a possiblity to set the printer name also for StarOffice/OpenOffice
if (OSHelper.isWindows())
{
if (_aGTA.getPrinterName() != null)
{
ArrayList<PropertyValue> aPropertyList = new ArrayList<PropertyValue>();
// PropertyValue [] aPrintProps = new PropertyValue[1];
PropertyValue Arg = new PropertyValue();
Arg.Name = "Name";
Arg.Value = _aGTA.getPrinterName();
aPropertyList.add(Arg);
showProperty(Arg);
// GlobalLogWriter.get().println("Printername is not null, so set to " + _aGTA.getPrinterName());
aPrintable.setPrinter(PropertyHelper.createPropertyValueArrayFormArrayList(aPropertyList));
}
}
// set property values for XPrintable.print()
// more can be found at "http://api.openoffice.org/docs/common/ref/com/sun/star/view/PrintOptions.html"
// int nProperties = 1; // default for 'FileName' property
// if (_aGTA.printAllPages() == false)
// {
// // we don't want to print all pages, build Pages string by ourself
// nProperties ++;
// }
// int nPropsCount = 0;
// If we are a SpreadSheet (calc), we need to set PrintAllSheets property to 'true'
XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, _aDoc );
if ( xServiceInfo.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
{
XMultiServiceFactory xMSF = _aGTA.getMultiServiceFactory();
Object aSettings = xMSF.createInstance( "com.sun.star.sheet.GlobalSheetSettings" );
if (aSettings != null)
{
XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, aSettings );
xPropSet.setPropertyValue( "PrintAllSheets", new Boolean( true ) );
GlobalLogWriter.get().println("PrintAllSheets := true");
}
}
ArrayList<PropertyValue> aPrintProps = new ArrayList<PropertyValue>();
// GlobalLogWriter.get().println("Property FileName:=" + _sPrintFileURL);
// PropertyValue [] aPrintProps = new PropertyValue[nProperties];
PropertyValue Arg = new PropertyValue();
Arg.Name = "FileName";
Arg.Value = _sPrintFileURL;
// aPrintProps[nPropsCount ++] = Arg;
aPrintProps.add(Arg);
showProperty(Arg);
if (_aGTA.printAllPages() == false)
{
String sPages = "";
if (_aGTA.getMaxPages() > 0)
{
sPages = "1-" + String.valueOf(_aGTA.getMaxPages());
}
if (_aGTA.getOnlyPages().length() != 0)
{
if (sPages.length() != 0)
{
sPages += ";";
}
sPages += String.valueOf(_aGTA.getOnlyPages());
}
Arg = new PropertyValue();
Arg.Name = "Pages";
Arg.Value = sPages;
aPrintProps.add(Arg);
showProperty(Arg);
}
// GlobalLogWriter.get().println("Start printing.");
_aGTA.getPerformance().startTime(PerformanceContainer.Print);
aPrintable.print(PropertyHelper.createPropertyValueArrayFormArrayList(aPrintProps));
TimeHelper.waitInSeconds(1, "Start waiting for print ready.");
GlobalLogWriter.get().println("Wait until document is printed.");
boolean isBusy = true;
int nPrintCount = 0;
while (isBusy)
{
PropertyValue[] aPrinterProps = aPrintable.getPrinter();
int nPropIndex = 0;
while (!"IsBusy".equals(aPrinterProps[nPropIndex].Name))
{
// System.out.println(aPrinterProps[nPropIndex].Name);
nPropIndex++;