Difference between revisions of "Documentation/DevGuide/Text/Printing Text Documents"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Initial author Sun Microsystems, Inc.)
 
 
(8 intermediate revisions by 5 users not shown)
Line 5: Line 5:
 
|NextPage=Documentation/DevGuide/Text/Working with Text Documents
 
|NextPage=Documentation/DevGuide/Text/Working with Text Documents
 
}}
 
}}
{{DISPLAYTITLE:Printing Text Documents}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Text/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Printing Text Documents}}
 
=== Printer and Print Job Settings ===
 
=== Printer and Print Job Settings ===
 
<!--<idltopic>com.sun.star.view.XPrintable</idltopic>-->
 
<!--<idltopic>com.sun.star.view.XPrintable</idltopic>-->
 
Printing is a common office functionality. The chapter [[Documentation/DevGuide/OfficeDev/Office Development|Office Development]] provides in-depth information about it. The writer document implements the <idl>com.sun.star.view.XPrintable</idl> interface for printing. It consists of three methods:
 
Printing is a common office functionality. The chapter [[Documentation/DevGuide/OfficeDev/Office Development|Office Development]] provides in-depth information about it. The writer document implements the <idl>com.sun.star.view.XPrintable</idl> interface for printing. It consists of three methods:
 
+
<syntaxhighlight lang="idl">
 
   sequence< com::sun::star::beans::PropertyValue > getPrinter ()
 
   sequence< com::sun::star::beans::PropertyValue > getPrinter ()
 
   void setPrinter ( [in] sequence< com::sun::star::beans::PropertyValue > aPrinter)
 
   void setPrinter ( [in] sequence< com::sun::star::beans::PropertyValue > aPrinter)
 
   void print ( [in] sequence< com::sun::star::beans::PropertyValue > xOptions)
 
   void print ( [in] sequence< com::sun::star::beans::PropertyValue > xOptions)
 
+
</syntaxhighlight>
 
The following code is used with a given document xDoc to print to the standard printer without any settings:  
 
The following code is used with a given document xDoc to print to the standard printer without any settings:  
 
<!--[SOURCE:Text/TextDocuments.java]-->
 
<!--[SOURCE:Text/TextDocuments.java]-->
 
+
<syntaxhighlight lang="java">
 
   // query the XPrintable interface from your document
 
   // query the XPrintable interface from your document
 
   XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
 
   XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
Line 25: Line 26:
 
   // kick off printing
 
   // kick off printing
 
   xPrintable.print(printOpts);
 
   xPrintable.print(printOpts);
 
+
</syntaxhighlight>
 
There are two groups of properties involved in general printing. The first one is used with <code>setPrinter()</code> and <code>getPrinter()</code> that controls the printer, and the second one is passed to <code>print()</code> and controls the print job.
 
There are two groups of properties involved in general printing. The first one is used with <code>setPrinter()</code> and <code>getPrinter()</code> that controls the printer, and the second one is passed to <code>print()</code> and controls the print job.
  
