Hi,
Hi Gary,
Hi Sana,
Thank you for assistance. Currently I am using code like this to add some text with links to a pdf document. I want to put the text in any position I want in a page so I use a stamp to implement this.
Aspose.Pdf.Document document;
string text = “something”; //the string might be so long that it may exceed the width of the page, or I just want to divide them to multiple lines
PdfFileStamp fileStamp = new PdfFileStamp();
fileStamp.BindPdf(document);
FormattedText formattedText = new FormattedText(text, TextColor, BackgroundColor, TextFont, TextEncoding, true, TextSize);
float totalHeight;
float totalWidth;
if(formattedText .TextWidth<=MaxLineWidth)// if the width of the test is not greater than give value, we can draw that text in one line
{
var textStamp = new Stamp();
textStamp.BindLogo(formattedText );
totalHeight = formattedText.TextHeight;
textStamp.SetOrigin(x-totalHeight ,y);//given x,y is left up corner. We use this for multi-line situation
textStamp.Page = new int[]{pagenum};
totalWidth = formattedText.TextWidth;
fileStamp.AddStamp(textStamp);
}
else// otherwise we have to divide text into several parts that fit the width
{
List textPartList= WordTrap(text,fontstyle,fontsize)//I was wondering if there is a function break a long string into lines that already exists, and I hope it won’t break a word to two parts
totalHeight = 0;
foreach (string part in textPartList)
{
FormattedText formattedPart = new FormattedText(part , TextColor, BackgroundColor, TextFont, TextEncoding, true, TextSize);
totalHeight+=formattedPart.TextHeight;
textStamp.BindLogo(formattedPart );
textStamp.SetOrigin(x-totalHeight ,y);
textStamp.Page = new int[]{pagenum};
fileStamp.AddStamp(textStamp);
}
}
Page page = document.Pages[i];
LinkAnnotation link = new LinkAnnotation(page, new Rectangle(x, y-totalHeight, x+totalWidth, y));
Border border = new Border(link);
border.Width = 0;
link.Border = border;
link.Action = someAction;
page.Annotations.Add(link);
Please let me know if you want to know more about my problem.
Hi Gary,