Left/Top aligning of text

I have a very simple requirement and it is proving to be very difficult withyour product.
I am appending text to an existing pdf file. I cannot get the text/paragraph to be aligned to the left/top of the page. Currently it is adding the text to the bottom of the page. Please give the code to position the paragraph to the top of the page. The text is variable in length, so I would appreciate the formula to calculate the XIndent/YIndent properties of the Position object.

My code looks as follows:

TextBuilder textBuilder = new TextBuilder(page);
TextParagraph para = new TextParagraph();
para.Position = new Position(?,?); //PLEASE HELP HERE
using (StreamReader file = new StreamReader(fileToCombine))
{
string line;
while ((line = file.ReadLine()) != null)
{
para.AppendLine(line);
}
}
textBuilder.AppendParagraph(para);

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

Thank you for considering Aspose.Pdf.

You can use Page.Rect and TextParagraph.Rectangle properties to set the alignment of the paragraph to be added in the PDF document. Please see the following sample code which adds the new paragraph to top left of the PDF file.

Aspose.Pdf.Document dom = new Aspose.Pdf.Document("input.pdf");

Page page = dom.Pages[dom.Pages.Count];

TextBuilder textBuilder = new TextBuilder(page);

TextParagraph para = new TextParagraph();

using (StreamReader file = new StreamReader("temp.txt"))

{

string line;

while ((line = file.ReadLine()) != null)

{

para.AppendLine(line);

}

}

para.Position = new Position(page.Rect.LLX, page.Rect.URY - para.Rectangle.Height);

textBuilder.AppendParagraph(para);

dom.Save("output.pdf");

However, during my test I am able to notice a problem that para.Rectangle.Height is not returning the proper value. As per my test, after adding the lines to paragraph, the height property is not updating properly (but the non public member is showing the new height, you may check / Confirm that by using the break point on para.Rectangle line). I have registered an issue in our issue tracking system with issue id: PDFNEWNET-34394. We will notify you via this forum thread regarding any updates against this issue.

Sorry for the inconvenience,

Thank you for the quick reply.

I also have noticed that the height is not being updated after lines are added to the paragraph. Any idea as to when we can expect a hotfix? Or if you could indicate the name of the private member, I could use reflection to determine the height of the paragraph.

Thanks,

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

Thank you for the feedback.

Well, we are just able to notice the problem and it will require some time for our development team to further analyze the issue and schedule it for fixing. Once the issue is further analyzed and scheduled by the development team, we will update you regarding the ETA of the reported issue.

Regarding the non-public member which is showing the updated value, I have share a screen shot of the debug item if that can be of any help.

Sorry for the inconvenience,

Any update on this issue?

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

I am afraid; we don’t have any update regarding your issue at the moment as our development team will need some time to analyze your issue (due to other priority issues). However, I have requested the development team to share an ETA regarding the resolution of your issue once they are done with their analysis. As soon as I receive a feedback, I will update you via this forum thread.

Sorry for the inconvenience,

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

I have received a feedback from the development team and as per the plan; your issue will be fixed and released in Aspose.Pdf for .NET v7.6 to be released in December 2012. However, please keep in mind that it is an ETA (not a promise) and in case there is some change in the plan by the development team (due to other priority issues), we will update you via this forum thread.

Sorry for the inconvenience,

Hi Jason,


Once Aspose.Pdf for .NET 7.6.0 has been released, please use TextRectangle property to retrieve text dimensions that was added to TextParagraph

  • Rectangle property is dimensions object, defined by the user. It is just a placeholder that is used to format the text.
  • TextRactangle property is calculated. It may be used if user needs actual text dimensions.


[C#]

Aspose.Pdf.Document
dom = new Aspose.Pdf.Document(“c:/pdftest/Test.pdf”);<o:p></o:p>

Page page = dom.Pages[dom.Pages.Count];

TextBuilder textBuilder = new TextBuilder(page);

TextParagraph para = new TextParagraph();

using (StreamReader file = new StreamReader("c:/pdftest/temp.txt"))

{

string line;

while ((line = file.ReadLine()) != null)

{

para.AppendLine(line);

}

}

para.Position = new Position(page.Rect.LLX ,page.Rect.URY - para.TextRectangle.Height);

// get text position information

Console.WriteLine("" + page.Rect.LLX + (page.Rect.URY - para.TextRectangle.Height));

textBuilder.AppendParagraph(para);

dom.Save("c:/pdftest/temp_output.pdf");

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


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