Change text color of Link Annotation

Hi

I am trying to change the color of a text within a Link Annotation using the code sample provided in your documentation. It is changing the color even outside of the link rectangle for the some of PDF documents. I have attached both input & out documents for your reference. It worked fine for some PDF documents. I am using Aspose.pdf version v11.2.0

The following is the code sample from Aspose URL "http://www.aspose.com/docs/display/pdfnet/Update+Links+in+a+PDF+File"

/// Code Start
Document doc = new Document("AsposeCaseExample.pdf");
foreach (Annotation annotation in doc.Pages[1].Annotations)
{

if (annotation is LinkAnnotation)
{

//search text under the annotation
TextFragmentAbsorber ta = new TextFragmentAbsorber();
Rectangle rect = annotation.Rect;
rect.LLX -= 10;
rect.LLY -= 10;
rect.URX += 10;
rect.URY += 10;
ta.TextSearchOptions = new TextSearchOptions(rect);
ta.Visit(doc.Pages[1]);
//change color of the text.
foreach (TextFragment tf in ta.TextFragments)
{
tf.TextState.ForegroundColor = Color.Red;
}
}
}
doc.Save("output.pdf");
/// Code End

I have attached sample input file "color-issue-input.pdf" having one link annotation using which I created an output file "color-issue-output.pdf". In output file you can see the text is changed even outside of the link rectangle. This is an issue for us now.

Please let me know is there any resultion for this or Am I doing something incorrect here?

Regards

Chenna Basappa C

Hi Cheena,

Thanks for your inquiry. I have tested your scenario with shared document using Aspose.Pdf for .NET 11.3.0 and managed to observe the reported issue. For further investigation, I have logged an issue in our issue tracking system as PDFNEWNET-40279 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

We are sorry for the inconvenience caused.

Hi,

Any update on this issue "PDFNEWNET-40279"?, I did not see this is fixed in most recent release (v11.4.0).

Regards

Chenna Basappa C

Hi Cheena,


Thanks for your inquiry. I am afraid your issue is still not resolved as we have recently noticed the issue and it is still pending for investigation in the queue with other issues, reported earlier. As soon as our product team completes the investigation of the issue then we will share any ETA/findings. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience.

Best Regards,

Hi,

Could I expect the resolution to this issue atleast in next few days? Due to this issue our project timeline is now at risk.

Please expedite the issue at the earliest and do the needful.

Thanks in advance.

Regards

Chenna Basappa C

Hi Cheena,


Thanks for your patience.

As we recently have noticed this problem, so its still pending for review. However I have shared your concerns with product team and they will surely consider them, while resolving this problem. As soon as we have some further updates, we will let you know. Please be patient and spare us little time.

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


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi,

We still see issue in applying Link text color, The issue is not completely fixed.

Issue related to applying Text color outside of link rectangle seems resolved, But now we are finding another issue,

i.e. Text color is applying partially inside link rectangle for some of the links.

Please find I have attached two sample PDF files,

  1. input-1.pdf
  2. output-1.pdf

You can verify the output file (output-1.pdf), after applying link text color, the color is not applying completely to the text inside the link rectangle. We have many documents having this issue.

I used AdobePDF.Net version v11.7 and the sample code is same as mentioned in issue-id “PDFNEWNET-40279”.

Please look into the issue and let me know if you need further information on this.

Regards,

Chenna Basappa

Hi Chenna,


We are sorry for the inconvenience. I am afraid I am unable to find attachments (input-1.pdf,output-1.pdf). We will appreciate it if you please attach the documents again, so we will look into it and will guide you accordingly.

Best Regards,

Hi,



Please find now I have attached the files. Sorry for the inconvenience,



Regards



Chenna Basappa C

Hi Chenna,

Thanks for sharing the resource files.

I have tested the scenario using following code snippet and as per my observations, the color of Annotation is not getting changed. The Annotations count being returned is 0. Can you please share the code snippet which you are using, so that we can test the scenario in our environment. We are sorry for this inconvenience.

