TextStamp too long to wrap, out of bounds

How to wrap textstamp?

I want to write a URL that doesn’t wrap when the content is too long. Using formattedtext causes the URL to be invalid

@ljq

Would you please share the sample code snippet with complete URL value so that we can test the scenario in our environment and address it accordingly.

    Document doc = new Document();
    Page page = doc.Pages.Add();
    TextStamp textStamp = new TextStamp("www.baidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidubaidu.com");
    textStamp.TopMargin = 200;
    textStamp.LeftMargin = 100;
    textStamp.Opacity = 1;
    textStamp.Zoom = 1;
    textStamp.HorizontalAlignment = HorizontalAlignment.Left;
    textStamp.VerticalAlignment = VerticalAlignment.Top;
    page.AddStamp(textStamp);
    doc.Save(AppContext.BaseDirectory + "test.pdf");

This is a Smiple.That Url Can’t Change Line.

@ljq

We tried WordWrap and Width properties together to force the text stamp wrapped but it did not give any success. Therefore, an issue has been logged as PDFNET-49054 in our issue tracking system for the sake of further investigation. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

We hope to solve this problem as soon as possible. Our company is preparing to purchase the certificate this month, and we need to submit the version to the customer at the end of this month.

Or can I use a url tag? It is similar to clicking “Click here”, but after clicking it will trigger the internal custom url link. Do you have related functions? FreeTextAnnotation will not be able to click the url and cause movement in the pdf editing software. We want to achieve an effect similar to TextStamp, but it cannot wrap lines, nor can it achieve the effect I described above. We are ready to purchase a certificate, this function is more important! Hope there can be a solution!

@ljq

You can surely create a PDF file with “Click Here” functionality. Once you create a PDF document, you can add a LinkAnnotation around the desired text to link it with some URL. You can find your desired text using TextFragmentAbsober Class. In case you face any issue, please share your sample desired PDF document which you want to obtain. We will try to create similar output and share our feedback with you.

urlTest.pdf (12.5 KB)
Can you create a pdf sample code like the one I provided?
This is created by me using Adobe Acrobat DC

@ljq

Please find below code snippet and attached output PDF document:

Document doc = new Document();
Page page = doc.Pages.Add();
TextFragment text = new TextFragment("Aspose Pty Ltd");
page.Paragraphs.Add(text);
doc.ProcessParagraphs();
TextFragmentAbsorber absorber = new TextFragmentAbsorber("Aspose Pty Ltd");
page.Accept(absorber);
foreach(TextFragment fragment in absorber.TextFragments)
{
 LinkAnnotation link = new LinkAnnotation(page, fragment.Rectangle);
 link.Action = new GoToURIAction("https://aspose.com");
 page.Annotations.Add(link);
}
doc.Save(dataDir + "output.pdf");

output.pdf (2.0 KB)

1 Like

Can I change the text color and set the underline font?
Because it is different from the url, or at least I need to set it to blue

@ljq

You can use following properties for TextFragment to set color and underline:

TextFragment text = new TextFragment("Aspose Pty Ltd");
text.TextState.ForegroundColor = Color.Blue;
text.TextState.Underline = true;

Also, you can remove annotation border using following properties:

LinkAnnotation link = new LinkAnnotation(page, fragment.Rectangle);
link.Action = new GoToURIAction("https://aspose.com");
link.Border = new Border(link);
link.Border.Width = 0;
1 Like
Document doc = new Document();
Page page = doc.Pages.Add();
TextFragment text = new TextFragment("ClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClick");
text.TextState.Underline = true;
text.TextState.ForegroundColor = Color.Blue;
page.Paragraphs.Add(text);
doc.ProcessParagraphs();
TextFragmentAbsorber absorber = new TextFragmentAbsorber();
absorber.TextFragments.Add(text);
page.Accept(absorber);
foreach (TextFragment fragment in absorber.TextFragments)
{
    LinkAnnotation link = new LinkAnnotation(page, fragment.Rectangle);
    Border border = new Border(link);
    border.Width = 0;
    link.Border = border;
    link.Action = new GoToURIAction("https://forum.aspose.com/t/textstamp-too-long-to-wrap-out-of-bounds/221419/9");
    page.Annotations.Add(link);
}
doc.Save(AppContext.BaseDirectory + "output.pdf");

Thank you very much for your answer! I didn’t find the TextState property before, and it can solve my problem perfectly now! And I found that if I use the above code, the problem that the URL is too long and exceeds the boundary can also be solved. Although each line will be decomposed into different textFragments, we can assign each textFragment to the same URL address. Finally, thank you very much for your reply!

@ljq

The earlier suggested approach is recommended when a PDF document is generated and you need to find some text to assign to an URL or weblink. However, at the time of PDF generation, you may also use TextFragment.Hyperlink property to link it with a web URL. This way you would not need to add link annotation separately. Please try using following code:

Document doc = new Document();
Page page = doc.Pages.Add();
TextFragment text = new TextFragment("ClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClick");
text.TextState.ForegroundColor = Color.Blue;
text.TextState.Underline = true;
text.Hyperlink = new WebHyperlink("https://aspose.com");
page.Paragraphs.Add(text);
doc.Save(dataDir + "output.pdf");

output.pdf (2.1 KB)

1 Like

thank you very much! This effect is better!

thank you very much! This effect is better!
I don’t know why I reply to you twice. The first time it didn’t show it was @you, the second time there was a prompt, I don’t know if it’s a bug

@ljq

The post editor allows keyboard shortcuts as well. Do you press Ctrl + Enter by any chance during writing a message? Because it posts the content to the thread.