XSLF copy slides

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

XSLF copy slides

Louis.Masters
Any simple way to copy slides from one presentation to another?  I'll even
take tips for a not-so-easy way.

I saw a post about removing the slides that you don't want, but this
method will be complex for me in that I also have to reorder.

Thanks,
Lou
Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

Yegor Kozlov-4
Below is a simple app that merges multiple .pptx presentations together:

public class MergePresentations {

    public static void main(String args[]) throws Exception {
        XMLSlideShow ppt = new XMLSlideShow();

        for(String arg : args){
            FileInputStream is = new FileInputStream(arg);
            XMLSlideShow src = new XMLSlideShow(is);
            is.close();

            for(XSLFSlide srcSlide : src.getSlides()){
                ppt.createSlide().importContent(srcSlide);
            }
        }

        FileOutputStream out = new FileOutputStream("merged.pptx");
        ppt.write(out);
        out.close();
    }

}

I'm going to add this code in the XSLF cookbook.

Yegor

On Mon, Jan 16, 2012 at 4:23 AM,  <[hidden email]> wrote:
> Any simple way to copy slides from one presentation to another?  I'll even
> take tips for a not-so-easy way.
>
> I saw a post about removing the slides that you don't want, but this
> method will be complex for me in that I also have to reorder.
>
> Thanks,
> Lou

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

Louis.Masters
Yegor:

Awesome.  Thanks.

-Lou

Yegor Kozlov <[hidden email]> wrote on 01/16/2012 01:45:39 AM:

> Yegor Kozlov <[hidden email]>
> 01/16/2012 01:47 AM
>
> Please respond to
> "POI Users List" <[hidden email]>
>
> To
>
> POI Users List <[hidden email]>
>
> cc
>
> Subject
>
> Re: XSLF copy slides
>
> Below is a simple app that merges multiple .pptx presentations together:
>
> public class MergePresentations {
>
>     public static void main(String args[]) throws Exception {
>         XMLSlideShow ppt = new XMLSlideShow();
>
>         for(String arg : args){
>             FileInputStream is = new FileInputStream(arg);
>             XMLSlideShow src = new XMLSlideShow(is);
>             is.close();
>
>             for(XSLFSlide srcSlide : src.getSlides()){
>                 ppt.createSlide().importContent(srcSlide);
>             }
>         }
>
>         FileOutputStream out = new FileOutputStream("merged.pptx");
>         ppt.write(out);
>         out.close();
>     }
>
> }
>
> I'm going to add this code in the XSLF cookbook.
>
> Yegor
>
> On Mon, Jan 16, 2012 at 4:23 AM,  <[hidden email]> wrote:
> > Any simple way to copy slides from one presentation to another?  I'll
even

> > take tips for a not-so-easy way.
> >
> > I saw a post about removing the slides that you don't want, but this
> > method will be complex for me in that I also have to reorder.
> >
> > Thanks,
> > Lou
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

rohit_sh1
In reply to this post by Yegor Kozlov-4
Hi Yegor,

importContent seems to be missing slide background information while merging.

I am trying a workaround as well i.e. remove all the shapes from source slide, save the slide as png and then apply the PNG file as background.

This method works for HSLF but not with XSLF.

Please help.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

Yegor Kozlov-4
A similar question was answered last week:

A slide contents consists of two components:
1. shapes that actually present on the slide
2. shapes defined on the slide master. For example, if slide master
has a picture background then all slides that follow it will show this
picture even if the picture is not physically defined on the slide.

Slide#importContent imports (1), that is, it imports only the actual
slide contents.
In theory this approach can be used for master sheets too, but it
wasn't tested. Try to get slide's layout and slide's master and call
importContent on them. What is the result?

Yegor

On Tue, Jun 12, 2012 at 12:54 PM, rohit_sh1 <[hidden email]> wrote:

> Hi Yegor,
>
> importContent seems to be missing slide background information while
> merging.
>
> I am trying a workaround as well i.e. remove all the shapes from source
> slide, save the slide as png and then apply the PNG file as background.
>
> This method works for HSLF but not with XSLF.
>
> Please help.
>
> Thanks
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/XSLF-copy-slides-tp5147500p5710130.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

