Annotation bug

Hello,

I’m facing the following issues with FreeTextAnnotation to a pdf document on ASPOSE for PDF C#:
- when I try to open the pdf, the annotation is not visible from the beginning, but it appears only if I move, or enlarge or change text
- the functionality “ReadOnly” does not exist, so for anyone is possible modify the the text and the commets
- automatically get the size of the text, so it will be easily possible to auto-size the rectangle of the annotation textbox

Thank you
Luca

Here below the code I used:
//open document
Document pdfDocument = new Document(dataDir + SetFreeTextAnnotationFormatting.pdf);
// instantiate DefaultAppearance object
Aspose.Pdf.InteractiveFeatures.DefaultAppearance default_appearance = new DefaultAppearance(Arial, 28, System.Drawing.Color.Red);
//create annotation
FreeTextAnnotation freetext = new FreeTextAnnotation(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(200, 400, 400, 600), default_appearance);
// specify the contents of annotation
freetext.Contents = Free Text;
// add anootation to annotations collection of page
pdfDocument.Pages[1].Annotations.Add(freetext);
// save the updated document
pdfDocument.Save(dataDir + SetFreeTextAnnotationFormatting_out.pdf);
luca.guarnaccia:
I'm facing the following issues with FreeTextAnnotation to a pdf document on ASPOSE for PDF C#:
- when I try to open the pdf, the annotation is not visible from the beginning, but it appears only if I move, or enlarge or change text
Hi Luca,

Thanks for contacting support. I have tested the scenario using Aspose.Pdf for .NET 10.8.0 and I am unable to notice any issue. The TextAnnotation is properly visible. For your reference, I have also attached the PDF file generated over my end.

[C#]

Document pdfDocument = new Document();

pdfDocument.Pages.Add();

// instantiate DefaultAppearance object

Aspose.Pdf.InteractiveFeatures.DefaultAppearance default_appearance = new DefaultAppearance("Arial", 28, System.Drawing.Color.Red);

//create annotation

FreeTextAnnotation freetext = new FreeTextAnnotation(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(200, 400, 400, 600), default_appearance);

// specify the contents of annotation

freetext.Contents = "Free Text";

// add anootation to annotations collection of page

pdfDocument.Pages[1].Annotations.Add(freetext);

// save the updated document

pdfDocument.Save(“c:/pdftest/SetFreeTextAnnotationFormatting_out.pdf”);

Hi Luca,


Thanks for your inquiry. Please check following code snippet to add FreeAnnotation to show up without editing it. Moreover, please note by default it is editable. To restrict FreeAnnotation editing you need to set security privileges of the the document as following.

Aspose.Pdf.Document
pdfDocument = new Aspose.Pdf.Document(myDir + “HelloWorld.pdf”);<o:p></o:p>

// instantiate DefaultAppearance object

Aspose.Pdf.InteractiveFeatures.DefaultAppearance default_appearance = new DefaultAppearance("Arial", 12, System.Drawing.Color.Red);

FreeTextAnnotation freetext = new FreeTextAnnotation(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(100, 650, 294, 700), default_appearance);

Aspose.Pdf.InteractiveFeatures.Annotations.Border border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(freetext);

border.Style = Aspose.Pdf.InteractiveFeatures.Annotations.BorderStyle.Solid;

border.Width = 2;

//border.Style = Aspose.Pdf.InteractiveFeatures.Annotations.BorderStyle.Dashed;

border.EffectIntensity = 2;

freetext.Opacity = 10f;

freetext.Characteristics.Border = System.Drawing.Color.Black;

freetext.Border = border;

freetext.Contents = "Free Text";

//freetext.Flags = AnnotationFlags.Print | AnnotationFlags.NoView;

// add anootation to annotations collection of page

pdfDocument.Pages[1].Annotations.Add(freetext);

//pdfDocument.Save(myDir + "FreeTextAnnotation.pdf");

//Settting document privileges

DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;

privilege.ChangeAllowLevel = 0;

privilege.AllowPrint = true;

PdfFileSecurity fileSecurity = new PdfFileSecurity();

fileSecurity.BindPdf(pdfDocument);

//set document privileges

fileSecurity.SetPrivilege(privilege);

// save final output file

fileSecurity.Save(myDir+"FreeTextAnnotation_Secured.pdf");

fileSecurity.Close();

fileSecurity.Dispose();

pdfDocument.Dispose();

Please feel free to contact us for any further assistance.


Best Regards,

luca.guarnaccia:
- the functionality "ReadOnly" does not exist, so for anyone is possible modify the the text and the commets
Hi Luca,

In order to accomplish above stated requirement, you may consider setting Document access privileges over PDF file. Therefore when viewing the document with user password, you cannot modify the annotation. However when viewing the file with Owner password, you can modify the annotation.

[C#]

Document pdfDocument = new Document();

pdfDocument.Pages.Add();

// instantiate DefaultAppearance object

Aspose.Pdf.InteractiveFeatures.DefaultAppearance default_appearance = new DefaultAppearance("Arial", 28, System.Drawing.Color.Red);

//create annotation

FreeTextAnnotation freetext = new FreeTextAnnotation(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(200, 400, 400, 600), default_appearance);

// specify the contents of annotation

freetext.Contents = "Free Text";

// add anootation to annotations collection of page

pdfDocument.Pages[1].Annotations.Add(freetext);

// Instantiate Document Privileges object

// Apply restrictions on all privileges

DocumentPrivilege documentPrivilege = DocumentPrivilege.ForbidAll;

// Only allow screen reading

documentPrivilege.AllowModifyAnnotations = false;

// Encrypt the file with User and Owner password.

// Need to set the password, so that once the user views the file with user password,

// only screen reading option is enabled

pdfDocument.Encrypt("user", "owner", documentPrivilege, CryptoAlgorithm.AESx128, false);

// save the updated document

pdfDocument.Save(“c:/pdftest/SetFreeTextAnnotationFormatting_out.pdf”);

Hi Tilal,

I copied and pasted your code and I got the same result of yesterday.
It seems NOT working.

I’m using the free trial, because my company is asking for a tool that must do this annotation, but if I’m not sure it works I cannot say them to buy Aspose.

THank you
Luca
Hi Luca,

luca.guarnaccia:
Hi Tilal,
I copied and pasted your code and I got the same result of yesterday.
It seems NOT working.

I'm using the free trial, because my company is asking for a tool that must do this annotation, but if I'm not sure it works I cannot say them to buy Aspose.

THank you
Luca

Thanks for your feedback. It seems you are getting issue due to evaluation limitation. Please make a 30 days temporary license and implement it, it will resolve the issue. Please find attached the sample output, hopefully it fulfills your requirements.

Best Regards,

ok thank you,

could you please post the link where I can find it?

Luca

Hi Luca,


I am sorry for the missing link. I have updated above post, please proceed.

Best Regards,