How to Add Ellipse annotation with coordinates to existing pdf file in Dot Net Aspose.pdf.annotations

Hi Team,
How to add the ellipse on existing pdf file using dot net aspose.pdf.annotations with particular angle or Rotation. With below code Rotation is not working with coordinates, Please help on this.

Sample code for ellipse:

                        Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
                        var pageEllipse = document.Pages[s.pageNumber ?? 0];
                        filename = Path.GetFileName(path);
                        var rectEllipse = GetRectangle(document, (float)xValue, (float)yValue, (float)width, (float)height, (float)CHeight, (float)CWidth, s.pageNumber ?? 0, pageEllipse.Rotate);
                        //int rotation = Convert.ToInt32(s.rotation);
                      //  rectEllipse.Rotate(rotation);

                  
                        var rectAnnotateEllipse = new CircleAnnotation(pageEllipse, rectEllipse)
                        {
                            Title = s.createdByName + ":" + Convert.ToDateTime(s.createdOn).ToString("dd-MMM-yyyy HH:mm"),
                            Color = Aspose.Pdf.Color.Red,
                            Opacity = 1,
            
                        };

                        Aspose.Pdf.Annotations.Border borderEllipse = new Aspose.Pdf.Annotations.Border(rectAnnotateEllipse);
                        borderEllipse.Width = Convert.ToInt32(((s.strokeWidth) * 72 / 150 + (1)) ?? 2); ;
                      
                        rectAnnotateEllipse.Border = borderEllipse;
                        rectAnnotateEllipse.Color = Aspose.Pdf.Color.Parse(s.strokeColor);
                        pageEllipse.Annotations.Add(rectAnnotateEllipse);

document.Save(path);

GetRectangle Method:

public Aspose.Pdf.Rectangle GetRectangle(Aspose.Pdf.Document doc, float llx, float lly, float Urx, float Ury, float CHeight, float CWidth, int currentPage, Aspose.Pdf.Rotation currrotation)
{
float shapeX = ((llx) * 72 / 150);
float shapeY = ((lly) * 72 / 150);
float shapeW = ((Urx) * 72 / 150);
float shapeH = ((Ury) * 72 / 150);

        float CanX = ((CWidth) * 72 / 150);
        float CanY = ((CHeight) * 72 / 150);

        double width1 = 0;

        double height1 = 0;
        if (currrotation == Aspose.Pdf.Rotation.on270 || currrotation == Aspose.Pdf.Rotation.on90)
        {
            width1 = doc.Pages[currentPage].Rect.Height;
            height1 = doc.Pages[currentPage].Rect.Width;
        }
        else
        {
            width1 = doc.Pages[currentPage].Rect.Width;
            height1 = doc.Pages[currentPage].Rect.Height;
        }

        double xx = width1 / CanX;
        double yy = height1 / CanY;

        float LLY = (float)(height1 - (shapeY * yy));
        //float LLX = (float)(width1 - (shapeX * xx));

        double x = (shapeX * xx)-xx;
        double y = LLY+(yy);
        double w = (shapeX + shapeW) * xx;
        double h = (LLY - (shapeH * yy))-yy;

        return new Aspose.Pdf.Rectangle(x, y,w, h);
    }

Thanks & Regards,
Kiran G

@kirangali

There are some undefined variables in the code snippet that you have shared. Can you please share the complete code snippet OR a code snippet with hardcoded values so that it can be tested in our environment? Also, please do share the sample PDF document as well so that we can test the scenario accordingly.

Hi Team,

Please find attached sample code and take any pdf file to draw ellipse annotation with coordinates Annotations Sample code.docx (21.4 KB)

Thanks & Regards,
Kiran G

@kirangali

We are afraid that we were unable to run this code that you have just shared. Are you trying to add the ellipse annotation in a page that is rotated? OR you are specifying the angle of the ellipse annotation and it is not working at your end. For our better understanding, please share a sample PDF along with the information of text around which you need to draw ellipse. Also, share an expected output PDF or screenshot. We will try to create a code snippet to achieve your expected output and share with you.

Hi Team,

we are displaying PDF’s in browser by using pdfjs.js and drawing ellipse annotation on Pdf by mouse coordinates. Please find attachment for reference,Draw with Mouse Coordinates.PNG (17.1 KB)

we are Reading All annotations (Ellipse) with mouse coordinates using Aspose.pdf.annotations to download pdf file with all annotations. Please find attached screen shot.After Download with Aspose.PNG (18.1 KB)

Sample Code: Annotations Sample code.docx (21.4 KB)

Thanks & Regards,
Kiran G

@kirangali

Thanks for sharing more details. As far as the shared code is concerned, we cannot test the case using it as it includes several Classes that are undefined. However, you may share little information which would be helpful in testing the case. Please share some coordinate values for Rectangle object along with the rotation angle value for example:

Ellipse needs to be drawn at Page 1 with:

Rectangle(100, 100, 200, 200) and 90 rotation
Rectangle(25, 25, 60, 60) and 45 rotation

Hi Team,

Please find the below coordinates to draw ellipse with rotation 24.8 .Ellipse Coordinates.PNG (44.4 KB)

Samples Input and output screen shots:Downloaded using aspose with rorate 24.8 .PNG (1.7 KB)
Downloaded using aspose without rorate.PNG (9.7 KB)
Ellipse with mouse coordinates.PNG (6.7 KB)

Thanks & Regards,
Kiran G

@kirangali

We are checking it and will get back to you shortly.

Could you please update on this issue?

@kirangali

We tested using the below simple code snippet and noticed that the rotation property was not working. We tested using 22.6 version:

Document doc = new Document();
Page page = doc.Pages.Add();

CircleAnnotation circleAnnotation = new CircleAnnotation(page, GetRectangle(doc, 1032.6f, 222.004f, 370.32f, 185.16f, 1061.70f, 1642.55f, 1, page.Rotate)); // hardcoded values are captured using mouse coordinates

circleAnnotation.Rect.Rotate(25); // it is required and its not working
circleAnnotation.Characteristics.Rotate = Rotation.on90; // Its not working either
circleAnnotation.Color = Color.Red;

page.Annotations.Add(circleAnnotation);

doc.Save(dataDir + "ellipse.pdf");

Therefore, an issue as PDFNET-52106 has been logged in our issue tracking system. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We apologize for the inconvenience.

Thank you for your update. Maximum may i know how many days it will be take to resolve based on current serve basis?

@kirangali

Since, the issues are resolved on first come first serve basis in the free support model, the resolution time of the issue depends upon number of issues logged prior to it as well as its complexity and nature. Nevertheless, we will let you know once we are done with the investigation and have some news about its resolution ETA. Please spare us some time.

We are sorry for the inconvenience.