Louis.Masters
I am furthering my investigation into this using your suggestion.  I do
have a workaround that is pretty simple:  reverse the creation so that
instead of adding slides to a new presentation, copy the old presentation
and remove the slides you do not want.  This seems to keep the templates
in place.

When I get a chance I will check into Yegor's suggestion and report back.

-Lou


Yegor Kozlov <[hidden email]> wrote on 2012-06-13 02:41:02 AM:

> Yegor Kozlov <[hidden email]>
> 2012-06-13 02:42 AM
>
> Please respond to
> "POI Users List" <[hidden email]>
>
> To
>
> POI Users List <[hidden email]>,
>
> cc
>
> Subject
>
> Re: XSLF copy slides
>
> A similar question was answered last week:
>
> A slide contents consists of two components:
> 1. shapes that actually present on the slide
> 2. shapes defined on the slide master. For example, if slide master
> has a picture background then all slides that follow it will show this
> picture even if the picture is not physically defined on the slide.
>
> Slide#importContent imports (1), that is, it imports only the actual
> slide contents.
> In theory this approach can be used for master sheets too, but it
> wasn't tested. Try to get slide's layout and slide's master and call
> importContent on them. What is the result?
>
> Yegor
>
> On Tue, Jun 12, 2012 at 12:54 PM, rohit_sh1 <[hidden email]> wrote:
> > Hi Yegor,
> >
> > importContent seems to be missing slide background information while
> > merging.
> >
> > I am trying a workaround as well i.e. remove all the shapes from
source
> > slide, save the slide as png and then apply the PNG file as
background.

> >
> > This method works for HSLF but not with XSLF.
> >
> > Please help.
> >
> > Thanks
> >
> > --
> > View this message in context: http://apache-poi.
> 1045710.n5.nabble.com/XSLF-copy-slides-tp5147500p5710130.html
> > Sent from the POI - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

rohit_sh1
In reply to this post by Yegor Kozlov-4
Hi Yegor,

I am getting org.apache.xmlbeans.impl.values.XmlValueDisconnectedException on the second slide of my .pptx file while trying to importContent of slideLayout.

PLease help. I will keep searching to see anyone else had similar issues.
Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

Yegor Kozlov-4
As I said earlier, importContent was designed to import slides, not
masters and layouts.
XmlValueDisconnectedException  when importing a layout is not a bug,
rather a limitation of the current implementation.

It might be a fundamental problem or a simple fix  - it is hard to
tell without a sample code and stack trace. Can you post both?

Yegor

On Wed, Jun 13, 2012 at 6:08 PM, rohit_sh1 <[hidden email]> wrote:

> Hi Yegor,
>
> I am getting org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
> on the second slide of my .pptx file while trying to importContent of
> slideLayout.
>
> PLease help. I will keep searching to see anyone else had similar issues.
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/XSLF-copy-slides-tp5147500p5710155.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

rohit_sh1
Here's the stack trace
org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
        at org.apache.xmlbeans.impl.values.XmlObjectBase.check_orphaned(XmlObjectBase.java:1213)
        at org.apache.xmlbeans.impl.values.XmlObjectBase.newCursor(XmlObjectBase.java:243)
        at org.apache.xmlbeans.impl.values.XmlObjectBase.selectPath(XmlObjectBase.java:424)
        at org.apache.xmlbeans.impl.values.XmlObjectBase.selectPath(XmlObjectBase.java:415)
        at org.apache.poi.xslf.usermodel.XSLFSimpleShape.getSpPr(XSLFSimpleShape.java:116)
        at org.apache.poi.xslf.usermodel.RenderableShape$4.fetch(RenderableShape.java:351)
        at org.apache.poi.xslf.usermodel.XSLFSimpleShape.fetchShapeProperty(XSLFSimpleShape.java:574)
        at org.apache.poi.xslf.usermodel.RenderableShape.getFillPaint(RenderableShape.java:364)
        at org.apache.poi.xslf.usermodel.XSLFSimpleShape.getFillColor(XSLFSimpleShape.java:490)
        at org.apache.poi.xslf.usermodel.XSLFSimpleShape.copy(XSLFSimpleShape.java:649)
        at org.apache.poi.xslf.usermodel.XSLFTextShape.copy(XSLFTextShape.java:561)
        at org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:310)
        at pptxMerger.doMerge(pptxMerger.java:92)
        at mergePowerPoint.main(mergePowerPoint.java:42)


