We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Copying content issue

Hi,

So here's the issue, I'm iterating thru a collection of paragraphs in a source document and when I locate certain verbage I note the starting Node. I then continue on searching for other verbage and note the ending Node. At this point I copy everything in between the two nodes to a destination document. Then I continue on searching the source document, and so on.

When I write the content found btwn the first Start / End node the destination looks fine, however performing this action again causes the second Start / End node to be placed almost on top of the first Start / End node.

Couple of things:

1. I read in my Source like this:

Document srcDoc = new Aspose.Words.Document(....

2. I create my destination like this:

Document dstDoc = srcDoc.Clone();

dstDoc.RemoveAllChildren();

dstDoc.EnsureMinimum();

dstDoc.FirstSection.Body.RemoveAllChildren();

3. Here's my importer and nodes to search:

NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.UseDestinationStyles);

NodeCollection MyNodes = srcDoc.GetChildNodes(NodeType.Paragraph, true);

4. I grab the content as outlined here: <A href="https://forum.aspose.com/t/70413</A></FONT></FONT></P> <P>I've even tried the following code to add some sort of buffer in btwn content inserts but it just gives lots of empty sections of large unwanted pages:</P><FONT size=2 face=Consolas><FONT size=2 face=Consolas> <P></FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Section</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> section = </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>new</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Section</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>(dstDoc);</P> <P>dstDoc.AppendChild(section);</P> <P></FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Body</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> body = </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>new</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Body</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>(dstDoc);</P> <P>section.AppendChild(body);</P> <P></FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Paragraph</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> p1 = </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>new</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Paragraph</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>(dstDoc);</P> <P>dstDoc.LastSection.Body.AppendChild(p1);</P> <P>body.AppendChild(p1);</P></FONT></FONT> <P><FONT size=2 face=Consolas><FONT size=2 face=Consolas></FONT></FONT> </P> <P>Anyone have some thoughts?</P> <P> </P> <P>Thanks - Dave</P> <P><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </P></FONT></FONT></FONT></FONT></FONT></FONT>

Hello

Thanks for your request. I think in this case you can try using the same approach as suggested here:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-extract-selected-content-between-nodes-in-a-document.html

Best regards,

Andrey,

Thanks for the reply. That article is a good example of getting the content between two nodes, repeatedly. I'm using it now. However the issue still remains, during the second attempt to write out a content chunk to the destination, it will place that content chuck just about ON TOP of the first content chunk that was written.

To help prevent this, in between the various writes of the content chunks I place this code below -

Which fixes the first problem BUT adds excessive spacing and pages.

Section section = new Section(dstDoc);

dstDoc.AppendChild(section);

Body body = new Body(dstDoc);

section.AppendChild(body);

//section.PageSetup.SectionStart = SectionStart.Continuous;

Paragraph p1 = new Paragraph(dstDoc);

dstDoc.LastSection.Body.AppendChild(p1);

body.AppendChild(p1);

Hi there,


Thanks for this additional information.

Could you please attach your source document as well as which nodes you are extracting? We will gladly take a closer look into this for you.

Thanks,