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

Free Support Forum - aspose.com

Differences in right-align between Aspose.Pdf 3.6 and 6.7

We had been using Aspose.Pdf.dll version 3.6 for awhile and we just recently upgraded to version 6.7.

Unfortunately, this upgrade has caused several changes in our resulting PDFs.

one of the changes I am having trouble remedying is the way that the AlignmentType.Right is arranging things for us. Here is an excerpt of code we are using:

TextInfo info = (TextInfo)pdf.TextInfo.Clone();
info.Alignment = AlignmentType.Right;

Text t = new Text(“TEST”, info);
t.PositioningType = PositioningType.PageRelative;
t.Top = 5;
t.Left = 30;
t.TextWidth = 90;
CurrentPage.Paragraphs.Add(t);

In 3.6, what this would do is put a text block 30 pixels in, and make that block 90 pixels wide, and right-aligned, so the “TEST” text would be on the right side of that 90-pixel box (so the right-side of the text is at 120 pixels).

However, when we run this code using the 6.7 version of the dll file, it always prints the “TEST” text to the far-right edge of the pdf. What do we have to change in our program to give us the same results it gave is in 3.6?

Here is the full code I am using to compare 3.6 and 6.7-- the “using Asponse.Pdf.Generator” is only there for 6.7, otherwise I am using the same code with each dll, and it’s producing different results.

using System;
using Aspose.Pdf;
using Aspose.Pdf.Generator;
using System.IO;
using System.Collections;
using System.Reflection;
using System.Web;

namespace PDFConverter
{
class Converter
{
[STAThread]
static void Main(string[] args)
{

float PointSize = 8.375f;
Pdf pdf = null;
pdf = new Pdf();
pdf.IsBuffered = false;
pdf.PageSetup.PageHeight = 612;
pdf.PageSetup.PageWidth = 792;
Section CurrentPage = pdf.Sections.Add();
TextInfo info = (TextInfo)pdf.TextInfo.Clone();
info.Alignment = AlignmentType.Right;

Text t = new Text(“TEST”, info);
t.PositioningType = PositioningType.PageRelative;
t.Top = 5;
t.Left = 30;
t.TextWidth = 90;
CurrentPage.Paragraphs.Add(t);

pdf.Save(@“C:\alignnew.pdf”);
}

}
}

Hi Scott,

Thanks for using our product and sharing the sample source code with us.

I tested the scenario with your provided source code using Aspose.Pdf for .NET v7.0 and unable to find any issue. Resultant PDF document is attached for your reference. Kindly use the latest version of Aspose.Pdf for .NET v7.0 and check if it works fine for you.

Please feel free to contact support in case you need any further assistance.

Thanks & Regards,

The PDF you attached does show the problem. You see that the word “TEST” is on the far right of the PDF. With the “Left” property of the Text object being set at 30, and the TextWidth property being set at 90, I would expect that the right-most part of the word “TEST” would be at 120 pixels on the page. This is how version 3.6 behaved-- I’ve attached an example using Aspose 3.6 to explain the difference.

If you compare my attachment to your attachment, you can see the difference between the 3.6 and the 7.0 versions. What we need to know is how to recreate the behavior from our 3.6 version?

How do we create a right-aligned text field that is not on the far right of the screen?

Hello,

Have you had a chance to look at this yet? This roadblock is a critical problem for our customers’ PDF processing within our product.

Are you able to see the difference in my PDF and yours? If you need any more clarification, is there a way I can contact you directly regarding this issue?

Thanks,
Scott

Hi Scott,


Thanks for sharing the details and sorry for replying you late.

I
have tested the scenario and I am able to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as PDFNEWNET-33918. We
will investigate this issue in details and will keep you updated on the status
of a correction.

We
apologize for your inconvenience.

I’m actually having this same issue in version 7.7.0. Was there ever a resolution to this? Is there some other way to define the width of the text field to allow right justification?


I’m in the process of prototyping a PDF creator for our small agency product, using the trial version.

Hi Mac,


Thanks for contacting support. Can you please share the code snippet that you are using so that we can test the scenario at our end. We are sorry for this inconvenience.
Thanks for your response.

The code I've written does not translate well to a snippet, but I took the code shown above in this thread and modified it slightly to illustrate the point.

