OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Resolved] ppt2png export size

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
elixir
General User
General User


Joined: 17 Mar 2006
Posts: 6

PostPosted: Tue Mar 21, 2006 8:26 am    Post subject: [Resolved] ppt2png export size Reply with quote

hi,

i developed a java application to export ppt.
It works fine, but i want slides to be export in 640x480.
I tried to set the drawpage size but it cuts the slide.
Do you have any idea ? Thanks.


Last edited by elixir on Wed Mar 22, 2006 2:16 am; edited 1 time in total
Back to top
View user's profile Send private message
hagen00
Power User
Power User


Joined: 15 Apr 2005
Posts: 65
Location: South Africa

PostPosted: Tue Mar 21, 2006 11:38 am    Post subject: Reply with quote

Code:
Dim aFilterData (3) As New com.sun.star.beans.PropertyValue

aFilterData(0).Name  = "PixelWidth"
aFilterData(0).Value = 640
aFilterData(1).Name  = "PixelHeight"
aFilterData(1).Value = 480
 
aFilterData(2).Name  = "LogicalWidth"; 
aFilterData(2).Value = 640
aFilterData(3).Name  = "LogicalHeight"
aFilterData(3).Value = 480
 


Then you just need to set the XExporter.filter - (xExporter = createUnoService "com.sun.star.drawing.GraphicExportFilter") to that filter.

Sorry, can't give you the whole code right now, but i hope this helps a bit.
[/list]
Back to top
View user's profile Send private message
elixir
General User
General User


Joined: 17 Mar 2006
Posts: 6

PostPosted: Tue Mar 21, 2006 11:59 am    Post subject: Reply with quote

thank you !

It's seems quite simple finally, but i didn't find it in the docs.
I try it tomorrow.
Back to top
View user's profile Send private message
elixir
General User
General User


Joined: 17 Mar 2006
Posts: 6

PostPosted: Wed Mar 22, 2006 2:15 am    Post subject: Reply with quote

ok it works fine. I post my code, it can be helpful :

Code:

                                                   PropertyValue[] loadProps = new PropertyValue[2];
                        loadProps[0] = new PropertyValue();
                loadProps[0].Name = "Hidden";
                loadProps[0].Value = new Boolean(true);
               
               // open the document
               XComponent component = xcomponentloader
                     .loadComponentFromURL(url,
                           "_blank", 0, loadProps);
               
               
               //System.out.println("Document Opened");
               
               // filter
               loadProps = new PropertyValue[3];
               
               // type of image
               loadProps[0] = new PropertyValue();
               loadProps[0].Name = "MediaType";
               loadProps[0].Value = "image/png";
               
               // Height and width
               PropertyValue[] filterDatas = new PropertyValue[4];
               for(int i = 0; i<4 ; i++){
                  filterDatas[i] = new PropertyValue();
               }
               filterDatas[0].Name = "PixelWidth";
               filterDatas[0].Value = new Integer(640);
               filterDatas[1].Name = "PixelHeight";
               filterDatas[1].Value = new Integer(480);
               filterDatas[2].Name = "LogicalWidth";
               filterDatas[2].Value = new Integer(640);
               filterDatas[3].Name = "LogicalHeight";
               filterDatas[3].Value = new Integer(480);
               
               XDrawPagesSupplier pagesSupplier = (XDrawPagesSupplier) UnoRuntime
                     .queryInterface(XDrawPagesSupplier.class, component);
               //System.out.println(pagesSupplier.toString());            
               XDrawPages pages = pagesSupplier.getDrawPages();
               int nbPages = pages.getCount();
                 
               
               for (int i = 0; i < nbPages; i++) {
                                 
                  XDrawPage page = (XDrawPage) UnoRuntime.queryInterface(
                        com.sun.star.drawing.XDrawPage.class, pages
                              .getByIndex(i));
                  
                  XNamed xPageName = (XNamed)UnoRuntime.queryInterface(XNamed.class,page);
                  xPageName.setName(xPageName.getName().replace(' ','_'));
                  xPageName.setName(removeAccents(xPageName.getName()));
                  Object GraphicExportFilter = xMultiComponentFactory
                        .createInstanceWithContext(
                              "com.sun.star.drawing.GraphicExportFilter",
                              xComponentContext);
                  XExporter xExporter = (XExporter) UnoRuntime
                        .queryInterface(XExporter.class,
                              GraphicExportFilter);

                  XComponent xComp = (XComponent) UnoRuntime
                        .queryInterface(XComponent.class, page);

                  xExporter.setSourceDocument(xComp);
                  loadProps[1] = new PropertyValue();
                  loadProps[1].Name = "URL";
                  loadProps[1].Value = remoteFolderFullPath+remoteFolder+"/"+(i+1) + "-"+xPageName.getName()+".png";
                  loadProps[2] = new PropertyValue();
                  loadProps[2].Name = "FilterData";
                  loadProps[2].Value = filterDatas;
                  
                  XFilter xFilter = (XFilter) UnoRuntime.queryInterface(XFilter.class, GraphicExportFilter);

                  xFilter.filter(loadProps);
                  System.out.println((i+1) + "-"+xPageName.getName()+".png");
                  //System.out.println("Page saved to url "+loadProps[1].Value);
                  
               }
