Problem - Print a document using LibreOffice in Linux [closed]

asked 2014-10-01 11:56:26 +0200

Murali gravatar image

We are trying to print a word document using LIbreoffice API in java(Linux environment). We got the below program from the Libreoffice official site to print a word document. We used the same program and modified only three parameters

  1. Document Path
  2. Printer Name
  3. Number of Pgaes

The code executes completely but we have received our printout in the required printer. We are trying to print docx file. When we tried to print the document using command prompt, it is working fine. Please find the command we used.

This shows there is no issues in the Printer Configuration or libreoffice installation or the document.

Please ssuggest is there anything we are doing wrong here. PFB, program for your reference. We have taken this program from libreoffice official site.

          try {

              XComponentContext xContext = null;
              String oooExeFolder = "D:\\OpenOffice 4\\program\\";
              // get the remote office component context
               xContext = BootstrapSocketConnector.bootstrap(oooExeFolder);

              // get the remote office service manager
     xMCF =

              Object oDesktop = xMCF.createInstanceWithContext(
                  "", xContext);

     xCompLoader =
                  (XComponentLoader) UnoRuntime.queryInterface(
          , oDesktop);

              File file = new File("D:\\Test.doc");
      //filename should be with complete path

     sourceFile = new"D:\\Test.doc"); 
              StringBuffer sUrl = new StringBuffer("file:///");
              sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));

              // Load a Writer document, which will be automaticly displayed
     xComp = xCompLoader.loadComponentFromURL(
                  sUrl.toString(), "_blank", 0,
                  new[0] );

              // Querying for the interface XPrintable on the loaded document
     xPrintable =
                  (XPrintable) UnoRuntime.queryInterface(
          , xComp);

              // Setting the property "Name" for the favoured printer (name of
              // IP address)
     propertyValue[] =
              propertyValue[0] = new;
              propertyValue[0].Name = "Name";
              propertyValue[0].Value = "myPrinter01";
              System.out.println("Printer Name "  + propertyValue[0].Value );

              // Setting the name of the printer
              xPrintable.setPrinter( propertyValue );

              // Setting the property "Pages" so that only the desired pages
              // will be printed.
              propertyValue[0] = new;
              propertyValue[0].Name = "Pages";
              propertyValue[0].Value = "1";

              // Printing the loaded document
              xPrintable.print( propertyValue );

             // System.exit(0);
      System.out.println("propertyValue" + propertyValue);

  }  catch (Exception e) {
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2016-03-04 16:10:10.999093