[C#]

Document doc = new Document(@"C:\pdftest\input-1.pdf");

foreach (Aspose.Pdf.Annotations.Annotation annotation in doc.Pages[1].Annotations)
{
    if (annotation is LinkAnnotation)
    {
        // Search text under the annotation
        TextFragmentAbsorber ta = new TextFragmentAbsorber();
        Aspose.Pdf.Rectangle rect = annotation.Rect;

        rect.LLX -= 10;
        rect.LLY -= 10;
        rect.URX += 10;
        rect.URY += 10;

        ta.TextSearchOptions = new TextSearchOptions(rect);
        ta.Visit(doc.Pages[1]);

        // Change color of the text
        foreach (TextFragment tf in ta.TextFragments)
        {
            tf.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
        }
    }
}

doc.Save(myDir + "Annotation_color_output.pdf");

Hi,

Thanks for your response. I am sorry, the earlier file “input-1.pdf” doesn’t have links it was my mistake.

I have attached another file “input-2.pdf”. This file has link annotations created using AsposePDF.Net. Please try applying color to link text for this file you will see the issue.

I used your code and applied color still I see issue in output (output-2.pdf).

Hope this will help you to identify the issue.

Hi Chenna,


Thanks for sharing the source document. I have tested the scenario and noticed that text color of link annotation is not changing as expected. It seems file specific issue, so I have logged a ticket PDFNET-41137 in our issue tracking system for further investigation and rectification. We will notify you as soon as we resolve the issue.

We are sorry for the inconvenience caused.

Best Regards,

Hi,

I have tried using sample code snippet shared by Justin on 25th-Aug-2016, It resolved some of the documents, But still there is any issue with some documents.

I have attached Input file (Link-Color-Issue-Input.pdf) and output file (Link-Color-Issue-Output.pdf). You can look at them.

I used AsposePDF.Net version 11.9 with sample code snippet shared by Justin.

Regards

Chenna Basappa C

Hi Cheena,

Thanks for your feedback. We have investigated your above shared document. The problem with your document is that annotations are placed not exactly on text fragments i.e. some of text is intersected with annotations. It is questionable whether this text should marked or not, because if this text is marked we mark text outside of the annotation and otherwise it is not marked. It means we don’t mark text inside of the annotation. Please try following code snippet and confirm the results, a sample output is attached here for reference.

Document doc = new Document("Link-Color-Issue-Input.pdf");

TextFragmentAbsorber ta = new TextFragmentAbsorber();
ta.Visit(doc.Pages[1]);

foreach (Aspose.Pdf.Annotations.Annotation annotation in doc.Pages[1].Annotations)
{
    if (annotation is LinkAnnotation)
    {
        // Search text under the annotation
        Aspose.Pdf.Rectangle rect = annotation.Rect;

        doc.Pages[1].Contents.Add(new Operator.Re(rect.LLX, rect.LLY, rect.Width, rect.Height));
        doc.Pages[1].Contents.Add(new Operator.SetRGBColorStroke(System.Drawing.Color.Blue));
        doc.Pages[1].Contents.Add(new Operator.Stroke());

        foreach (TextFragment tf in ta.TextFragments)
        {
            // Check if annotation rectangle is intersected with text rectangle
            Aspose.Pdf.Rectangle textRect = tf.Rectangle;

            if (textRect.Intersect(rect) != null)
            {
                // Change color of the text
                tf.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
            }
        }
    }
}

doc.Save("Link-Color-Issue-Input-output.pdf");

Best Regards,

Hi Tilal Ahmad,

Thanks for your reply. I understand your code applies color to text fragments with-in link rectangle. I think you are not applying color to individual character. Using AsposePDF.Net I can extract characters from fragments

and I can get each character dimensions, properties etc. Same way, why can’t I apply color to each character?

Using Adobe Acrobat SDK, We are able to apply color to each character with-in link rectangle.

Please see I have attached sample output document (Link-Color-Apply-From-Adobe-SDK.pdf) for your reference, Where characters with-in link rectangle are colored.

Is this limitation from AsposePDF.NET ? OR Do we expect this will be taken care in future releases?

Regards,
Chenna Basappa C

Hi Cheena,

chennabasappa.c:
I understand your code applies color to text fragments with-in link rectangle. I think you are not applying color to individual character. Using AsposePDF.Net I can extract characters from fragments
and I can get each character dimensions, properties etc. Same way, why can’t I apply color to each character?

Thanks for your feedback. As suggested above that in your document annotations are not placed exactly on text fragments. So our “standard” code snippet (with TextSearchOption) does not work in the situation, because we proposed code snippet where intersection of the annotation and text is checked “manually” and decided whether text which intersected with annotation only be marked or not.

chennabasappa.c:
Same way, why can’t I apply color to each character? Using Adobe Acrobat SDK, We are able to apply color to each character with-in link rectangle. Please see I have attached sample output document (Link-Color-Apply-From-Adobe-SDK.pdf) for your reference, Where characters with-in link rectangle are colored. Is this limitation from AsposePDF.NET ? OR Do we expect this will be taken care in future releases?

Thanks for sharing your findings. We have logged an investigation ticket PDFNET-41381 in our issue tracking system for further investigation and implementation of the feature accordingly. We will notify you as soon as we get some updated in this regard.

Best Regards,

Hi Tilal Ahmad,

Thank You for your response on this. This is very urgent for us and pending since long time,
When can we expect this issue (PDFNET-41381) will be addressed? Can you please let us know in which release version you will be addressing this?

Thanks,

Chenna Basappa C

Hi Chenna,


We are sorry for the inconvenience that suggested code did not work for your scenario. We have recorded your concern, also raised the issue priority of above logged issue(PDFNET-41381) and requested our product team to complete its analysis as soon as possible. We will notify you as soon as more information or ETA is available.

Thanks for your patience and cooperation.

Best Regards,

Hi,

Since this issue(PDFNET-41381) was not completely addressed in v16.10.0, Your support has created another issue ID “PDFNET-41556”.

Any Update on this ISSUE ID:PDFNET-41556 ?

Regards

Chenna Basappa