Personal tools
You are here: Home Forum Nice Office Access (NOA) Background image

 • Background image

Replies: 5   Views: 157
Up one level

 • Background image

Posted by RuiRosado at 2010-11-04 21:24:09
Hi all,

I would like to add a background image to a multi-page text document.
In OpenOffice.org one can use the menu like e.g.: Format>Page>Background, choose Graphic in the dropdown, etc.
Now I would like to do this dynamically, i.e. insert a different background in a certain document depending on its status. Like e.g. a big lightgray "Concept" when it has not been reviewed, and a big lightgray "Final" when it has been reviewed and accepted.
How can I do this with NOA? Can I use a dispatcher on ".uno:FormatMenu" for this? But which propertyValues to set? Any examples or tips?

Thanks in advance for any help ...

Cheers,
Rui
RuiRosado Member
Posts: 6

 • Re: Background image

Posted by Markus Krueger at 2010-11-08 09:15:29
Hi Rui,

this is not implemented yet, but you can do this:

ITextDocument doc = (ITextDocument) documentService.constructNewDocument(IDocument.WRITER,
    DocumentDescriptor.DEFAULT);
XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
    doc.getXTextDocument());
XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
    doc.getXTextDocument());
XNameContainer xBitmapContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class,
    xMultiServiceFactory.createInstance("com.sun.star.drawing.BitmapTable"));
String tempId = "tempImageId" + System.currentTimeMillis();
xBitmapContainer.insertByName(tempId, "file:///P:/tests/my_image.gif");
String internalURL = AnyConverter.toString(xBitmapContainer.getByName(tempId));
XNameAccess xNameAccess = xSupplier.getStyleFamilies();
XNameContainer xPageStyleCollection = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class,
    xNameAccess.getByName("PageStyles"));
XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
    xPageStyleCollection.getByName("Standard"));
xPropertySet.setPropertyValue("BackGraphicURL", internalURL);
xPropertySet.setPropertyValue("BackGraphicLocation", GraphicLocation.LEFT_TOP);


Regards,

Markus
Markus Krueger Member
Posts: 507

 • Re: Background image

Posted by RuiRosado at 2010-11-08 12:24:11
Thank you Markus, I'm going to try this, and will let you know of my results.

Best regards,
Rui
RuiRosado Member
Posts: 6

 • Re: Background image

Posted by RuiRosado at 2010-11-14 21:22:11
Hi Markus,

I tried to get your suggestion to run, but at no success!Maybe you can still help me:
My situation is as follows:
- I'm opening a odt document in an ag.ion.bion.workbench.office.editor.ui.editors.OfficeEditor through
page.openEditor( editorInput, ..., true)
editorInput is a FileStoreEditorInput.
- I added a 'partOpened' listener: page.addPartListener(..) to postWindowCreate() in
ApplicationWorkbenchWindowAdvisor:
...
public void partOpened(IWorkbenchPart part) {
if (part instanceof AbstractOfficeEditor) {
final OfficeEditor editor = (OfficeEditor) part;
final IDocument document = editor.getDocument();
addDocumentListener(document(new IDocumentListener() {
public void onLoadDone(IDocumentEvent documentEvent) {
try {
insertBackground(document);
}
catch (Exception e1) {
e1.printStackTrace();
}
catch (java.lang.Exception e) {
e.printStackTrace();
}
}
}));
document.fireDocumentEvent(IDocument.EVENT_ON_LOAD_DONE);
...
- the method insertBackground() contains more or less your code-snippet as in your previous post, where I
used ITextDocument doc = (ITextDocument) document, instead of your (ITextDocument)
documentService.construct ... in your example.

When I run (debug) the code I can see that I get into the insertBackground() method, there is a document, but the xMultiServiceFactory and xSupplier that the UnoRuntime.queryInterface returns are both null.

Do you have any hints on where I could have gone wrong?

Thank you, and best regards.
Rui
PS I'm going to dive in the openoffice API, but it migth be just a small omission ...
RuiRosado Member
Posts: 6

 • Re: Background image

Posted by RuiRosado at 2010-11-15 10:15:00
Hi Markus,

I just wanted to point out that your code-snippet works well if I depart from an IOfficeApplication and construct a ITextDocument using the IOfficeApplication#getDocumentService().
So, apparently, my problem is: not being able to get valid results from UnoRuntime when it is embedded in an RCP application.

Cheers,
Rui
RuiRosado Member
Posts: 6

 • Re: Background image

Posted by RuiRosado at 2010-12-05 17:19:44
Hi Markus,

This is just to tell you that I got the background-image inserted using your suggestion above.
The fact that I got NPE's in the beginning was due to a setup error that caused UNORuntime not to be found.
I updated the classpaths, etc. and almost everything works fine now. I still have to figure out how to add this to every page of a document, but I am confident I will succeed in this too.
Thanks again for your help.

Cheers,
Rui
RuiRosado Member
Posts: 6

Powered by Plone, the Open Source Content Management System

This site conforms to the following standards: