Simon A Wilper wrote:

> Hallo Mathias,
> 
>>> Das geht per API, allerdings leider nicht in Basic. Das model eines
>>> Dokuments unterstützt das Interface css.datatransfer.XTransferable, mit
>>> dem man sich eine Repräsentation des Dokuments in einigen
>>> Graphikformaten, u.a. PNG abholen kann.
>> 
>> Etwas genauer: ein Abbild der ersten Seite des Dokuments, also auch das,
>> was im Thumbnail zu sehen ist.
> 
> Danke fuer die Info.  Das hoert sich schonmal sehr gut an.  Ich werde
> das mal in den naechsten Tagen evaluieren.  Leider bin ich in UNO noch
> nicht so vorangeschritten wie man sich das gerne wuenscht.
> 
> Wenn es nicht zu viel Umstaende macht: Gibt es dafuer Beispiele in C++?
> Oder auch in Java?

Ich habe das hier mal schnell in C++ zusammengestellt. Leider musste ich
dabei feststellen, dass eine der verwendeten Methoden einen Bug hat. :-(
Statt eines Thumbnails (also der ersten Seite) wird immer der Ausschnitt
abgebildet, der im Dokument sichtbar ist. Der Bug müsste also erst noch
gefixt werden (ist allerdings ein sehr einfacher Fix).

Der Code kann mit dem SDK übersetzt werden, als makefile kann das aus
dem SimpleBootstrap-Beispiel genommen werden (ein paar Typen muss man
noch ergänzen).

Das fertige Programm erwartet zwei Parameter auf der Kommandozeile, die
komplette URL der zu ladenden Datei und die komplette URL des zu
erzeugenden PNG.

Ciao,
Mathias

-- 
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
Please don't reply to "[EMAIL PROTECTED]".
I use it for the OOo lists and only rarely read other mails sent to it.
#include <iostream>
#include <cppuhelper/bootstrap.hxx>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/io/XStream.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
#include <com/sun/star/embed/XVisualObject.hpp>
#include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/graphic/XGraphicProvider.hpp>

using namespace com::sun::star;

int SAL_CALL main( int argc, char **argv )
{
    if ( argc < 3 )
    {
        ::std::cerr << "Missing arguments!\n";
        return 1;
    }

    ::rtl::OUString sMyURL = ::rtl::OUString::createFromAscii( argv[1] );
    ::rtl::OUString sOutURL = ::rtl::OUString::createFromAscii( argv[2] );

    try
    {
        // get the remote office component context
        uno::Reference< uno::XComponentContext > xContext( ::cppu::bootstrap() 
);
        if ( !xContext.is() )
        {
            ::std::cerr << "no component context!\n";
            return 1;
        }

        // get the remote office service manager
        uno::Reference< lang::XMultiComponentFactory > xServiceManager(
            xContext->getServiceManager() );
        if ( !xServiceManager.is() )
        {
            ::std::cerr << "no service manager!\n";
            return 1;
        }

        // create Desktop object to load the document
        uno::Reference < frame::XComponentLoader > xComponentLoader(
            xServiceManager->createInstanceWithContext( ::rtl::OUString(
            RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop") ),
            xContext ), uno::UNO_QUERY_THROW );

        // load the document
        uno::Reference < embed::XVisualObject > xObj(
            xComponentLoader->loadComponentFromURL( sMyURL, ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM("_blank") ),
            0, uno::Sequence < beans::PropertyValue >() ), uno::UNO_QUERY_THROW 
);

        embed::VisualRepresentation aRep = 
xObj->getPreferredVisualRepresentation( embed::Aspects::MSOLE_THUMBNAIL );
        uno::Sequence < sal_Int8 > myBytes;
        aRep.Data >>= myBytes;

        // convert to png
                uno::Reference < io::XStream > xTempFileStream(
            xServiceManager->createInstanceWithContext( ::rtl::OUString(
            RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ),
            xContext ), uno::UNO_QUERY_THROW );

        xTempFileStream->getOutputStream()->writeBytes( myBytes );

        uno::Reference < graphic::XGraphicProvider > xGraphicProv(
            xServiceManager->createInstanceWithContext( ::rtl::OUString(
            RTL_CONSTASCII_USTRINGPARAM("com.sun.star.graphic.GraphicProvider") 
),
            xContext ), uno::UNO_QUERY_THROW );

        uno::Sequence < beans::PropertyValue > aProps(1);
        aProps[0].Name = ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM("InputStream") );
        aProps[0].Value <<= xTempFileStream->getInputStream();
        uno::Reference < graphic::XGraphic > xGraphic = 
xGraphicProv->queryGraphic( aProps );

        uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess(
            xServiceManager->createInstanceWithContext( ::rtl::OUString(
            RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ),
            xContext ), uno::UNO_QUERY_THROW );

        uno::Reference < io::XStream > xStream ( 
xSimpleFileAccess->openFileReadWrite( sOutURL ), uno::UNO_QUERY_THROW );

        aProps.realloc(2);
        aProps[0].Name = ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM("OutputStream") );
        aProps[0].Value <<= xStream->getOutputStream();
        aProps[1].Name = ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM("MimeType") );
        aProps[1].Value <<= ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM("image/png") );

        xGraphicProv->storeGraphic( xGraphic, aProps );

        xStream->getOutputStream()->closeOutput();
    }
    catch ( ::cppu::BootstrapException & e )
    {
        ::std::cerr << "caught BootstrapException: "
             << OUStringToOString( e.getMessage(), RTL_TEXTENCODING_ASCII_US 
).getStr()
             << '\n';
        return 1;
    }
    catch ( uno::Exception & e )
    {
        ::std::cerr << "caught UNO exception: "
             << ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US 
).getStr()
             << '\n';
        return 1;
    }

    return 0;
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Antwort per Email an