Free Support Forum - aspose.com

Options for removing blank lines from documents

Hi,

We'd really like to take advantage of these flags to remove blank lines in documents based on an if statement:

doc.MailMerge.CleanupOptions = Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveContainingFields | Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveEmptyParagraphs | Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedFields | Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedRegions;

These are working fabulously in one of our smaller applications. The problem is, in our largest application we have a lot of existing customers who have created documents over the last 5 years. There are about 10K documents out there already. Some have built documents expecting that a line with just a TableStart or TableEnd mergefield and a carraige return will leave a blank line in a document.

With a version of Aspose from last fall (and with your help), we added this code so that they wouldn't have to change there documents

public static Document AddTableSpace(Document doc)

{

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))

{ if (para.Range.Text.Contains("TableStart") && !para.Range.Text.Contains("TableEnd")) para.AppendChild(new Run(doc, " "));

else if (para.Range.Text.Contains("TableEnd") && !para.Range.Text.Contains("TableStart")) para.AppendChild(new Run(doc, " ")); }

        </p><p>return doc;
    </p><p>}</p><p> </p><p>However, this is now returning an error, 'cannot remove because there is no parent'.  </p><p>I've attached a test template that tries out both situtions.  Where it says 'line above TableEnd_Case' and line below TableEnd_Case', our users want there to be a blank line in the resulting document. However, in the witness loop at the bottom, we only want a line for any witness that has a DSN, no blank lines for other witnesses.</p><p>Is it possible for us to have it both ways?</p><p>Thanks</p><p>Karen</p>

Hi
Karen,


Thank you for inquiry.

First,
please note that DocumentExplorer is a very useful tool which easily
enables us to see the entire document structure. You can
find DocumentExplorer in the folder where you installed Aspose.Words
e.g. C:\Program Files (x86)\Aspose\Aspose.Words for
.NET\Demos\CSharp\DocumentExplorer\bin\DocumentExplorer.exe.<o:p></o:p>


>>cannot remove because there is no parent’.

Secondly, I’m afraid we can’t reproduce that issue on our side. Could you please create a simple console application which reproduces the issue on your side and attach it here? We will take a closer look into what’s happening and provide you with some further feedback.


Moreover, i think you can achieved blank lines after TableStart and TableEnd by following code snippet:


Document doc = new
Document(“c:/temp/test007/TestEmptyRegions.doc”);

DocumentBuilder builder = new DocumentBuilder(doc);

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))

{

if (para.Range.Text.Contains("TableStart") && !para.Range.Text.Contains("TableEnd"))

{

builder.MoveTo(para);

builder.InsertParagraph();

//para.AppendChild(new Run(doc, " "));

}

else if (para.Range.Text.Contains("TableEnd") && !para.Range.Text.Contains("TableStart"))

{

builder.MoveTo(para);

builder.InsertParagraph();

// para.AppendChild(new Run(doc, " "));

}

}


Hope this will help.


Hi Karen,


Thanks for your inquiry.

We are aware of this exception when using the MailMergeCleanupOptions.RemoveEmptyParagraphs settings with empty regions.

I have linked your request to the appropriate issue. We will inform you as soon as it’s resolved.

Thanks,

Hi Karen,


Just to let you know, this issue has been fixed and it will be available in the next version of Aspose.Words. This will be released at the end of the month (around the 30th).

Thanks,

The issues you have found earlier (filed as WORDSNET-5912) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Thanks, I've downloaded the new version and am testing it. I've found that for several documents, the attached is one example, I'm able to merge the document successfully with these Cleanup Options:

doc.MailMerge.CleanupOptions = Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveContainingFields | Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedFields | Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedRegions;

But when I add

Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveEmptyParagraphs |

to the list, I get an error, unexpected end of children nodes reached.

I am able to merge this document with no error using a version of Aspose from last September. Can you see what is wrong?

Thanks,

Karen

v

Hi Karen,


Thanks for the additional information.

Actually, the fix of the issue, i.e. associated with your request, was included in Aspose.Words v11.1.0. Unfortunately, in the previous post, you were given links to an older version (11.0.0) by mistake. Please download Aspose.Words v11.1.0 from the following link and let us know your findings then:
http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/entry364946.aspx

We apologize for your inconvenience.

Best Regards,

Thanks, that would have been an easy fix, but after adding the 2/29/12 version of Aspose.Words.dll to our site I am still getting this same error. The same document merges without error with the 9/30/11 version of Aspose.Words.dll (using the old RemoveEmptyParagraphs and RemoveEmptyRegions), and it also merges without error with the 2/29/12 if I use all the cleanup options except RemoveEmptyParagraphs as described in my post from yesterday.

Any ideas what could be wrong?

Karen

Hi Karen,


Thank you for inquiry. Unfortunately, it is difficult for us to say what is the problem. Could you please create a simple console application which reproduces the issue on your side and attach it here? We will take a closer look into what’s happening and provide you with some further feedback.

I just experienced this described behaviour myself. The version however is 11.9, .net 2.0

Generating the Document without MailMergeCleanupOptions.RemoveEmptyParagraphs works perfectly fine. the structure of the template used to display the data data is the following:
<

>
<>
<<b.somefield>>
<<b.someotherfield>>
a b c d e
f g h

<</inner table b>><</table a>>

i need to get rid of the spaces caused by the closing tags. i hope this is just a matter of the .net 2.0 component just beeing left behind and the behaviour is actually fixed because we only recently updated the component to deal with another issue caused by using tables in the header.

a swift reply upon this matter would be kindly appreciated.

Hi Patrick,


Thanks for your inquiry. I have answered, here in this thread, to a similar query of yours. I would suggest you please follow this thread for further proceedings from now on wards.

Best Regards,