Java .odt文档中的图像:知道它在哪里并将其复制到另一个文档

Java .odt文档中的图像:知道它在哪里并将其复制到另一个文档,java,openoffice.org,openoffice-writer,Java,Openoffice.org,Openoffice Writer,我正在开发一个应用程序,它可以打开一个或多个.odt文档,并允许N个不同的客户端查看和编辑这些文档,而不是同时查看和编辑同一部分。关键是,我需要将一个部分或整个文档复制到另一个新文档中,以便另一个客户端可以对其进行编辑 为了复制文档,我在原始文档中逐个获取段落,并将其复制到新的可编辑文档中。到目前为止,我对文本没有任何问题(顺便说一句,多亏了stackoverflow),但我无法知道当前段落是文本还是图形,并复制该图形;实际上,图形被解释为空白段落 我已经看到了几个答案,包括,这有点帮助,但不符

我正在开发一个应用程序,它可以打开一个或多个.odt文档,并允许N个不同的客户端查看和编辑这些文档,而不是同时查看和编辑同一部分。关键是,我需要将一个部分或整个文档复制到另一个新文档中,以便另一个客户端可以对其进行编辑

为了复制文档,我在原始文档中逐个获取段落,并将其复制到新的可编辑文档中。到目前为止,我对文本没有任何问题(顺便说一句,多亏了stackoverflow),但我无法知道当前段落是文本还是图形,并复制该图形;实际上,图形被解释为空白段落

我已经看到了几个答案,包括,这有点帮助,但不符合我的需要,因为我需要知道图像在哪里,并将其以与原始文档相同的顺序放入新文档中

打开文档,在对其执行任何操作之前,我有以下代码来处理它:

XTextDocument xTextDocument = (XTextDocument)UnoRuntime.queryInterface( XTextDocument.class,xComp );
XText xText = xTextDocument.getText();//Get the text from the open document
XEnumerationAccess xEnumerationAccess = (XEnumerationAccess)UnoRuntime.queryInterface( XEnumerationAccess.class,xText );
XEnumeration xParagraphEnumeration = xEnumerationAccess.createEnumeration();//Get every paragraph in the document
try
{
    while ( xParagraphEnumeration.hasMoreElements() ) 
    {
        XTextContent xTextElement = (XTextContent)UnoRuntime.queryInterface( XTextContent.class,xParagraphEnumeration.nextElement() );
        aParagraphs.add(xTextElement);//Store the paragraphs
        
        XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface( XServiceInfo.class,xTextElement );
        System.out.println("Document(Document,Index - Supported Services");
        String [] aS = xServiceInfo.getSupportedServiceNames();//What are your supported services?
        for( int i=0 ; i<aS.length ; i++ )
            System.out.println("Document(Document,Index) - " + aS[i]);
        if( xServiceInfo.supportsService("com.sun.star.text.TextGraphicObject") )//Are you a graphic?
            System.out.println("Document(Document,Index) - This is a graphic.");
        else if( xServiceInfo.supportsService("com.sun.star.text.Paragraph") )//Are you text??
        {
            //b.copyParagraphFormat(j,xTextCursor);
            //xText.insertTextContent(xTextCursor, b.getParagraphs().get(j), false);
            //xText.insertString(xTextCursor, b.getParagraphs().get(j).getAnchor().getString(), false);
            System.out.println("Document(Document,Index) - This is text.");
        }
        else //Are you anything else?
            System.out.println("Document(Document,Index) - This isn't either graphic nor text??");
        
    }
}
XTextDocument XTextDocument=(XTextDocument)unruntime.queryInterface(XTextDocument.class,xComp);
XText=xTextDocument.getText()//从打开的文档中获取文本
XEnumerationAccess XEnumerationAccess=(XEnumerationAccess)UnoRuntime.queryInterface(XEnumerationAccess.class,xText);
XEnumeration xParagraphEnumeration=xEnumerationAccess.createEnumeration()//获取文档中的每个段落
尝试
{
while(xParagraphEnumeration.hasMoreElements())
{
XTextContent XtexElement=(XTextContent)UnoRuntime.queryInterface(XTextContent.class,xParagraphEnumeration.nextElement());
aParagraphs.add(xTextElement);//存储段落
XServiceInfo XServiceInfo=(XServiceInfo)unorauntime.queryInterface(XServiceInfo.class,xTextElement);
System.out.println(“文档(文档,索引支持的服务”);
String[]aS=xServiceInfo.getSupportedServiceNames();//您支持哪些服务?

对于(int i=0;我为什么不复制整个文档(另存为…),然后删除不需要的部分?!我需要通过编程创建新文档,并控制打开的文档和正在编辑的部分。