MSK Software Development

OpenOffice

Development Blog moved …

by admin on Aug.26, 2010, under .NET, Mac, OpenOffice, Smalltalk, Unix and Linux

I moved my development blog to schrievkrom.wordpress.com … my more private posting will stay at www.schrievkrom.de

Leave a Comment more...

Printing under C# and OpenOffice

by admin on Aug.14, 2009, under .NET, OpenOffice

We have an application which uses OpenOffice (3.0/3.1) under Windows and .NET 3.5 more or less as a reporting tool. Whatever I do I did not manage to get printing done in a reliable way, that works for hundreds of reports (one page size).

I tried API way, I tried dispatcher way - more or less I noticed, that my C# application simply hangs at some points (in the print() method):

XPrintable aPrintableDocument = (XPrintable)this._aOOTextDocHelper.mxDocument;
PropertyValue[] propValues = new PropertyValue[1];
propValues[0] = new PropertyValue { Name = "Name", Value = new Any(theSetting.PrinterName)};
aPrintableDocument.setPrinter(propValues);
propValues = new PropertyValue[2];
propValues[0] = new PropertyValue { Name = "CopyCount", Value = new Any((short) theSetting.CopiesToPrint) };
propValues[1] = new PropertyValue { Name = "Wait", Value = new Any(true)};
aPrintableDocument.print(propValues);

Very often the system hangs then in the last line …. and the printer shows, that second job is going to be
added and the state information shows “In Warteschlange”. Number of pages are N/V. This continues for several
minutes and then the job finshed.

Yesterday I changed the printing method to:

XPrintable aPrintableDocument = (XPrintable)this._aOOTextDocHelper.mxDocument;
PropertyValue[] propValues = new PropertyValue[1];
propValues[0] = new PropertyValue { Name = "Name", Value = new Any(theSetting.PrinterName)};
aPrintableDocument.setPrinter(propValues);
propValues = new PropertyValue[2];
propValues[0] = new PropertyValue { Name = "CopyCount", Value = new Any((short) theSetting.CopiesToPrint) };
// !!! false !!!!
propValues[1] = new PropertyValue { Name = "Wait", Value = new Any(false)};
// check for ending
bool abort = false;
while (!abort)
{
   System.Threading.Thread.Sleep((100));
   PropertyValue[] stateValues = aPrintableDocument.getPrinter();
   for (int index = 0; index < stateValues.Length; index++)
   {
     PropertyValue aValue = stateValues[index];
     if (aValue.Name == "IsBusy")
     {
       abort = !(bool)aValue.Value.Value;
       break;
     }
   }
}

And problems were reduced radically.

I am not sure if this is a reliable solution, but it works much better, that with wait=true, which is published as a standard way.

Leave a Comment more...

OOWrapper 2008-12-22

by admin on Dec.22, 2008, under OpenOffice

New version. This was needed because of errors in the code generation in the MasterField area. Additional examples showing available TextFields within a document and how to fill TextFields from an application.

The following code shows all all available master fields within a document:

writerOpenEmptyAndPrintKnownFieldMasters
	"Within this example print the names of all known field masters within a newly created document
 
		MSKOOoExamples new initialize writerOpenEmptyAndPrintKnownFieldMasters
	"
 
	<PIPE> writerDocument <PIPE>
 
 
		(writerDocument := OOTextTextDocument fromURL: (self getAsURLTestDocumentNamed: 'testUserFields.odt')) isAbtError
		ifFalse:[
			<PIPE> xNamedAccess <PIPE>
 
			xNamedAccess :=  writerDocument getTextFieldMasters.
			xNamedAccess getElementType inspect.
			xNamedAccess getElementNames do: [:eachString <PIPE>
				<PIPE> singleField introspection aComSunStarBeansXIntrospectionAccess <PIPE>
				singleField := xNamedAccess getByName: eachString.
				(singleField supportsService: OOTextFieldMasterUser)
					ifTrue:[						
						Transcript
							cr<SEMI>
							show: 'Name of known master field ...' <SEMI>
							show: eachString<SEMI>
							show: ' understand services: ', OOTextFieldMasterUser starName.
						]
 
			]
		]

The example opens a known document and fills out the text fields:

writerFillTextFieldsInDocument
	"Within this example we simply create a an empty writer document
 
		MSKOOoExamples new initialize writerFillTextFieldsInDocument
 
	"
 
	<PIPE> writerDocument aDictionary <PIPE>
 
 
	aDictionary := Dictionary new.
	aDictionary
		at: 'firstField' put: 'VASmalltalk' <SEMI>
		at: 'secondField' put: ' is a good development'<SEMI>
		at: 'thirdField' put: ' IDE'.
 
 
	(writerDocument := OOTextTextDocument fromURL: (self getAsURLTestDocumentNamed: 'testUserFields.odt')) isAbtError
		ifFalse:[
			writerDocument 
				updateContentOfUserTextFields: aDictionary <SEMI>
				refreshVisibleTextFields
		]

Here is the new complete code:

Archive-2008-12-22

Leave a Comment more...

OpenOffice 3.0 and Wrapper

by admin on Dec.16, 2008, under OpenOffice

It works ! The reason was simple. Do not use URL’s like “file:///c:\test.odt” - instead you must use “file:///c:/test.odt” and everything is ok.

Leave a Comment more...

loadComponentFromURL and OpenOffice 3.0

by admin on Dec.14, 2008, under OpenOffice

Bad luck - I was not able to make this API call runnable in a good way - all documents are opened in a read-only way and I can not find the error. The same code works with OO 2.4.1.

Due to the fact, that this API call is a pretty important one I can only suggest to stay with 2.4.1 - if you want to use OpenOffice with OLE …

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...