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

Free Support Forum - aspose.com

How horizontal line is detected in Aspose.words

Hi!

I have attached an image of a sample file for describing my problem. I want to process only last paragraphs “EFG” and “HIJ”. To do so I need to detect the occurrence of the horizontal line right before those paragraphs.

I have used DocumentVisitor and visited every paragrph using “public int visitParagraphStart(Paragraph p)”. I need to know only one thing.

  1. how can I detect the existance of the horizontal line in a paragraph p.

I need the solution as early as possible.
Thanks in advance.

Regards,
Asfak Mahamud

Hi
Thanks for your inquiry. Actually there is few ways to insert horizontal line into the document (border of paragraph, sequence of “_” characters, Line drawing object, etc). I don’t think that this way to determine place in document is correct. I think that you should use bookmark to achieve this.
Please attach your document.
Best regards.

Thanks for your reply. I’ve attached my sample file.

Asfak

Hi
You attached image instead document (you changed extension to “.doc”). Any way I would advice you to use bookmarks in this case.
Best regards.

Hi,

Thanks for your reply again.

Sorry, Yes it is true I attached the image in my first post and then when you told me to attach the doc file I attached it ( the doc file) in the first post again. So you could not see it in my previous reply. I should be sorry for this. I am trying with bookmarks.

[I’ve attached the doc file with this reply. If you wish you can see.]

Regards,
Asfak

Hi
Here is code that shows how you can use bookmark in your case.

// Open document
Document doc = new Document(@"Test005\in.doc");
// Get bookmark's parent paragraph
Paragraph firstPar = doc.Range.Bookmarks["myBookmark"].BookmarkStart.ParentNode as Paragraph;
// For example we can change alignment of paragraph
firstPar.ParagraphFormat.Alignment = ParagraphAlignment.Center;
// Get next paragraph
(firstPar.NextSibling as Paragraph).ParagraphFormat.Alignment = ParagraphAlignment.Right;
// Save result
doc.Save(@"Test005\out.doc");

Also I attached input and output documents.
[Document you attached is blank :-)]
Best regards.

Hi,

Thanks again.

I should be extemely sorry for the mistake. The snap in my first post was taken from an unsaved doc file. And the file when I attached at my post had not been saved. I am extremely sorry, again. I should also give you thanks for the file you made yourself.

I am coding in Java. You have written in vb or vba. Okay no problem. But as your code is saying you are editing the word doc. In my case I have no authority to modify the format of the document ( that is I have no authority to give a bookmark in the word file). Acutally there are hundreds of this type of documents in a directory. I am not able to send you the original file due to authority measures. So now my question is

  1. Is it possible to detect the horizontal line programmatically (without knowing where it could be) from a paragraph.

I thank you again. And must be sorry for my fault. I attached the document saved_sample.doc which is actually like yours in.doc

Regards,
Asfak

Hi
Thanks you for additional information. In your case horizontal line is bottom border of paragraph. You can try using the following code:

// Open document
Document doc = new Document("C:\\Temp\\in.doc");
// In your case horisontal line is bottom border of paragraph
// So we should loop through all paragraphs and seeach for paragraph with bottom border
Paragraph par = doc.getFirstSection().getBody().getFirstParagraph();
// Get collection of all paragraphs from the document
NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);
// Loop through all paragraphs
for (int i = 0; i < paragraphs.getCount(); i++)
{
    Paragraph currentPar = (Paragraph)paragraphs.get(i);
    // Check bottom border of current paragraph
    if (currentPar.getParagraphFormat().getBorders().get(BorderType.BOTTOM).getLineStyle() == LineStyle.SINGLE)
    {
        par = currentPar;
        // Break loop
        break;
    }
}
// Get content after horizontal line
Node currentNode = par.getNextSibling();
while (currentNode != null)
{
    System.out.println(currentNode.toTxt());
    currentNode = currentNode.getNextSibling();
}

Hope this helps.
Best regards.

Hi,
Thank You Very Much. I also think this will work.

Thanks again.
Regards,
Asfak