and sample code:for(XSLFSlide srcSlide : src.getSlides()){        
                       
                        XSLFSlide newSlide =  ppt.createSlide();
                                   
                            /*      *       */            
                        newSlide.setFollowMasterGraphics(false);
               
                //Apply the background
                        XSLFSlideLayout src_sl = srcSlide.getSlideLayout();
                        XSLFSlideMaster src_sm = srcSlide.getSlideMaster();
                           
                        XSLFSlideLayout new_sl = newSlide.getSlideLayout();
                        XSLFSlideMaster new_sm = newSlide.getSlideMaster();
                               
                        new_sl.importContent(src_sl);
                        new_sm.importContent(src_sm);
                        /*} catch (org.apache.xmlbeans.impl.values.XmlValueDisconnectedException xmlE){
                        continue;
                        }*/
                       
                            /*             *              */
                           
                           
                        newSlide.importContent(srcSlide);            
                       
Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

rohit_sh1
In reply to this post by Yegor Kozlov-4
Hi Yegor,

I was wondering if you had any chance to look at my code and Stack trace. ANy assistance you can provide will be extremely helpful and appreciated.

Rohit
Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

Yegor Kozlov-4
Here is the code that worked for me:

            for(XSLFSlide srcSlide : src.getSlides()){
                XSLFSlide newSlide = ppt.createSlide();


                XSLFSlideLayout src_sl = srcSlide.getSlideLayout();
                XSLFSlideMaster src_sm = srcSlide.getSlideMaster();

                XSLFSlideLayout new_sl = newSlide.getSlideLayout();
                XSLFSlideMaster new_sm = newSlide.getSlideMaster();

                // copy source layout to the new layout
                new_sl.importContent(src_sl);
                // copy source master to the new master
                new_sm.importContent(src_sm);


                newSlide.importContent(srcSlide);
            }


Note that you should import layout into layout and master into master,
not master to slide as in you code snippet.

Yegor

On Fri, Jun 15, 2012 at 12:25 AM, rohit_sh1 <[hidden email]> wrote:

> Hi Yegor,
>
> I was wondering if you had any chance to look at my code and Stack trace.
> ANy assistance you can provide will be extremely helpful and appreciated.
>
> Rohit
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/XSLF-copy-slides-tp5147500p5710195.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

rohit_sh1
Thanks Yegor,

That is actually what I am doing as well. But this works only if there is one slide in the .pptx file.

When there is more than 1 slide, the program throws the org.apache.xmlbeans.impl.values.XmlValueDisconnectedException

Did your test include multiple slides?

rohit


From: Yegor Kozlov-4 [via Apache POI] <[hidden email]>
To: rohit_sh1 <[hidden email]>
Sent: Friday, June 15, 2012 12:45:51 AM
Subject: Re: XSLF copy slides

Here is the code that worked for me:

            for(XSLFSlide srcSlide : src.getSlides()){
                XSLFSlide newSlide = ppt.createSlide();


                XSLFSlideLayout src_sl = srcSlide.getSlideLayout();
                XSLFSlideMaster src_sm = srcSlide.getSlideMaster();

                XSLFSlideLayout new_sl = newSlide.getSlideLayout();
                XSLFSlideMaster new_sm = newSlide.getSlideMaster();

                // copy source layout to the new layout
                new_sl.importContent(src_sl);
                // copy source master to the new master
                new_sm.importContent(src_sm);


                newSlide.importContent(srcSlide);
            }


Note that you should import layout into layout and master into master,
not master to slide as in you code snippet.

Yegor

On Fri, Jun 15, 2012 at 12:25 AM, rohit_sh1 <[hidden email]> wrote:

> Hi Yegor,
>
> I was wondering if you had any chance to look at my code and Stack trace.
> ANy assistance you can provide will be extremely helpful and appreciated.
>
> Rohit
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/XSLF-copy-slides-tp5147500p5710195.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]




If you reply to this email, your message will be added to the discussion below:
http://apache-poi.1045710.n5.nabble.com/XSLF-copy-slides-tp5147500p5710203.html
To unsubscribe from XSLF copy slides, click here.
NAML


Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

Govardhan
This post was updated on .
HI Yegor,

  I am able to copy the slides from src ppt to user ppt, i didn't apply src master slide to user slide.
 Still unable to get the user font styles and placeHolder sizes.