Back to top
View user's profile Send private message
hagen00
Power User
Power User


Joined: 15 Apr 2005
Posts: 65
Location: South Africa

PostPosted: Wed Mar 22, 2006 4:45 am    Post subject: Reply with quote

Good on you elixir for marking the thread as resolved and posting the code! That's very good netiquette and all of us should do that!

Glad to be able to help.
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Wed Mar 22, 2006 10:15 am    Post subject: Reply with quote

Thank you to post your code. I think when you have working code to post it's beter to use "code snippet" forum.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Fri Jan 07, 2011 4:03 am    Post subject: Reply with quote

Due to this thread http://www.oooforum.org/forum/viewtopic.phtml?t=113679, I tried to get the above code working. With some small modifications it worked indeed. This is the complete Java code I came up with (heavily based on the above one):
Code:
import com.sun.star.beans.PropertyValue;
import com.sun.star.container.XNamed;
import com.sun.star.document.XExporter;
import com.sun.star.document.XFilter;
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XDrawPages;
import com.sun.star.drawing.XDrawPagesSupplier;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

import ooo.connector.BootstrapSocketConnector;

public class PresentationToImage {

    private static final String oooExeFolder = "/usr/lib/openoffice/program/";
    private static final String loadUrl="file:///tmp/example.odp";
    private static final String exportFilterUrl="file:///tmp/example";
    private static final int    exportWidth = 800;
    private static final int    exportHeight = 600;

