Do I have to specify a rectangle area for any link action

Hi,

I am using Aspose.PDF library to build a table of content with links to pages or to attachment (I made it using JavaScript Action). Currently I add items in the table of content as stamps and set a rectangle area for link action that covers corresponding text for each link. In this approach I have to calculate the position and size of each item and place them manually . I was wondering there is another way I can automatically add text object and set its links.

I have tried Aspose.PDF.Heading and it is good I was wondering if I can change the text on the right, which is the direction page number of the link to something else since if I set the direction to an attachment, the page number is invalid.

Hi Gary,


Thanks for your feedback. We will appreciated it if you please share your sample code here. We will look into it and will guide you accordingly.

Best Regards,

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,


Thank for sharing the additional information. I am afraid currently Aspose.Pdf does not support to edit TOC, to change text page number text on right side of the entry and its link to other than page destination. We have logged an enhancement ticket PDFNEWNET-37569 in our issue tracking system to investigate your requirement and its implementation. We will notify you as soon as we implement it.

Moreover, I am afraid you have to mention rectangle coordinates for any link action for positioning purpose.

We are sorry for the inconvenience caused.

Best Regards,