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