Setting IsPrintFitPage via C# API has no effect during print

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
edooforum
Posts: 1
Joined: Mon Apr 08, 2013 9:03 pm

Setting IsPrintFitPage via C# API has no effect during print

Post by edooforum »

I am trying to print via the API(AOO 3.4.1) a Presentation document and set the "IsPrintFitPage" setting.
The setting does not seem to work. For example, print a Tabloid presentation to a printer with Letter size paper.

Using the desktop application and selecting the "Fit to Page" checkbox on the Print dialog, will fit the
Tabloid presentation page to the Letter paper size. However, following the API instructions below does not seem to work.

http://wiki.openoffice.org/wiki/Documen ... _Documents
http://wiki.openoffice.org/wiki/Documen ... s/Settings

The following code will load a document and print to file.
But setting "IsPrintFitPage", has no effect on presentations bigger than printer paper size.
Thanks in advance for any help to resolve this.

Example code:

Code: Select all

public static void PrintToFile(string inputFilename, string outputFilename, string printerQueue)
{
    XComponentContext _xContext = uno.util.Bootstrap.bootstrap();
    XMultiComponentFactory _xService = _xContext.getServiceManager();

    // create the component loader
    Object desktop = _xService.createInstanceWithContext("com.sun.star.frame.Desktop", _xContext);
    XComponentLoader xComponentLoader = (XComponentLoader)desktop;
 
    // set the load properties
    PropertyValue[] loadProps = new PropertyValue[1];
    loadProps[0] = new PropertyValue() { Name = "Hidden", Value = new Any(true) };

    // load the file uri
    Uri fileUri = new Uri(inputFilename, UriKind.Absolute);
    XComponent xComponent = xComponentLoader.loadComponentFromURL(fileUri.AbsoluteUri, "_blank", 0, loadProps);

    // get the print interface for the component
    XPrintable xPrintable = (XPrintable)xComponent;

    // set printer
    List<PropertyValue> printerDesc = new List<PropertyValue>();
    printerDesc.Add(new PropertyValue() { Name = "Name", Value = new Any(printerQueue) });
    xPrintable.setPrinter(printerDesc.ToArray());

    // set fit to page for presentation type document
    XMultiServiceFactory factory = (XMultiServiceFactory)xComponent;
    object docSettings = factory.createInstance("com.sun.star.presentation.DocumentSettings");
    if (docSettings != null)
    {
        XPropertySet propSet = (XPropertySet)docSettings;
        propSet.setPropertyValue("IsPrintFitPage", new Any(true));
    }

    // create output file name uri
    Uri outputFileUri = new Uri(outputFilename, UriKind.Absolute);

    // create an printOptions array that will hold specific and generic print properties.
    List<PropertyValue> printOpts = new List<PropertyValue>();
    printOpts.Add(new PropertyValue() { Name = "FileName", Value = new Any(outputFileUri.AbsoluteUri) });
    printOpts.Add(new PropertyValue() { Name = "Wait", Value = new Any(true) });
    printOpts.Add(new PropertyValue() { Name = "Collate", Value = new Any(true) });
    printOpts.Add(new PropertyValue() { Name = "CopyCount", Value = new Any((short)1) });

    // kick off printing
    xPrintable.print(printOpts.ToArray());

    xComponent.dispose();   
}
OpenOffice 3.4.1 on Windows 7
Post Reply