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

Free Support Forum - aspose.com

Create Link annotation with page break

Hi Aspose Team,


We are trying to create a link annotation with page break (like few text in first page and few text in second page) using below code. but we are failed to create link annotation in 2 different page same time. Refer the attached PDF file & image file.

Please help to create link annotation with page break.

NOTE: its very high priority. Please help me ASAP

TextFragmentCollection textFragmentCollection;
Document doc = new Document(pdf);
TextFragmentAbsorber textFragmentAbsorber;
textFragmentAbsorber = new TextFragmentAbsorber(kv.Key, new TextSearchOptions(true));

doc.Pages.Accept(textFragmentAbsorber);

//get the extracted text fragments
textFragmentCollection = textFragmentAbsorber.TextFragments;

if (textFragmentCollection.Count > 0)
{
foreach (TextFragment textFragment in textFragmentCollection)
{
// Use the text segments when the text fragment has a newline char.
if (textFragment.Text.Contains(Environment.NewLine))
{
foreach (TextSegment s in textFragment.Segments)
{
// Create the annotation for each segment.
s.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
LinkAnnotation link = new LinkAnnotation(textFragment.Page, s.Rectangle);
Aspose.Pdf.Point start = new Aspose.Pdf.Point(s.Rectangle.LLX, s.Rectangle.LLY);
Aspose.Pdf.Point end = new Aspose.Pdf.Point(s.Rectangle.LLX + s.Rectangle.Width, s.Rectangle.LLY);
LineAnnotation line = new LineAnnotation(textFragment.Page, s.Rectangle, start, end);

line.Color = Aspose.Pdf.Color.Blue;
line.Border = new Border(link) { Width = 1 };
link.Border = new Border(link) { Width = 0 };
s.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
link.Action = new GoToURIAction(kv.Value);
textFragment.Page.Annotations.Add(link);
textFragment.Page.Annotations.Add(line);
}
}
}
}


Regards,
Ganesan. BHi Aspose Team,


We are trying to create a link annotation with page break (like few text in first page and few text in second page) using below code. but we are failed to create link annotation in 2 different page same time. Refer the attached PDF file & image file.

TextFragmentCollection textFragmentCollection;
Document doc = new Document(pdf);
TextFragmentAbsorber textFragmentAbsorber;
textFragmentAbsorber = new TextFragmentAbsorber(kv.Key, new TextSearchOptions(true));

doc.Pages.Accept(textFragmentAbsorber);

//get the extracted text fragments
textFragmentCollection = textFragmentAbsorber.TextFragments;

if (textFragmentCollection.Count > 0)
{
foreach (TextFragment textFragment in textFragmentCollection)
{
// Use the text segments when the text fragment has a newline char.
if (textFragment.Text.Contains(Environment.NewLine))
{
foreach (TextSegment s in textFragment.Segments)
{
// Create the annotation for each segment.
s.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
LinkAnnotation link = new LinkAnnotation(textFragment.Page, s.Rectangle);
Aspose.Pdf.Point start = new Aspose.Pdf.Point(s.Rectangle.LLX, s.Rectangle.LLY);
Aspose.Pdf.Point end = new Aspose.Pdf.Point(s.Rectangle.LLX + s.Rectangle.Width, s.Rectangle.LLY);
LineAnnotation line = new LineAnnotation(textFragment.Page, s.Rectangle, start, end);

line.Color = Aspose.Pdf.Color.Blue;
line.Border = new Border(link) { Width = 1 };
link.Border = new Border(link) { Width = 0 };
s.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
link.Action = new GoToURIAction(kv.Value);
textFragment.Page.Annotations.Add(link);
textFragment.Page.Annotations.Add(line);
}
}
}
}


Regards,
Ganesan. B

I am using below mentioned regex pattern for find text.

(?im)\b2[\W]*0[\W]*0[\W]*9[\W]*0[\W]*0[\W]*0[\W]*6[\W]*7[\W]*8[\W]*9[\W]*4[\W]*2\b

Hi Ganesan,


Thanks for contacting support.

I have tried testing the scenario over my end where I have used the following code line to find the TextFragment and I am afraid I am getting following exception. Can you please share complete code which can help us in replicating this issue at our end. We are sorry for this inconvenience.

[C#]

TextFragmentCollection textFragmentCollection;<o:p></o:p>

Aspose.Pdf.Document doc = new Aspose.Pdf.Document("c:/pdftest/exhitbit.pdf");

TextFragmentAbsorber textFragmentAbsorber;

textFragmentAbsorber = new TextFragmentAbsorber("(?im)\b2[\\W]*0[\\W]*0[\\W]*9[\\W]*0[\\W]*0[\\W]*0[\\W]*6[\\W]*7[\\W]*8[\\W]*9[\\W]*4[\\W]*2\\b)", new TextSearchOptions(true));

doc.Pages.Accept(textFragmentAbsorber);

//get the extracted text fragments

textFragmentCollection = textFragmentAbsorber.TextFragments;

if (textFragmentCollection.Count > 0)

{

foreach (TextFragment textFragment in textFragmentCollection)

{

// Use the text segments when the text fragment has a newline char.

if (textFragment.Text.Contains(Environment.NewLine))

{

foreach (TextSegment s in textFragment.Segments)

{

// Create the annotation for each segment.

s.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;

LinkAnnotation link = new LinkAnnotation(textFragment.Page, s.Rectangle);

Aspose.Pdf.Point start = new Aspose.Pdf.Point(s.Rectangle.LLX, s.Rectangle.LLY);

Aspose.Pdf.Point end = new Aspose.Pdf.Point(s.Rectangle.LLX + s.Rectangle.Width, s.Rectangle.LLY);

LineAnnotation line = new LineAnnotation(textFragment.Page, s.Rectangle, start, end);

line.Color = Aspose.Pdf.Color.Blue;

line.Border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(link) { Width = 1 };

link.Border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(link) { Width = 0 };

s.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;

link.Action = new GoToURIAction("www.google.com");

textFragment.Page.Annotations.Add(link);

textFragment.Page.Annotations.Add(line);

}

}

}

}

doc.Save("c:/pdftest/exhitbit_WithLink.pdf");



A first chance exception of type 'System.ArgumentException' occurred in System.dll

System.ArgumentException: parsing "(?im)2[\W]*0[\W]*0[\W]*9[\W]*0[\W]*0[\W]*0[\W]*6[\W]*7[\W]*8[\W]*9[\W]*4[\W]*2\b)" - Too many )'s.

at System.Text.RegularExpressions.RegexParser.ScanRegex()

at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op)

at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, TimeSpan matchTimeout, Boolean useCache)

at System.Text.RegularExpressions.Regex..ctor(String pattern)

at ?.??.?(String initialOrderPhrase, Int32 startIndex, Boolean isRegexp, Int32& occurenceIndex, Int32& occurenceLength, String& foundTextInitialOrder)

at ?.??.?(Int32& nextStartIndex, String phrase, Boolean isRegexpUsed, ?& foundText, Int32& indexInFirstSegment)

at ?.?.?(String , Boolean )

at Aspose.Pdf.Text.TextFragmentAbsorber.Visit(Page page)

at Aspose.Pdf.Page.Accept(TextFragmentAbsorber visitor)

at Aspose.Pdf.PageCollection.Accept(TextFragmentAbsorber visitor)