Fill line with dots

We are using Aspose.PDF Generator to generate a form that will be printed and filled in by hand.

Is there a possibility to tell Aspose to fill the current line with dots like to following example?

Name: … (until TextWidth is reached)

If there is not, how can I figure out how much horizontal space some text uses in the current Text / Segment configuration? Something like mySegment.GetTextWidth()?

itp:
We are using Aspose.PDF Generator to generate a form that will be printed and filled in by hand.
Is there a possibility to tell Aspose to fill the current line with dots like to following example?

Name: ............ (until TextWidth is reached)

Hi,

Thanks for your interest in our products.

In case you need to display dots(.....) in form field, please try using TextField.FieldValue = "......."; which will add dots (....) as default value in Form Field.

itp:
If there is not, how can I figure out how much horizontal space some text uses in the current Text / Segment configuration? Something like mySegment.GetTextWidth()?


In case you need to specify the width/maximum number of characters that can be added in Form Field, please try using TextField.TextMaxLength = 5; where TextField is the name of Text form field. Please take a look over the following code snippet that I have used to generate a simple Text field with Pink as BackGround color and it can only support 5 characters to be added inside it. For your reference, I have also attached the resultant PDF that I have generated using Aspose.Pdf for .NET 6.0.0.

In case I have not properly understood your requirements or you have any further query, please feel free to contact. We apologize for your inconvenience.

[C#]

// create a PDF instance
Pdf pdf = new Pdf();
// create a section object and add it to Pdf object
Section sec = pdf.Sections.Add();

//Create a form field
FormField TextField = new FormField();
//Set the type of form field to Combo
TextField.FormFieldType = FormFieldType.Text;
//Set the field name
TextField.FieldName = "TextField";
// specify the backGround color for Text Field
TextField.BackgroundColor = System.Drawing.Color.Pink;
// specify the width of Text Field
TextField.FormWidth = 50;
// specify the Maximum number of characters that can be placed inside Text Field
TextField.TextMaxLength = 5;
// add the form field to paragraphs collection of section object
sec.Paragraphs.Add(TextField);
// save the resultant PDF
pdf.Save(@"d:/pdftest/FormField.pdf");

We are not using FormFields. The generated document is a report representing a form. The document is only printed and not distributed digitally.


My question was whether there is a command that fills the remainder of a line with dots. If a have a paragraph (Text) containing some text that does no take up the available text width, I need to fill that remaining empty space with dots.

I found the method “Aspose.Pdf.Generator.Pdf.GetStringWidth(…)” which should give me the width that a specified string uses. To get the remaining space, I’m still looking how the get the actual text width of the current paragraph.
I specified page width and margins for the Section and margins for the Text. Is there a property or method that calculates the remaining text width?

Hi,

Thanks for your patience and sorry for replying you late.

As far as I have understood form your requirement, you need to place some text paragraph inside PDF Section and if the text width is less than Right margin of Section, you need to place Dots (...) at that place. If so is the case, then please try using the following code snippet to accomplish your requirements.

[C#]

// Instantiate PDF object
Pdf pdf = new Pdf();
// create section object
Aspose.Pdf.Section sec = pdf.Sections.Add();
// create a sample string object
String sample_String = "Sample Hello World ";
// create text object using sample string
Aspose.Pdf.Text sample_Text = new Aspose.Pdf.Text(sample_String);
// add the Text paragraph to paragraphs collection of section object
sec.Paragraphs.Add(sample_Text);

// get the width of string object
float String_Width = pdf.GetStringWidth(sample_String, new Aspose.Pdf.TextInfo());
// calculate the amount of blank space if we remove String width, Left Margin and Right margin information from page width
float Remaining_Space = sec.PageInfo.PageWidth - sec.PageInfo.Margin.Left - sec.PageInfo.Margin.Right - pdf.GetStringWidth(sample_String, new Aspose.Pdf.TextInfo());
// counter for adding Dotted text segments
for (int counter = 0; counter <= Remaining_Space/4; counter++)
{
// create a new segment with .
Segment Dotted_Segment = new Segment(".");
// add the segment to segments collection of text object
sample_Text.Segments.Add(Dotted_Segment);
}

// save the resultant PDF
pdf.Save(@"d:/pdftest/StringWidthTest.pdf");

For your reference, I have also attached the resultant PDF that I have generated. In case I have not properly understood your requirement, please share some more details and if possible, please share some sample document/image that can help us in understanding this requirement. We apologize for your inconvenience.