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

Free Support Forum - aspose.com

Problem with HTML and line spacing

Hi Aspose Team

I am not able to figure out how to reduce the space between 2 lines of inserted HTML text.

Here is an example code:


Dim htmlPDF As Pdf = New Pdf()
Dim mySection As Section = New Section(htmlPDF)
htmlPDF.Sections.Add(mySection)

mySection.IsLandscape = False
mySection.IsNewPage = True
mySection.TextInfo.FontName = "Verdana"
mySection.TextInfo.FontSize = 9

Dim myContent As String = "

This is my first div in a p tag
" & _
"
This is my second div in the same p tag
"

Dim myText As Aspose.Pdf.Text = New Aspose.Pdf.Text(mySection, myContent)
myText.IsHtmlTagSupported = True
mySection.Paragraphs.Add(myText)

htmlPDF.Save("C:\Temp\HTMLTest.pdf")

I have also tested with span tags, but then I miss the line breaks !

How do I reduce the space between the two lines ?

Regards, Martti

Hello Martti,

Thanks for considering Aspose.

We have a class named TextInfo which contains a property named LineSpacing, sets a float value that indicates the spacing between two text lines. But as you are using the

HTML tag, it has no effect on it. The contents are being placed over Pdf file based over the HTML tag.

As a workaround you can reduce the line spacing by modifying your text string with

Dim myContent As String = "

This is my first div in a p tag #$NL" & _
"This is my second div in the same p tag

"

Where #$NL is the new line feed character. I have attached the resultant Pdf, please take a look.

For information on replaceable symbols, please visit Replaceable Symbols

Hi,

I am sorry I simplified my example too much.

My HTML is delivered by Infopath, and I do some transformations before I insert the text into PDF.

In my transformation I transform

tag's to tag's with
tag at end of span.
So
"
This is some text.
This is some more text.
  • Bullet one.
  • Bullet two.
"
becomes
"This is some text.
This is some more text.
  • Bullet one.
  • Bullet two.
"

- This is allmost same result as using #$NL, The problem is the new line between the last span and list of bullets !

I would prefer to remove this insert of line breaks, I also have pictures and large XHTML chunks of text witch ends with an unpredictable result.

Regards, Martti

Hi Martti,

I have noticed that using instead of

provides much better results. But, does not display the contents over new line. You need to add the line feed characters to display specific over new line. I have removed
and have used #$NL, and the result is much better. As far as I know, The tag is used to group inline-elements in a document, so the results seemed to be correct.

Also could you please explain, "I also have pictures and large XHTML chunks of text witch ends with an unpredictable result"

Dim myContent As String = "This is some text.#$NLThis is some more text.

  • Bullet one.
  • Bullet two.
"

The resultant file is in attachment, please take a look.

Hi,

Thanks a lot, you solved my problem.

The picture problem seems to be a "keep with next" with some text before and after my pictures, I am currently testing a solution to that problem.

However I discovered a stange thing.

This do not work: "This is some text.#$NLThis is some more text#$NL"

But this do: "#$NLThis is some text.#$NLThis is some more text"

Thank you for your time and solution.

Regards Martti

Hello Martti,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for sharing your observations.

I have tested the scenario and I am able to notice the same problem. When using #$NL as last character in tag, the Tag appears over the resultant Pdf file. We are looking into the details of this issue and will keep you updated with the status of correction. We apologize for your inconvenience.

As a workaround, if you place a single character, even a blank space before closing the Tag, the resultant file is generated fine. Please take a look and try using the following modified string.

Dim myContent As String = "#$NLThis is some text.#$NLThis is some more text#$NL "

Hello Martti,

I am pleased to inform you that the problem you reported is resolved. Please try using the latest version of Aspose.Pdf 3.9.0.0.

In case of any further issue, please feel free to contact.