-1

I have set PaperOrientation and PaperFormat but I can't find where to set right,left,page margin. xPageProps always equals null.

static void setPaper(Object oDoc_To_Store, com.sun.star.view.PaperOrientation paperOrientation,com.sun.star.view.PaperFormat paperFormat) {
    com.sun.star.view.XPrintable xPrintable = 
            UnoRuntime.queryInterface(
            com.sun.star.view.XPrintable.class, oDoc_To_Store);
    com.sun.star.beans.PropertyValue[] pv = new com.sun.star.beans.PropertyValue[2];
    pv[0] = new PropertyValue();
    pv[0].Name="PaperOrientation";
    pv[0].Value=paperOrientation;//com.sun.star.view.PaperOrientation.LANDSCAPE;
   // pv[0].State=pv[0].State.DEFAULT_VALUE;
    pv[1] = new PropertyValue();
    pv[1].Name="PaperFormat";
    pv[1].Value=paperFormat;//com.sun.star.view.PaperFormat.A4;
  //  pv[1].State=pv[0].State.DEFAULT_VALUE;

    xPrintable.setPrinter(pv)

    com.sun.star.beans.XPropertySet xPageProps = (com.sun.star.beans.XPropertySet)
        UnoRuntime.queryInterface(
            com.sun.star.beans.XPropertySet.class, xDrawPage);
    if ((xPageProps!=null)) {// Always = null,
        System.out.println("++++++++ xPageProps!=null");
        Property[] pp = xPageProps.getPropertySetInfo().getProperties();// 
        int ii =pp.length;
        for (int i = 0; i < pp.length; i++) {
              System.out.println(pp[i].Name+" "+pp[i].Attributes+" "+pp[i].Type);
        }
    }
John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

0

In my answer at Python libreoffice set margin values, optimal height and print document with uno, there is Python code that sets the LeftMargin property as an example.

Here is some C# code I haven't tried, but should hopefully give an idea of the specific UNO interfaces needed in Java: OpenOffice 3 text document - set page size and margins

The developer guide at https://wiki.documentfoundation.org/Documentation/DevGuide/Text_Documents#Page_Layout is informative:

A page layout in LibreOffice is always a page style. A page can not be hard formatted. To change the current page layout, retrieve the current page style from the text cursor property PageStyleName and get this page style from the StyleFamily PageStyles.

Check out the API docs if you haven't yet: https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1style_1_1PageProperties.html

Jim K
  • 12,824
  • 2
  • 22
  • 51