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,
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.
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?
Hi Mac,
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.
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.
Hi Mac,
Has this been fixed? Our company originally posted this way back in 2011.
Hi Mac,
// 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.
Hi Steve,
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.