    public static void main(String[] args) {

        try {
            XComponentContext xContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
            XMultiComponentFactory xMultiComponentFactory = xContext.getServiceManager();

            Object desktop = xMultiComponentFactory.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
            XComponentLoader xcomponentloader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop);
            XComponent document = xcomponentloader.loadComponentFromURL(loadUrl, "_blank", 0, new PropertyValue[0]);

            Object graphicExportFilter = xMultiComponentFactory.createInstanceWithContext("com.sun.star.drawing.GraphicExportFilter", xContext);

            extract(document, graphicExportFilter);
        }
        catch (java.lang.Exception e) {
            e.printStackTrace();
        }
        finally {
            System.exit(0);
        }
    }

    private static void extract(XComponent objectDocument, Object graphicExportFilter) throws com.sun.star.uno.Exception {

        // Export filter properties
        PropertyValue[] exportFilterProps = new PropertyValue[3];

        // Type of image
        exportFilterProps[0] = new PropertyValue();
        exportFilterProps[0].Name = "MediaType";
        exportFilterProps[0].Value = "image/png";

        // Height and width
        PropertyValue[] exportFilterData = new PropertyValue[4];
        exportFilterData[0] = new PropertyValue();
        exportFilterData[0].Name = "PixelWidth";
        exportFilterData[0].Value = new Integer(exportWidth);
        exportFilterData[1] = new PropertyValue();
        exportFilterData[1].Name = "PixelHeight";
        exportFilterData[1].Value = new Integer(exportHeight);
        exportFilterData[2] = new PropertyValue();
        exportFilterData[2].Name = "LogicalWidth";
        exportFilterData[2].Value = new Integer(exportWidth);
        exportFilterData[3] = new PropertyValue();
        exportFilterData[3].Name = "LogicalHeight";
        exportFilterData[3].Value = new Integer(exportHeight);

        exportFilterProps[1] = new PropertyValue();
        exportFilterProps[1].Name = "FilterData";
        exportFilterProps[1].Value = exportFilterData;

        // Get slides of document
        XDrawPagesSupplier pagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, objectDocument);
        XDrawPages pages = pagesSupplier.getDrawPages();

        for (int i = 0; i < pages.getCount(); i++) {
            // Get slide
            XDrawPage page = (XDrawPage) UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, pages.getByIndex(i));
            XNamed xPageName = (XNamed)UnoRuntime.queryInterface(XNamed.class,page);
            xPageName.setName(xPageName.getName().replace(' ','_'));
           
            XExporter xExporter = (XExporter) UnoRuntime.queryInterface(XExporter.class, graphicExportFilter);
            xExporter.setSourceDocument((XComponent) UnoRuntime.queryInterface(XComponent.class, page));

            exportFilterProps[2] = new PropertyValue();
            exportFilterProps[2].Name = "URL";
            exportFilterProps[2].Value = exportFilterUrl + "-" + xPageName.getName()+"("+(i+1)+").png";

            // Store slide with graphic export filter
            XFilter xFilter = (XFilter) UnoRuntime.queryInterface(XFilter.class, graphicExportFilter);
            xFilter.filter(exportFilterProps);
            System.out.println("Page saved to url: "+exportFilterProps[2].Value);
        }
    }
}

I've used OOo 3.2.0 on Ubuntu 10.04, NetBeans 6.8 and Java 1.6.0_16. From OO's jar files the code needs juh.jar, jurt.jar, ridl. jar and unoil.jar. For getting connected with OOo the code needs the bootstrapconnector.jar from http://user.services.openoffice.org/en/forum/viewtopic.php?f=44&t=2520.

The code works with ODP (OOo Impress) documents and should work with OOo Draw documents, too. Due to the usage of XDrawPagesSupplier (http://api.openoffice.org/docs/common/ref/com/sun/star/drawing/XDrawPagesSupplier.html) it can not work with OOo Writer or OOo Calc documents.
Back to top
View user's profile Send private message
gabelu
Newbie
Newbie


Joined: 02 Mar 2011
Posts: 2
Location: Bucharest

PostPosted: Wed Mar 02, 2011 1:24 am    Post subject: for any of document Reply with quote

How do I make this code work for any kind of document? not only for presentation ones.

I get a NullPointerException on
XDrawPages pages = pagesSupplier.getDrawPages();

Apparently the
XDrawPagesSupplier pagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, objectDocument);
doesn't work for a simple .odt file
Back to top
View user's profile Send private message Yahoo Messenger
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Thu Mar 03, 2011 9:54 am    Post subject: Re: for any of document Reply with quote

gabelu wrote:
How do I make this code work for any kind of document? not only for presentation ones.

I think, it is not possible to get this code working for any kind of document.
Back to top
View user's profile Send private message
shivakumar6g
General User
General User


Joined: 19 Jan 2011
Posts: 12

PostPosted: Thu Mar 01, 2012 5:15 am    Post subject: Reply with quote

hello, i created a image in ts.odg file.
Then i read the image from openoffice java and insert that in the word document.
When i do this i am seeing the image with some white portion which is not required to me.
Please reply me any body knows immediately. its urgent for me.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group