Free Support Forum - aspose.com

Copy Slide Notes with Slides

Hi,

I am using cloneslides to import slides from one presentation to another. Is it possible to import the slide notes as well as the slide content?

Regards

Alan

Dear Alan,

CloneSlide method clones the full slide along with its all contents. For slide’s notes, you will have to write the code to import notes of cloned slide.

For it, you can use Slide.Notes property and Slide.Notes.Paragraphs

Hi,

Do you have an example of some code to do this? Any help would be very appreciated.

Regards

Alan

Dear Alan,

The code below clone slides as well as its notes. The method takes three parameters as input, one is source presentation, the slide number to be cloned and destination presentation.

It then not only clones the source slide from source presentation into the destination presentation but also copies its notes.

I have attached the source presentation, code and resulting output presentation.

Imports System

Imports System.IO

Imports System.Collections.Generic

Imports System.Collections

Imports System.Text

Imports System.Drawing

Imports System.Drawing.Imaging

Imports Aspose.Slides

Module PPTPractice

Sub Main()

Dim srcPres As Presentation

srcPres = New Presentation("c:\srcPres.ppt")

Dim dstPres As Presentation

dstPres = New Presentation()

CloneSlideWithNotes(srcPres, 1, dstPres)

dstPres.Write("c:\dstPres.ppt")

End Sub

Sub CloneSlideWithNotes(ByVal srcPres As Presentation, ByVal srcSlidePosition As Integer, _

ByVal dstPres As Presentation)

Dim srcSld As Slide

srcSld = srcPres.GetSlideByPosition(srcSlidePosition)

If srcSld Is Nothing Then

Exit Sub

End If

Dim dstSldPosition As Integer

dstSldPosition = dstPres.Slides.LastSlidePosition + 1

'Clone slide now, we have all the necessary parameters

Dim dstSld As Slide

dstSld = srcPres.CloneSlide(srcSld, dstSldPosition, dstPres, New SortedList)

'Now below is the code to copy srcSld notes to dstSld notes

'Add notes to dstSld and clear all paragraphs

dstSld.AddNotes()

dstSld.Notes.Paragraphs.Clear()

'Finally add all the pargraphs in notes of sldSrc into the notes of dstSld

For Each srcPara As Paragraph In srcSld.Notes.Paragraphs

'Create the replica of srcPara

Dim dstPara As Paragraph

dstPara = New Paragraph(srcPara)

'Add this Replica to dstSld.Notes.Paragraphs

dstSld.Notes.Paragraphs.Add(dstPara)

Next

End Sub

End Module

Hi Shakeel

That works perfectly. Thank you for you help once again

Regards

Alan

Below is the same code in C#

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

C# Code

----------------------------------------------------------------------------------------------------------------------

static void <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />Main(string[] args)

{

Presentation srcPres = new Presentation(@"C\srcPres.ppt");

Presentation dstPres = new Presentation();

CloneSlideWithNotes(srcPres, 1, dstPres);

dstPres.Write(@"c:\dstPres.ppt");

Console.WriteLine("\nPress any key to continue...");

Console.ReadKey();

}

static void CloneSlideWithNotes(Presentation srcPres, int srcSlidePosition, Presentation dstPres)

{

Slide srcSld;

srcSld = srcPres.GetSlideByPosition(srcSlidePosition);

if (srcSld == null)

return;

int dstSldPosition;

dstSldPosition = dstPres.Slides.LastSlidePosition + 1;

//Clone slide now, we have all the necessary parameters

Slide dstSld;

dstSld = srcPres.CloneSlide(srcSld, dstSldPosition, dstPres, new SortedList());

//Now below is the code to copy srcSld notes to dstSld notes

//Add notes to dstSld and clear all paragraphs

dstSld.AddNotes();

dstSld.Notes.Paragraphs.Clear();

//Finally add all the pargraphs in notes of sldSrc into the notes of dstSld

foreach (Paragraph srcPara in srcSld.Notes.Paragraphs)

{

//Create the replica of srcPara

Paragraph dstPara = new Paragraph(srcPara);

//Add this Replica to dstSld.Notes.Paragraphs

dstSld.Notes.Paragraphs.Add(dstPara);

}

}

Below is the same code in JAVA. It has the same output, you can see the output presentation and source presentation from the post above, they are attached there.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

JAVA CODE

----------------------------------------------------------------------------------------------------------------------

public static void main(String[] args) {

try

{

Presentation srcPres = new Presentation(new FileInputStream("c:\\srcPres.ppt"));

Presentation dstPres = new Presentation();

CloneSlideWithNotes(srcPres, 1, dstPres);

dstPres.write(new FileOutputStream("c:\\dstPres.ppt"));

}

catch(Exception ex)

{

System.out.println(ex.toString());

}

}

public static void CloneSlideWithNotes(Presentation srcPres, int srcSlidePosition,

Presentation dstPres) throws Exception

{

Slide srcSld;

srcSld = srcPres.getSlideByPosition(srcSlidePosition);

if (srcSld == null)

return;

int dstSldPosition;

dstSldPosition = dstPres.getSlides().getLastSlidePosition() + 1;

//Clone slide now, we have all the necessary parameters

Slide dstSld;

dstSld = srcPres.cloneSlide(srcSld, dstSldPosition, dstPres, new TreeMap());

//Now below is the code to copy srcSld notes to dstSld notes

//Check if the source slide has notes

if(srcSld.getNotes()==null)

return;

//Add notes to dstSld and clear all paragraphs

dstSld.addNotes();

Paragraphs dstNotesParas=dstSld.getNotes().getParagraphs();

dstNotesParas.clear();

//Finally add all the pargraphs in notes of sldSrc into the notes of dstSld

Paragraphs srcNotesParas=srcSld.getNotes().getParagraphs();

int parasCount=srcNotesParas.size();

for(int i=0; i<parasCount; i++)

{

Paragraph srcPara=srcNotesParas.get(i);

//Create the replica of srcPara

Paragraph dstPara=new Paragraph(srcPara);

//Add this Replica to dstSld.Notes.Paragraphs

dstNotesParas.add(dstPara);

}//for

}