private void test()
{

Pdf pdf = null;
pdf = new Pdf();
pdf.IsBuffered = false;
pdf.PageSetup.PageHeight = 612;
pdf.PageSetup.PageWidth = 792;
Section CurrentPage = pdf.Sections.Add();
TextInfo info = (TextInfo)pdf.TextInfo.Clone();
info.Alignment = AlignmentType.Right;

Text t = new Text("TEST", info);
t.PositioningType = PositioningType.PageRelative;
t.Top = 5;
t.Left = 30;
t.TextWidth = 90;
CurrentPage.Paragraphs.Add(t);

pdf.Save("C:\\test.pdf");
System.Diagnostics.Process.Start("c:\\test.pdf");
}

Much the same as the original poster said, I get the word test to the extreme right of the page, when i would have expected it somewhere mid page, based on the size width of the text.

The original posting also listed an issue tracking number (PDFNEWNET-33918).

Is there a way to track this from my standpoint, or is that really only an internal number?

MacScotsman:
The code I’ve written does not translate well to a snippet, but I took the code shown above in this thread and modified it slightly to illustrate the point. Much the same as the original poster said, I get the word test to the extreme right of the page, when i would have expected it somewhere mid page, based on the size width of the text.
Hi Mac,

Thanks for sharing the code snippet and sorry for the delayed response.

I have tested the scenario and have observed the same results as shared in your earlier post. However I would suggest you to please try using Auto value from PositioningType enumeration instead of PageRelative and the output generated with this modification is quite better. For your reference, I have also attached the resultant PDF which I have generated over my end.

MacScotsman:
The original posting also listed an issue tracking number (PDFNEWNET-33918).

Is there a way to track this from my standpoint, or is that really only an internal number?

The issue management system is for internal use only and I am afraid you might not have access to it. However we share the issue ID’s so that customers can keep track of issues reported by them and release notes also contain the issue ID’s fixed in particular version.

I get the same result as you when I change the enum to auto.


But based on a page width of 792 and a left location of 30 with a width of 90, it would seem that the correct location would be somewhere in the left 1/3 of the page, not on the right side as your attached pdf shows…

It can be illustrated by adding the following line to the code snippet

t.TextInfo.BackgroundColor = new Aspose.Pdf.Generator.Color(“Yellow”);

Then you will see a yellow bar that starts about where I’d expect it to, but then stretches to the other side of the page.


Hi Mac,


Thanks for sharing the details. I am able to notice the problem and have communicated the same information to development team. We will definitely consider this information during the resolution of this problem. Please be patient and spare us little time.

Has this been fixed? Our company originally posted this way back in 2011.


We really need to move forward with a new pdf option, but this error will be a deal breaker.


Hi Mac,


Thanks for your patience.

I have again tested the scenario using Document Object Model of Aspose.Pdf for .NET as per my observations, the output being generated is correct. Please take a look over following code snippet. Please note that the Horizontal alignment of text is set as Right so XIndent is calculated from right page margin. For your reference, I have also attached the resultant PDF file generated with latest release of Aspose.Pdf for .NET 8.5.0.

[C#]

// instantiate Document object<o:p></o:p>

Document doc = new Document();

// add page to PDF file

doc.Pages.Add();

// set the height of PDF file

doc.Pages[1].PageInfo.Height = 612;

// set the width of PDF file

doc.Pages[1].PageInfo.Width = 792;

// create Text fragment object

Aspose.Pdf.Text.TextFragment textfrag = new TextFragment("TEST");

// set the alignment of text fragment as right

textfrag.TextState.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;

// specify the YIndent of TextFragment

textfrag.Position.YIndent = 5;

textfrag.Position.XIndent = 30;

// set the background color of TextFragment object

textfrag.TextState.BackgroundColor = Aspose.Pdf.Color.Yellow;

// add the text fragment to paragraphs collection of page

doc.Pages[1].Paragraphs.Add(textfrag);

// save the PDF file

doc.Save(“c:/pdftest/TextFragment_AlignmentIssue.pdf”);

I am testing with v9.0 and am getting the same issue as first mentioned in this thread. All Text objects with right aligned TextInfo print on the far-right edge of the pdf. I tried using right margin but that messed up other things. Shouldn’t the Left positioning this work exactly the same as left aligned text objects?

This is STILL an issue in version 9.0.0.0.


How has this not been corrected since it was first reported almost two years ago? Our company is waiting to purchase licensing for this product until this issue has been corrected.

Is there a time frame on when this issue will be looked at if at all?

Thank you.

Hi Steve,


We are sorry for the inconvenience caused. I am afraid the reported issue is still not resolved due to other priority tasks. However, we have shared your concerns with the development team and requested to investigate the issue and share an ETA at their earliest. We will update you as soon as we get a feedback.

Thanks for your patience and cooperation.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-33918) have been fixed in Aspose.Pdf for .NET 9.2.0.

The blog post for this release is created over this link


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.