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

Free Support Forum - aspose.com

Inconsistency in the text placement using different sizes of font

Hi,

We are using Aspose.PDF dll (version 3.5.0.0)

I am trying to place two text layers one above the other without any spacing between them.Following are the placement coordinates for the text layers in a pdf of size ( 600 * 600)

Text Value Coordinates
Top, Left

PAIR - I “Arial 24” 100, 100
“Arial 24” 117,100


PAIR-II “Arial 24” 100, 400

“Arial 12” 117,400

The placement for PAIR-I text layers works perfectly since the font size is same 24 points for aboth layers( textlayers with text value “Arial24”) …

However when I changes the font size to 12 with the bottom layer of Pair II, there is a text overlap between two layers…which we don’t expect. It’s happening when either the font size is changed or the font name is changes. Is there some some way we could get rid of this inconsistency ?

Following is the code for the reproduction of the issue :-

using System;
using System.Collections.Generic;
using System.Text;
using Aspose.Pdf;

namespace AsposeTextLayerPlacementIssue
{
class Program
{
static void Main(string[] args)
{

Pdf _TemplatePDF;
Section _MainSection;

_TemplatePDF = new Pdf();
_MainSection = _TemplatePDF.Sections.Add();
Aspose.Pdf.Text text;
_MainSection.PageInfo.PageWidth = 600f;
_MainSection.PageInfo.PageHeight = 600f;

text = DrawTextLayer(“Arial 24”, 100, 100, “Arial”, 24);
_MainSection.Paragraphs.Add(text);
text = DrawTextLayer(“Arial 24”, 117, 100, “Arial”, 24);
_MainSection.Paragraphs.Add(text);

text = DrawTextLayer(“Arial 24”, 100, 400, “Arial”, 24);
_MainSection.Paragraphs.Add(text);
text = DrawTextLayer(“Arial 12”, 117, 400, “Arial”, 12);
_MainSection.Paragraphs.Add(text);


_TemplatePDF.Save(@“C:\sample_out.pdf”);



}

static Text DrawTextLayer(string textValue, float top, float left, string fontName, float fontSize)
{
Text textLayer;
System.Drawing.Font textFont;
System.Drawing.FontStyle textStyle = System.Drawing.FontStyle.Regular;

textLayer = new Text(textValue);
textLayer.TextInfo.IsUnicode = true;
textLayer.TextInfo.IsFontEmbedded = true;
textLayer.PositioningType = PositioningType.PageRelative;
textLayer.TextWidth = 1440;

textLayer.TextInfo.FontName = fontName;
textLayer.TextInfo.FontSize = fontSize;
textLayer.TextInfo.IsTrueTypeFontBold = false;
textLayer.TextInfo.IsTrueTypeFontItalic = false;
textLayer.TextInfo.IsUnderline = false;
textLayer.TextInfo.Color = new Color(“Red”);
textLayer.RotatingAngle = 360;
textLayer.Top = top;
textLayer.Left = left;
textFont = new System.Drawing.Font(textLayer.TextInfo.FontName, textLayer.TextInfo.FontSize, textStyle, System.Drawing.GraphicsUnit.Pixel);
textLayer.TextInfo.LineSpacing = textFont.Height * 72 / 300;
return textLayer;

}
}
}


Thanks,
Harshal





Hello Harshal,

You may try specifying the top margin value of "Arial 12" 117,400 TextLayer as 127. As per my observation, the output is being generated without any issue. Can you please take a look over the attached resultant PDF document.

text = DrawTextLayer("Arial 12", 127, 400, "Arial", 12);

In case it does not resolve your problem or you have any further query, please feel free to contact.

We apologize for your inconvenience.

Sure I know that will fix it . but we have an automated system where the user can place back to back textlayers which may be of different size. I guess I am not sure but do you mean different font size should be provided different margin values ??

My point is the inconsistency in the results. The PAIR-I’s second textlayer uses the same top and left margin values (117,400) as “Arial 12” but there is no overlap which is present in PAIR-II’s placement of “Arial 12” . Shouldn’t the top corner placement of “Arial 12” start from the position where the “Arial 24” ends ?

Thanks,
Harshal




Hello Harshal,

I have again tested the scenario and as per your observations, it seems to be an issue. For the sake of correction, I have logged it in our issue tracking system as PDFNET-16807. We will investigate this issue in details and will keep you updated on the status of a correction. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

We apologize for your inconvenience.

Hi Shahbaz,

We have seen this issue also shows up in case the text is one of multiline nature …

One question I had was :-

Doing some experiments we have found out that different fonts produce different line spacing for multiline text …Say for a font of size X points… what is the equation to be followed for assigning the LineSpacing value in the textinfo object of the text layer ?


Also Is there any progress in finding a solution to this
issue ?
We have been getting a lot of issue like this which is
becoming our main concern. And hence we are awaiting for a fix …Please
help …

Thanks,
Harshal

Hi Shahbaz,

We have seen this issue also shows up in case the
text is one of multiline nature …

One question I had was :-

Doing
some experiments we have found out that different fonts produce
different line spacing for multiline text …Say for a font of size X
points… what is the equation to be followed for assigning the
LineSpacing value in the textinfo object of the text layer ?


Also
Is there any progress in finding a solution to this
issue ?
We have been getting a lot of issue like this which is
becoming our main concern. And hence we are awaiting for a fix …Please
help …

Thanks,
Harshal

harshaljoshi:

Doing some experiments we have found out that different fonts produce different line spacing for multiline text ...Say for a font of size X points.. what is the equation to be followed for assigning the LineSpacing value in the textinfo object of the text layer ?

Hello Harshal,

We are looking into the details of this matter that why different fonts are producing different line spacing. Whereas concerning to the resolution of PDFNET-16807 reported earlier, our development team is working hard to get it resolved and I have also contacted them to share the ETA regarding its resolution. Please spare us little time and as soon as we have some definite information, we would be pleased to update you with the status of correction.

Your patience and comprehension is greatly appreciated in this regard. We apologize for your inconvenience.

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

Thanks for your patience.

We have further investigated this issue and have figured out that the issue is occurring because you are using LineSpacing for the text object. In fact the LineSpacing parameter is required for multiline test segments with automatic segments placement. But in your case, you are manually specifying the position for each text block, so I believe LineSpacing is not required. Please comment out the following code lines

// textLayer.RotatingAngle = 360; //no effect
// textLayer.TextInfo.LineSpacing = textFont.Height * 72 / 300;

Meanwhile I have also tested the scenario using the latest release version of Aspose.Pdf for .NET (which will be published sometimes soon) and I am unable to notice the Text overlapping problem. The resultant PDF that I have generated is also in attachment. Please notice that I have used 118f for the Top position of Arial 12 text string. You may also notice from the attached image file that the text is overlapping with a very minor factor.

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

The issues you have found earlier (filed as 16807) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.