We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to apply zoom factor to rectangle annotations in pdf?

Hi Team,
I am unable to apply zoom factor to rectangle annotation while generating pdf.
Please find attached input annotations by raphel.min.js (shape-ediotr.js) input.png (119.4 KB)
and output pdf file by aspose output.pdf (266.5 KB)

Please find below code to generate annotation by aspose .pdf

    public void DrawAnnotationsonPDFAspose(List<ShapesEditorProp> shapesEditorProps, List<ShapesEditorProp> initialShapes, string filename, string filePath,string UserName)
    {

        initialShapes.ForEach(s =>
        {
            if (!shapesEditorProps.Any(sd => sd.id == s.id))
            {
                shapesEditorProps.Add(s);
            }
        });

       
        string path = Path.Combine(filePath);
        Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
        filename = Path.GetFileName(path);
     
        shapesEditorProps.ForEach(s =>
        {
            int? type = s.type == "Rectangle" ? 1 : s.type == "Ellipse" ? 2 : s.type == "Arrow" ? 3 : s.type == "Line" ? 4 : s.type == "TextAnnotation" ? 5 : 0;

            decimal? height = type == 1 ? s.height : type == 2 ? s.radiusY : (type == 3 || type == 4) ? s.y2 : s.height;
            decimal? width = type == 1 ? s.width : type == 2 ? s.radiusX : (type == 3 || type == 4) ? s.x2 : s.width;
            decimal? xValue = (type == 3 || type == 4) ? s.x1 : s.x;
            decimal? yValue = (type == 3 || type == 4) ? s.y1 : s.y;
            decimal? CHeight = s.CHeight ?? 0;
            decimal? CWidth = s.CWidth ?? 0;

            string tb = HTMLToText(WebUtility.HtmlDecode(s.annoateComment));
            switch (type)
            {
                case 1: //Rectangle
                    var pageRectangle = document.Pages[s.pageNumber ?? 0];
                    //var rectRectangle = new Rectangle((double)xValue, (double)yValue, (double)(width - xValue), (double)(height - yValue));
                    var rectRectangle = GetRectangle(document, (float)xValue, (float)yValue, (float)(width), (float)(height), (float)CHeight, (float)CWidth, s.pageNumber ?? 0, pageRectangle.Rotate);
                    var rectAnnotate = new SquareAnnotation(pageRectangle, rectRectangle)
                    {
                        Title = s.createdByName + "-" + "PD" + ":" + Convert.ToDateTime(s.createdOn).ToString("dd-MMM-yyyy HH:mm"),
                        Color = Aspose.Pdf.Color.Red,
                        InteriorColor = Aspose.Pdf.Color.MistyRose,
                        Contents = tb.ToString(),
                        Opacity = 0.5,
                        Popup = new PopupAnnotation(pageRectangle, rectRectangle)
                    };

                    Border border = new Border(rectAnnotate);
                    border.Width = Convert.ToInt32(s.strokeWidth??2); ;
                    rectAnnotate.Border = border;
                    rectAnnotate.Color = Aspose.Pdf.Color.Parse(s.strokeColor);
                    pageRectangle.Annotations.Add(rectAnnotate);

                    break;
      
                case 6: //Scale

                    break;
            }
        });
        document.Save(path);
       // PdfPageEditor editor = new PdfPageEditor();
        //editor.BindPdf(document);
        //editor.Zoom = 0.5f;
    }

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;
        double y = LLY;
        double h = (shapeX + shapeW) * xx;
        double w = (LLY - (shapeH * yy));

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

Thanks,
Lavanya

@Lavanya_Jujjavarapu

Can you please explain a bit more about your requirements? What do you actually mean by applying zoom? Do you want to zoom-in the text around which you are drawing annotations? Please share input PDF along with expected output PDF document that you want to obtain using the API. Also, please share the information about complete use case so that we can further proceed to assist you accordingly.

@asad.ali
Input -> 1) empty pdf file(without annotations) , list of rectangle coordinates (based on these coordinates we need to bind on pdf file) and zoom size of pdf file
output -> generate pdf file with annotations(rectangles) with input rectangle coordinates from input pdf file and apply zoom fraction to output pdf file…

Example: Please find comments in this input input.png (45.7 KB)

Note: We need to zoom annotations along with pdf file… After applying zoom fraction annotations must be aligned properly.

@Lavanya_Jujjavarapu

Your particular requirements need further investigation. We have logged an enhancement request as PDFNET-50850 in our issue tracking system for the sake. We will look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.