Modify annotation on FreeTextAnnotationChanged event

Hello,

I'm trying to modify the width and height of a free text annotation when it is created. I have an eventhandler on the FreeTextAnnotationChanged event of the PdfViewerControl (simplified version):

private void PdfViewerControl_FreeTextAnnotationChanged(object sender, FreeTextAnnotationChangedEventArgs e)
{
if (e.Action == AnnotationChangedAction.Add)
{
e.Settings.Width = _labelWidth;
e.Settings.Height = _labelHeight;
}
}

The width and height are being stored in a private variable (_labelWidth and _labelHeight). When the user resizes the textbox (e.Action == AnnotationChangedAction.Resize), the new width and height are stored in these private variables. I already figured out that I have to swap them when the orientation is landscape:

if (e.Action == AnnotationChangedAction.Resize)
{
if (PdfViewerControl.LoadedDocument.Pages[e.PageNumber - 1].Rotation == Syncfusion.Pdf.PdfPageRotateAngle.RotateAngle90 ||
PdfViewerControl.LoadedDocument.Pages[e.PageNumber - 1].Rotation == Syncfusion.Pdf.PdfPageRotateAngle.RotateAngle270)
{
_labelWidth = e.NewBounds.Height;
_labelHeight = e.NewBounds.Width;
}
else
{
_labelWidth = e.NewBounds.Width;
_labelHeight = e.NewBounds.Height;
}
}

This works like expected on a standard A4 sized portrait page. But when I open a A3 sized landscape PDF and create a new free text annotation with the modified width and height, the selection box does not match the actual textbox:


Can someone help me solve this issue or is it possible to share the code that is being executed when a new FreeTextAnnotation is created by selecting the tool on the toolbar and clicking somewhere in the document?

Thanks!


Edit: I'm explicitly not looking for a solution that requires the document to be saved and reloaded. We work with large PDF files and it takes about 5 seconds to load. It's not a workable solution to have to wait 5 seconds after each click.


6 Replies 1 reply marked as answer

VS Vikas Sekar Syncfusion Team December 3, 2021 05:22 PM UTC

Hi Wouter, 
 
We can reproduce the reported issue “Selection Bounds Changes when modify and add free text bounds on rotated page”. We have forwarded this issue to our development team for further analysis, and we will update further details on 7th December 2021. 
 
Regards, 
Vikas 



VS Vikas Sekar Syncfusion Team December 8, 2021 11:19 PM UTC

Hi Wouter, 
  
Sorry for the inconvenience. 
  
Can you please confirm and provide details for the below? 
  
We can reproduce the reported issue “Selection Bounds Changes when modify and add free text bounds on rotated page” 
As we mentioned earlier, we can able to reproduce this issue by certain replication steps. Please find the replication steps in below which we have reproduced this issue. 
  
1.       Initialize values for variables _labelWidth and _labelHeight in application and use it in the code that you have shared. 
2.       Add free text annotation in 0-degree portrait page of A4 document. 
3.       Rotate the page to 90 degree. 
4.       Add free text annotation in rotated page. 
5.       Now if we select the added annotation the selection bounds were improper. 
  
Can you please confirm us whether our observation is same as you have reported? 
  
Note: Currently, we are validating the issue with the above replication. we will update future detail on 10th Dec 2021. 
  
  
  
Also, can you please share your requirement which you are trying to achieve? This will help us to understand and provide prompt solution for your requirement. 
  
Regards, 
Vikas 



WV Wouter van der Post replied to Vikas Sekar December 9, 2021 08:26 AM UTC

The steps to reproduce are correct. 

Also note that it is not required to rotate the page within your control. We have A0 size PDF files that have landscape orientation already. When I open one of those files in Syncfusion PDF control, it also messes up the selection bounds.


The requirement:

A user can place a text annotation on the page, resize it, and the next text annotation that is being placed should have the width and height of the earlier resized annotation.



DD Divya Dhayalan Syncfusion Team December 10, 2021 09:43 PM UTC

Hi Wouter, 
 
Thank you for your confirmation and providing information.  
 
From the provided information, we come to know that, to set desire bounds (width and height ) for newly creating free text annotation. To achieve this we should set the size for freetext annotation using FreeTextAnnotationSettings. This will set the default properties for newly creating annotation. Please find the below code snippet for the same. 
 
pdfViewerControl.Load("../../Data/A2.pdf"); 
pdfViewerControl.FreeTextAnnotationSettings.Height = _labelHeight; 
pdfViewerControl.FreeTextAnnotationSettings.Width = _labelWidth; 
 
private void PdfViewerControl_FreeTextAnnotationChanged(object sender, FreeTextAnnotationChangedEventArgs e) 
        { 
            if (e.Action == AnnotationChangedAction.Resize) 
            { 
                if (pdfViewerControl.LoadedDocument.Pages[e.PageNumber - 1].Rotation == Syncfusion.Pdf.PdfPageRotateAngle.RotateAngle90 || 
                    pdfViewerControl.LoadedDocument.Pages[e.PageNumber - 1].Rotation == Syncfusion.Pdf.PdfPageRotateAngle.RotateAngle270) 
                { 
                    _labelWidth = e.NewBounds.Height; 
                    _labelHeight = e.NewBounds.Width; 
                    pdfViewerControl.FreeTextAnnotationSettings.Height = _labelHeight; 
                    pdfViewerControl.FreeTextAnnotationSettings.Width = _labelWidth; 
                } 
                else 
                { 
                    _labelWidth = e.NewBounds.Width; 
                    _labelHeight = e.NewBounds.Height; 
                    pdfViewerControl.FreeTextAnnotationSettings.Height = _labelHeight; 
                    pdfViewerControl.FreeTextAnnotationSettings.Width = _labelWidth; 
                } 
            } 
        } 
 
We have also created a sample for your reference, and which can be downloaded from the below link, 
 
Please check the above details and let us know if it is helpful or if you need any further assistance on this. 
 
Regards, 
Divya  


Marked as answer

WV Wouter van der Post replied to Divya Dhayalan December 16, 2021 10:22 AM UTC

Thanks! This seems to be a working solution.



DD Divya Dhayalan Syncfusion Team December 17, 2021 05:26 AM UTC

Hi Wouter, 
 
Most welcome, we are glad that the provided solution helped to resolve the issue in your end. Please let us know if you need any further assistance on this. 
 
Regards, 
Divya

Loader.
Up arrow icon