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.
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.
|
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.
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;
}
}
} |
Thanks! This seems to be a working solution.