Complete a paragraph with dashes


#1

Hi
I am trying to create a doc with several paragraphs and at the of each paragraph I want to complete the line with dashes if there’s a space like the following example:
This is paragraph this is paragraph
This is paragraph this is paragraph this
Is paragraph------------------------------------------


#2

@Tato_tia,

Please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Your expected document showing the desired output. You can create expected document by using MS Word.

As soon as you get these pieces of information ready, we will start investigation into your scenario and provide you code to achieve the same by using Aspose.Words. Thanks for your cooperation.


#3

Hi , thank you for your response
i created a program that tells the user to fill some forms and then the program will generates a word based on the filled informations and arrange them to pragraphs , but some paragraphs have an empty space at the last line , and because the documents have sensitive data , each empty space should filled so no one can add external data or change some infos , that’s why the empty space at the last line of each paragraph should be filled with dashes
i hope things are clear
thank again
res.zip (15.3 KB)


#4

@Tato_tia,

Please tell if the following solution is acceptable for you?

Document document = new Document("E:\\Temp\\res\\INPUT.docx");
DocumentBuilder builder = new DocumentBuilder(document);

LayoutCollector collector = new LayoutCollector(document);
LayoutEnumerator enumerator = new LayoutEnumerator(document);

foreach (Paragraph paragraph in document.FirstSection.Body.GetChildNodes(NodeType.Paragraph, true))
{
    if (!string.IsNullOrEmpty(paragraph.ToString(SaveFormat.Text).Trim()) &&
        paragraph.ParagraphFormat.Alignment == ParagraphAlignment.Justify)
    {
        PageSetup ps = paragraph.ParentSection.PageSetup;

        enumerator.Current = collector.GetEntity(paragraph);

        double pageBody = ps.PageWidth - ps.RightMargin;
        AddLine(paragraph,
            enumerator.Rectangle.Bottom - ((enumerator.Rectangle.Bottom - enumerator.Rectangle.Top) / 2),
            enumerator.Rectangle.Left,
            pageBody - enumerator.Rectangle.Left);
    }
}

document.UpdatePageLayout();
document.Save("E:\\Temp\\res\\19.8.docx");

public static void AddLine(Paragraph para, double top, double left, double width)
{
    DocumentBuilder builder = new DocumentBuilder((Document)para.Document);
    builder.MoveTo(para);

    Shape line = new Shape((Document)para.Document, ShapeType.Line);
    line.StrokeColor = Color.Black;
    line.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
    line.RelativeVerticalPosition = RelativeVerticalPosition.Page;
    line.WrapType = WrapType.None;

    builder.InsertNode(line);

    line.Width = width;
    line.Left = left;
    line.Top = top;
}

#5

amazing
finally got a solution , but ther still a little probleme with paragraphs that have orientation right to left


#6

@Tato_tia,

Please ZIP and attach the following resources here for testing:

  • Your simplified input Word document containing paragraphs with orientation from right to left
  • Your expected document showing the desired output. You can create expected document by using MS Word.

As soon as you get these pieces of information ready, we will start further investigation into your scenario and provide you code to achieve the same by using Aspose.Words. Thanks for your cooperation.


#7

Hi thank you for response
res.zip (15.2 KB)


#8

@Tato_tia,

Please try specifying the following values in AddLine method:

AddLine(paragraph,
    enumerator.Rectangle.Bottom - ((enumerator.Rectangle.Bottom - enumerator.Rectangle.Top) / 2),
    ps.LeftMargin,
    enumerator.Rectangle.Left - ps.LeftMargin);

#9

hi again
the code works fine but there is a little issue (please be patient with me) which is : some added lines have lot of space between them and the text i will give the output to see it .
please look at the text line before the two last lines.
thanks
have a good daytemp3.zip (15.7 KB)


#10

@Tato_tia,

We have logged your problem in our issue tracking system. Your ticket number is WORDSNET-19105. We will further look into the details of this problem and will keep you updated on the status of the linked issue. We apologize for your inconvenience.