Thanks,
GOvi
Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

paoim101084
In reply to this post by rohit_sh1
Here is what I did:
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;

public class MergeDemo {

        public static void main(String[] args) throws Exception {
                try (FileOutputStream out = new
FileOutputStream("output/MergeMultiplePresentations.pptx")) {
                        XMLSlideShow ppt = new XMLSlideShow();
                        String[] inputs = { "input/default_one.pptx", "input/default_two.pptx",
"input/title_two_columns.pptx" };
                        for (String arg : inputs) {
                                FileInputStream is = new FileInputStream(arg);
                                XMLSlideShow src = new XMLSlideShow(is);
                                is.close();

                                for (XSLFSlide srcSlide : src.getSlides()) {
                                        XSLFSlide newSlide = ppt.createSlide();
                                        copySlideContent(srcSlide, newSlide);
                                        newSlide.importContent(srcSlide);
                                }
                                src.close();
                        }

                        ppt.write(out);
                        ppt.close();
                }
        }
       
        private static void copySlideContent(final XSLFSlide slideNeedToMerge,
final XSLFSlide newSlide) {
                XSLFSlideLayout newSlideLayout = newSlide.getSlideLayout();
                XSLFSlideMaster newSlideMaster = newSlide.getSlideMaster();

                XSLFSlideLayout mergeSlideLayout = slideNeedToMerge.getSlideLayout();
                XSLFSlideMaster mergeSlideMaster = slideNeedToMerge.getSlideMaster();

                try {
                        // copy source layout to the new layout
                        newSlideLayout.importContent(mergeSlideLayout);
                        // copy source master to the new master
                        newSlideMaster.importContent(mergeSlideMaster);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
}

But I always got error:
java.lang.ClassCastException: org.apache.poi.ooxml.POIXMLDocumentPart cannot
be cast to org.apache.poi.xslf.usermodel.XSLFPictureData
        at org.apache.poi.xslf.usermodel.XSLFSheet.importBlip(XSLFSheet.java:651)
        at
org.apache.poi.xslf.usermodel.XSLFPictureShape.copy(XSLFPictureShape.java:223)
        at
org.apache.poi.xslf.usermodel.XSLFSheet.wipeAndReinitialize(XSLFSheet.java:452)
        at
org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:431)


The slide is overlap with each others.

Any help?




--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

kiwiwings
Although you excavate a 3+ year thread, I assume you've tested with a current POI 4.0.x version:

If not -> please try with POI 4.0.1

if yes -> open a bugzilla issue and add your files, because testing with a few arbitrary files and your code was successful.

Andi


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLF copy slides

paoim101084
Well, I try with 4.0.1, I still got error:
java.lang.ClassCastException: org.apache.poi.ooxml.POIXMLDocumentPart cannot
be cast to org.apache.poi.xslf.usermodel.XSLFPictureData
        at org.apache.poi.xslf.usermodel.XSLFSheet.importBlip(XSLFSheet.java:651)
        at
org.apache.poi.xslf.usermodel.XSLFPictureShape.copy(XSLFPictureShape.java:231)
        at
org.apache.poi.xslf.usermodel.XSLFSheet.wipeAndReinitialize(XSLFSheet.java:452)
        at
org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:431)
        at com.mckesson.MergeDemo.copySlideContent(MergeDemo.java:46)
        at com.mckesson.MergeDemo.main(MergeDemo.java:24)
java.lang.ClassCastException: org.apache.poi.ooxml.POIXMLDocumentPart cannot
be cast to org.apache.poi.xslf.usermodel.XSLFPictureData
        at org.apache.poi.xslf.usermodel.XSLFSheet.importBlip(XSLFSheet.java:651)
        at
org.apache.poi.xslf.usermodel.XSLFPictureShape.copy(XSLFPictureShape.java:231)
        at
org.apache.poi.xslf.usermodel.XSLFSheet.wipeAndReinitialize(XSLFSheet.java:452)
        at
org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:431)
        at com.mckesson.MergeDemo.copySlideContent(MergeDemo.java:46)
        at com.mckesson.MergeDemo.main(MergeDemo.java:24)

The result is overlap with each other.

Could you help to provide me the bugzilla? I will open a bugzilla issue.



--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]