Hi,
I am executing the following code to add FreeTextAnnotation to PDF document using Aspose.PDF Cloud SDK for .NET 23.4.0 but its producing an exception message.
Exception message
System.IO.InvalidDataException: Rect is a required property for FreeTextAnnotation and cannot be null
at Aspose.Pdf.Cloud.Sdk.Model.FreeTextAnnotation…ctor(List1 Links, Color Color, String Contents, String Modified, String Id, List
1 Flags, String Name, Rectangle Rect, Nullable1 PageIndex, Nullable
1 ZIndex, HorizontalAlignment HorizontalAlignment, VerticalAlignment VerticalAlignment, String CreationDate, String Subject, String Title, String RichText, Justification Justification, FreeTextIntent Intent, Rotation Rotate, TextStyle TextStyle)
Code snippet
C# .NET
`PdfApi api = new PdfApi(clientSecret, clientID);
List annotations = new List
{
new FreeTextAnnotation()
{
Contents = “Confidential !”,
Color = new Aspose.Pdf.Cloud.Sdk.Model.Color(0, 0, 0, 0),
Modified = “03/05/2023 16:00:00.000 PM”,
Rotate = Rotation.On90,
Id = “id1”,
Name = “Test Free Text”,
Rect = new Rectangle(100, 800, 350, 830),
TextStyle = new TextStyle(FontSize: 26, Font: “Arial”, ForegroundColor: new Aspose.Pdf.Cloud.Sdk.Model.Color(0xFF, 0, 0xFF, 0), BackgroundColor: new Aspose.Pdf.Cloud.Sdk.Model.Color(0xFF, 0xFF, 0, 0)),
Flags = new List<AnnotationFlags> { AnnotationFlags.Default},
HorizontalAlignment = HorizontalAlignment.Center,
Intent = FreeTextIntent.FreeTextTypeWriter,
RichText = "Rich Text",
Subject = "Text Box Subj",
ZIndex = 1,
Justification = Justification.Center,
Title = "Title",
PageIndex = 1,
CreationDate = "03/05/2023 16:00:00.000 PM"
}
};
var response = api. PostPageFreeTextAnnotations(“Binder1.pdf”, 1, annotations);
`
Sample PDF used can be downloaded from this link.
However, please note that the API works fine when we access the API using SwaggerUI.