[http://api.openoffice.org/docs/common/ref/com/sun/star/view/PrinterDescriptor.html :com.sun.star.view.PrinterDescriptor] comprises the properties for the printer:
+
<idl>com.sun.star.view.PrinterDescriptor</idl> comprises the properties for the printer:
  
 
{|border="1" cellpadding=4 style="border-collapse:collapse;"
 
{|border="1" cellpadding=4 style="border-collapse:collapse;"
Line 61: Line 62:
  
 
<idl>com.sun.star.view.PrintOptions</idl> contains the following possibilities for a print job:
 
<idl>com.sun.star.view.PrintOptions</idl> contains the following possibilities for a print job:
 
  
 
{|border="1" cellpadding=4 style="border-collapse:collapse;"
 
{|border="1" cellpadding=4 style="border-collapse:collapse;"
Line 78: Line 78:
 
|<idlm>com.sun.star.view.PrintOptions:Pages</idlm>  
 
|<idlm>com.sun.star.view.PrintOptions:Pages</idlm>  
 
|<code>string</code> - Specifies the pages to print in the same format as in the print dialog of the GUI (e.g. "1, 3, 4-7, 9-")  
 
|<code>string</code> - Specifies the pages to print in the same format as in the print dialog of the GUI (e.g. "1, 3, 4-7, 9-")  
 +
|-
 +
|<idlm>com.sun.star.view.PrintOptions:Wait</idlm>
 +
|<code>boolean</code> - Advises that the print job should be performed synchronously, i.e. wait until printing is complete before returning from printing. Otherwise return is immediate and following actions (e.g. closing the corresponding model) may fail until printing is complete. Default is false.
 
|}
 
|}
  
 
The following method uses <code>PrinterDescriptor</code> and <code>PrintOptions</code> to print to a special printer, and preselect the pages to print.  
 
The following method uses <code>PrinterDescriptor</code> and <code>PrintOptions</code> to print to a special printer, and preselect the pages to print.  
 
<!--[SOURCE:Text/TextDocuments.java]-->
 
<!--[SOURCE:Text/TextDocuments.java]-->
 
+
<syntaxhighlight lang="java">
 
   protected void printDocComponent(XComponent xDoc) throws java.lang.Exception {
 
   protected void printDocComponent(XComponent xDoc) throws java.lang.Exception {
 
       XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
 
       XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
Line 99: Line 102:
 
       xPrintable.print(printOpts);
 
       xPrintable.print(printOpts);
 
   }
 
   }
 
+
</syntaxhighlight>
 
=== Printing Multiple Pages on one Page ===
 
=== Printing Multiple Pages on one Page ===
  
 
<!--<idltopic>com.sun.star.text.XPagePrintable</idltopic>-->
 
<!--<idltopic>com.sun.star.text.XPagePrintable</idltopic>-->
 
The interface <idl>com.sun.star.text.XPagePrintable</idl> is used to print more than one document page to a single printed page.  
 
The interface <idl>com.sun.star.text.XPagePrintable</idl> is used to print more than one document page to a single printed page.  
 
+
<syntaxhighlight lang="idl">
 
   sequence< com::sun::star::beans::PropertyValue > getPagePrintSettings()
 
   sequence< com::sun::star::beans::PropertyValue > getPagePrintSettings()
 
   void setPagePrintSettings( [in] sequence< com::sun::star::beans::PropertyValue > aSettings)
 
   void setPagePrintSettings( [in] sequence< com::sun::star::beans::PropertyValue > aSettings)
 
   void printPages( [in] sequence< com::sun::star::beans::PropertyValue > xOptions)  
 
   void printPages( [in] sequence< com::sun::star::beans::PropertyValue > xOptions)  
 
+
</syntaxhighlight>
 
The first two methods <code>getPagePrintSettings()</code> and <code>setPagePrintSettings()</code> control the page printing. They use a sequence of <idl>com.sun.star.beans.PropertyValue</idl>s whose possible values are defined in <idl>com.sun.star.text.PagePrintSettings</idl>:
 
The first two methods <code>getPagePrintSettings()</code> and <code>setPagePrintSettings()</code> control the page printing. They use a sequence of <idl>com.sun.star.beans.PropertyValue</idl>s whose possible values are defined in <idl>com.sun.star.text.PagePrintSettings</idl>:
  
Line 118: Line 121:
 
|<code>short</code> - Number of rows in which document pages should appear on the output page.  
 
|<code>short</code> - Number of rows in which document pages should appear on the output page.  
 
|-
 
|-
|<idlm>com.sun.star.text.PagePrintSettings:ageColumns</idlm>  
+
|<idlm>com.sun.star.text.PagePrintSettings:PageColumns</idlm>  
 
|<code>short</code> - Number of columns in which document pages should appear on the output page.  
 
|<code>short</code> - Number of columns in which document pages should appear on the output page.  
 
|-
 
|-
Line 146: Line 149:
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Text Documents]]
+
 
 +
[[Category:Documentation/Developer's Guide/Text Documents]]

Latest revision as of 13:49, 3 January 2021



Printer and Print Job Settings

Printing is a common office functionality. The chapter Office Development provides in-depth information about it. The writer document implements the com.sun.star.view.XPrintable interface for printing. It consists of three methods:

  sequence< com::sun::star::beans::PropertyValue > getPrinter ()
  void setPrinter ( [in] sequence< com::sun::star::beans::PropertyValue > aPrinter)
  void print ( [in] sequence< com::sun::star::beans::PropertyValue > xOptions)

The following code is used with a given document xDoc to print to the standard printer without any settings:

  // query the XPrintable interface from your document
  XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
  
  // create an empty printOptions array
  PropertyValue[] printOpts = new PropertyValue[0];
  
  // kick off printing
  xPrintable.print(printOpts);

There are two groups of properties involved in general printing. The first one is used with setPrinter() and getPrinter() that controls the printer, and the second one is passed to print() and controls the print job.

com.sun.star.view.PrinterDescriptor comprises the properties for the printer:

Properties of com.sun.star.view.PrinterDescriptor
Name string - Specifies the name of the printer queue to be used.
PaperOrientation com.sun.star.view.PaperOrientation. Specifies the orientation of the paper.
PaperFormat com.sun.star.view.PaperFormat. Specifies a predefined paper size or if the paper size is a user-defined size.
PaperSize com.sun.star.awt.Size. Specifies the size of the paper in 1/100 mm.
IsBusy boolean - Indicates if the printer is busy.
CanSetPaperOrientation boolean - Indicates if the printer allows changes to PaperOrientation.
CanSetPaperFormat boolean - Indicates if the printer allows changes to PaperFormat.
CanSetPaperSize boolean - Indicates if the printer allows changes to PaperSize.


com.sun.star.view.PrintOptions contains the following possibilities for a print job:

Properties of com.sun.star.view.PrintOptions
CopyCount short - Specifies the number of copies to print.
FileName string - Specifies the name of a file to print to, if set.
Collate boolean - Advises the printer to collate the pages of the copies. If true, a whole document is printed prior to the next copy, otherwise the page copies are completed together.
Pages string - Specifies the pages to print in the same format as in the print dialog of the GUI (e.g. "1, 3, 4-7, 9-")
Wait boolean - Advises that the print job should be performed synchronously, i.e. wait until printing is complete before returning from printing. Otherwise return is immediate and following actions (e.g. closing the corresponding model) may fail until printing is complete. Default is false.

The following method uses PrinterDescriptor and PrintOptions to print to a special printer, and preselect the pages to print.

  protected void printDocComponent(XComponent xDoc) throws java.lang.Exception {
      XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
      PropertyValue[] printerDesc = new PropertyValue[1];
      printerDesc[0] = new PropertyValue();
      printerDesc[0].Name = "Name";
      printerDesc[0].Value = "5D PDF Creator"; 
  
      xPrintable.setPrinter(printerDesc); 
  
      PropertyValue[] printOpts = new PropertyValue[1];
      printOpts[0] = new PropertyValue();
      printOpts[0].Name = "Pages";
      printOpts[0].Value = "3-5,7"; 
  
      xPrintable.print(printOpts);
  }

Printing Multiple Pages on one Page

The interface com.sun.star.text.XPagePrintable is used to print more than one document page to a single printed page.

  sequence< com::sun::star::beans::PropertyValue > getPagePrintSettings()
  void setPagePrintSettings( [in] sequence< com::sun::star::beans::PropertyValue > aSettings)
  void printPages( [in] sequence< com::sun::star::beans::PropertyValue > xOptions)

The first two methods getPagePrintSettings() and setPagePrintSettings() control the page printing. They use a sequence of com.sun.star.beans.PropertyValues whose possible values are defined in com.sun.star.text.PagePrintSettings:

Properties of com.sun.star.text.PagePrintSettings
PageRows short - Number of rows in which document pages should appear on the output page.
PageColumns short - Number of columns in which document pages should appear on the output page.
LeftMargin long - Left margin on the output page.
RightMargin long - Right margin on the output page.
TopMargin long - Top margin on the output page.
BottomMargin long - Bottom margin on the output page.
HoriMargin long - Margin between the columns on the output page.
VertMargin long - Margin between the rows on the output page.
IsLandscape boolean - Determines if the output page is in landscape format.

The method printPages() prints the document according to the previous settings. The argument for the printPages() method may contain the PrintOptions as described in the section above (containing the properties CopyCount, FileName, Collate and Pages).

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages