Adding text with leading spaces to TEXT object

I seem unable to add text which has leading spaces to a text object. I have a need to create a paragraph/section that has 8 blank lines at the beginning. If I put a single character on each line (along with carriage return line feed) it works, if I add only the carriage return line feed it seems to get stripped off. Here is a code snippet in VB.net:

Dim loPDFDoc_ As New Pdf
Dim loPDFSection_ As Section
Dim loPDFText_ As Text
Dim loPDFSegment_ As Segment

Dim lsPage_ As String = String.Empty

'this is the shortened version of what I'm trying to do. In practice I'm creating 70+ lines of text with leading/trailing and internal blank lines. While the spaces are irrelevant I need the blank/empty lines.
lsPage_ = " " & vbcrlf & " " & vbcrlf & "this begins the text I want printed"

loPDFText_ = New Text
With loPDFText_
.TextInfo.Alignment = AlignmentType.Left
.TextInfo.FontName = FontName_
.TextInfo.FontSize = FontSize_
.IsSpaced = True
End With

loPDFSegment_ = loPDFText_.Segments.Add(lsPage_)

loPDFSection_ = loPDFDoc_.Sections.Add()
loPDFSection_.IsLandscape = False

loPDFSection_.Paragraphs.Add(loPDFText_) 'this is where it seems to strip out the leading spaces.

Hi,

Thank you for considering Aspose.

I don't know if I have understood your requirement exactly. The string in lsPage_ creates 3 lines and the last line has no leading space. If you add some space before "this begins ..", you can see the leading space.

No, when I add the lsPage_ string to the text object as the First thing I add the leading Spaces and Carriage Return/Line Feeds are deleted and all I get is the text "This begins..." as the beginning of the text. I want to know how to add the text with the leading spaces and carriage returns without having them stripped off. When I display the document it should have two blank lines and then the first line of text.

Thanks,

James Knowlton

Please try the following code and you can find there are two empty lines and spaces before the text:

lsPage_ = " " & vbCrLf & " " & vbCrLf & " this begins the text I want printed"

loPDFText_ = New Text
With loPDFText_
.TextInfo.Alignment = AlignmentType.Left
'.TextInfo.FontName = FontName_
'.TextInfo.FontSize = FontSize_
.IsSpaced = True
End With

loPDFSegment_ = loPDFText_.Segments.Add(lsPage_)

loPDFSection_ = loPDFDoc_.Sections.Add()
loPDFSection_.IsLandscape = False

loPDFSection_.Paragraphs.Add(New Text("This is a line for reference."))
loPDFSection_.Paragraphs.Add(loPDFText_) 'this is where it seems to strip out the leading spaces.

I'm afraid that did not have any affect. I had to replace "This is a line for reference." with " " because obviously I don't want any text at the begining of the page, I want blank lines.

Is there really no way to add "text" to a segment without losing the leading blank lines?

I'm experimenting with changing the top margin off the section to account for the blank lines but it seems to be affecting the positioning of text on other parts of the page.

What I'm attempting to do is to print address labels in VERY specific locations on a page. The address must start exactly according to the following:

Label #1 & Label #2 = 1.5 inches down the page, #1 indented .25 inches and #2 starting at 4.25 inches (I used columns in MS Word, but can't get those to work in PDF, something about unable to write directly to PDF without enterprise version).

Label #3 & #4 = 4.25 inches down and across same distance as previous

Label #5 & #6 = 7 inches down and across same distance as previous

Label #7 & #8 = 9.75 inches down and across same distance as previous.

I'm able to come close when using Courier New, 10pt and then simply puttting the addresses on specific lines in a very large string (1 page of text). Not very efficient but it would work if this tool would quit stripping of leading blank lines.

Any suggestions on how to create 8 paragraphs in a text or section object and position them VERY specifically on the page? Everything I tried failed to position the stuff correctly which is why I resorted to a HUGE string in which everything was positioned where I want it and then adding that string to the Text/Section object.

Thanks,

James Knowlton

Dear James,

I don’t know if you have tested my code. I have attached the result. If it is not what you want, can you please provide a graph or Word document to tell me what is you want?

From the description of your reauirement, I think you can use custom positioning. Please refer to CustomPositioning. Using this feature you can easily put your text at some position exactly.

I did test it, and it's not what I needed because the first several lines must be blank. I solved the problem by adjusting the margins of the page when I know the first few lines are going to be blank I'm attaching an example. The annoyance with this is having to the set of labels at the beginning of each page NOT have the blank lines and then having all the rest on the page have them. Just inconvient especially when the labels need to use the first few lines for a return address then I have to reset the page margins again.

Just seems to me that if I send blank lines to the document it should print blank lines.

Thanks for the help.

James.

Dear James,

I can't see your attachment. If you can provide a example of what you want, I will write example code for you.