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

Free Support Forum - aspose.com

Horizontal Line

Hi - I need to insert a horizontal line in a MS Word document using Java and Apose.Words. I cannot seem to find a good way to make that happen. Any suggestions?

Thanks

–John Nelson

To add a little to my problem. I am creating a document from a mail merge template and in that template I would like to have a horizintal line if certain data is present.

I use:
getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS);

to remove unused tags.

I would like to be able to populate a tag with a horizontal line - that way if the data does not exist then the line will not display in my final generated document.

does that make sense?


Hi John,


Thanks for your inquiry.

The MailMerge class provides two events that could be very useful in expanding mail merge capabilities. The MailMerge.FieldMergingCallback property accepts a class which implements the methods IFieldMergingCallback.FieldMerging and IFieldMergingCallback.ImageFieldMerging. These can be used to implement custom control over the mail merge process. Please refer to the following articles:

http://www.aspose.com/docs/display/wordsnet/How+to++Apply+Custom+Formatting+during+Mail+Merge
http://www.aspose.com/docs/display/wordsnet/How+to++Insert+Check+Boxes+during+Mail+Merge

The following code shows how to insert a line shape in document using DocumentBuilder:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("before line");

Shape lineShape = new Shape(doc, ShapeType.Line);

lineShape.Width = 72 * 2; // 2 inches

builder.InsertNode(lineShape);

builder.Writeln("after line");

doc.Save(MyDir + @“out.docx”);


I hope, this helps.

Best regards,

Thanks for the information. The red flag for me is this statement…

"This handler is called for every mail merge field found in the document,
for every record found in the data source."

I have around 120 merge fields in my original template. Is that callback
method really called for every one of my fields? I will only have one or two fields that
will represent the horizontal line.



Quick question - I am not that familiar with .NET - do you have Java versions of these examples?

ok - so I have the callback class setup in Java (I think) but the FieldMergingArgs object does not contain a ‘Document’ element.

Here is a code snippet and the very last line will not compile.

I am using aspose-words-14.11.0-jdk16.jar

private class HandleMergeImageFieldFromBlob implements IFieldMergingCallback {

private DocumentBuilder mBuilder;

public void fieldMerging(FieldMergingArgs e) throws Exception {
// Do nothing.

if (mBuilder == null)
mBuilder = new DocumentBuilder(e.Document);
}

}

Hi John,

Thanks for your inquiry. Yes, it will be called for every merge field in document. Secondly, please refer to the following Java articles:

How to Apply Custom Formatting during Mail Merge
How to Insert Check Boxes during Mail Merge

Best regards,