Difference between revisions of "AODL example 17"
From Apache OpenOffice Wiki
m |
|||
| Line 6: | Line 6: | ||
<b>Remarks:</b> The OpenOfficeLib is an add on library for AODL. It's a simple wrapper for the CLI UNO assemblies | <b>Remarks:</b> The OpenOfficeLib is an add on library for AODL. It's a simple wrapper for the CLI UNO assemblies | ||
which are part of OpenOffice.org since vers. 1.9.x. In contrast to the AODL library the OpenOfficeLib will need an | which are part of OpenOffice.org since vers. 1.9.x. In contrast to the AODL library the OpenOfficeLib will need an | ||
| − | existing OpenOffice | + | existing Apache OpenOffice installation in order to work! |
| − | < | + | <syntaxhighlight lang="c"> |
using System; | using System; | ||
using NUnit.Framework; | using NUnit.Framework; | ||
| Line 36: | Line 36: | ||
/// Creates the new document and print it out. | /// Creates the new document and print it out. | ||
/// </summary> | /// </summary> | ||
| − | [Test (Description="Simple print test. OpenOffice | + | [Test (Description="Simple print test. Apache OpenOffice installation and printer must exist."), Explicit] |
public void CreateNewDocumentAndDoAPrintOut() | public void CreateNewDocumentAndDoAPrintOut() | ||
{ | { | ||
| Line 70: | Line 70: | ||
} | } | ||
} | } | ||
| − | </ | + | </syntaxhighlight> |
Back to the [[AODL_examples|AODL examples]] overview. | Back to the [[AODL_examples|AODL examples]] overview. | ||
[[category:Summer of Code 2007]][[category:AODL]] | [[category:Summer of Code 2007]][[category:AODL]] | ||
Latest revision as of 12:47, 22 May 2022
Create a new TextDocument and use the OpenOfficeLib to do a print out
This example NUnit test will show how to create a new OpenDocument text document by using AODL and send it to a printer by using the new OpenOfficeLib.
Remarks: The OpenOfficeLib is an add on library for AODL. It's a simple wrapper for the CLI UNO assemblies which are part of OpenOffice.org since vers. 1.9.x. In contrast to the AODL library the OpenOfficeLib will need an existing Apache OpenOffice installation in order to work!
using System;
using NUnit.Framework;
using System.Xml;
using AODL.Document.Content.Tables;
using AODL.Document.TextDocuments;
using AODL.Document.Styles;
using AODL.Document.Content.Text;
using OpenOfficeLib.Connection;
using OpenOfficeLib.Document;
using OpenOfficeLib.Printer;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.bridge;
using unoidl.com.sun.star.frame;
namespace AODLTest
{
/// <summary>
/// OpenOfficeLibTests
/// </summary>
[TestFixture]
public class OpenOfficeLibTests
{
/// <summary>
/// Creates the new document and print it out.
/// </summary>
[Test (Description="Simple print test. Apache OpenOffice installation and printer must exist."), Explicit]
public void CreateNewDocumentAndDoAPrintOut()
{
string fileToPrint = "fileToPrint.odt";
//Create a new text document
TextDocument document = new TextDocument();
document.New();
//Create a standard paragraph using the ParagraphBuilder
Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
//Add some simple text
paragraph.TextContent.Add(new SimpleText(document, "Some simple text!"));
//Add the paragraph to the document
document.Content.Add(paragraph);
//Save empty
document.SaveTo(fileToPrint);
//Now print the new document via the OpenOfficeLib
//Get the Component Context
XComponentContext xComponentContext = Connector.GetComponentContext();
//Get a MultiServiceFactory
XMultiServiceFactory xMultiServiceFactory = Connector.GetMultiServiceFactory(xComponentContext);
//Get a Dektop instance
XDesktop xDesktop = Connector.GetDesktop(xMultiServiceFactory);
//Convert a windows path to an OpenOffice one
fileToPrint = Component.PathConverter(fileToPrint);
//Load the document you want to print
XComponent xComponent = Component.LoadDocument(
(XComponentLoader)xDesktop, fileToPrint, "_blank");
//Print the XComponent
Printer.Print(xComponent);
}
}
}
Back to the AODL examples overview.