PDF Added annotations not visible

I want to add some annotation when the pdf is loaded:

public IActionResult Load([FromBody] Dictionary jsonObject)

{

PdfRenderer pdfviewer = new PdfRenderer(_cache);

MemoryStream stream = new MemoryStream();

object jsonResult = new object();

// create new document - for test

//var filestream = Task.Run(() => _fileStorageService.GetObjektPlanAsync("1", "c52ba361-e2a7-4f55-8d58-5e218a7caeb.pdf")).Result;

//PdfLoadedDocument lDoc = new PdfLoadedDocument(filestream);

            //PdfLoadedPage page = lDoc.Pages[0] as PdfLoadedPage;

PdfDocument lDoc = new PdfDocument();

PdfPage page = lDoc.Pages.Add();


RectangleF rectangle = new RectangleF(0, 0, 100, 100);

PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(rectangle, "http://www.google.com");


uriAnnotation.Text = "Uri Annotation";

uriAnnotation.Color = new PdfColor(Color.FromName("red"));

uriAnnotation.Border = new PdfAnnotationBorder(4, 0, 0);

uriAnnotation.InnerColor = new PdfColor(Color.Red);

page.Annotations.Add(uriAnnotation);


RectangleF rectangle2 = new RectangleF(0, 200, 100, 100);

PdfRubberStampAnnotation rubberStampAnnotation = new PdfRubberStampAnnotation(rectangle2, " Text Rubber Stamp Annotation");

rubberStampAnnotation.Icon = PdfRubberStampAnnotationIcon.Draft;

rubberStampAnnotation.Text = "Text Properties Rubber Stamp Annotation";

rubberStampAnnotation.Color = new PdfColor(Color.FromName("red"));

rubberStampAnnotation.Border = new PdfAnnotationBorder(10);

rubberStampAnnotation.InnerColor = new PdfColor(Color.Red);

page.Annotations.Add(rubberStampAnnotation);


PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(new RectangleF(0, 300, 100, 50));

freeText.MarkupText = "Free Text with Callout";

freeText.TextMarkupColor = new PdfColor(Color.Black);

freeText.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f);

freeText.Color = new PdfColor(Color.Yellow);

freeText.BorderColor = new PdfColor(Color.Red);

freeText.Border = new PdfAnnotationBorder(.5f);

freeText.LineEndingStyle = PdfLineEndingStyle.OpenArrow;

freeText.AnnotationFlags = PdfAnnotationFlags.Default;

freeText.Text = "Free Text";

freeText.Opacity = 1f;

page.Annotations.Add(freeText);


lDoc.Save(stream);

lDoc.Close(true);

stream.Position = 0;


jsonResult = pdfviewer.Load(stream, jsonObject);

return Content(JsonConvert.SerializeObject(jsonResult));

}


In the viewer i can see that there are annotations at the locations because i can select it - but they are not visible. I tried opacity but thats not working. Any ideas?


6 Replies

SK Shamini Kiruba Sobers Syncfusion Team October 26, 2021 02:34 PM UTC

Hi Bernhard, 

Greetings from Syncfusion support. 

We can reproduce the reported issues. But please find the details from the following table. 

Annotation Type 
Response 
Uri annotation 
For UriAnnotation, it does not have any appearance to visible in other viewers and we have also checked the behavior with Adobe Acrobat and it is the same as our library. We can’t proceed further on this, since this is the default behavior of Uri annotation. 
Rubber stamp annotation 
Sorry, we don’t have support to view rubber stamp annotation in PDF Viewer and there are no immediate plans to implement this. 
Free text annotation 
By enabling the appearance[Graphical representation] for the annotation by using the “SetAppearance” method as below, PDF Annotations will be preserved properly on saving the file. 

//Enable the appearance to free text annotation
freeText.SetAppearance(true); 

But still, there is an issue with loading in PDF Viewer. We do have support for free text annotation in PDF Viewer. So we will validate the reported issue and let you know the details on October 28th, 2021

Regards, 
Shamini 



SK Shamini Kiruba Sobers Syncfusion Team October 28, 2021 01:32 PM UTC

Hi Bernhard, 

We regret the delay. 

We are still analyzing the root cause of the issue and can provide the details by tomorrow (October 29th, 2021). 

Regards, 
Shamini 



SK Shamini Kiruba Sobers Syncfusion Team November 1, 2021 03:25 AM UTC

Hi Bernhard, 

We are very sorry for the inconvenience caused. We will update the validation details within today. 

Regards, 
Shamini 



SK Shamini Kiruba Sobers Syncfusion Team November 1, 2021 12:22 PM UTC

Hi Bernhard, 

In the Syncfusion PDF Viewer control we differentiate the signature annotation with the ink and free text annotation based on the author property. If author value and name value do not set for the free-text annotation then it will be considered as signature text. So we request you to add the Author and Name properties while saving the free-text annotation to resolve the issue. 
 
Code Snippet: 
 
// Specifies the author name 
freeText.Author = "Guest"; 
 
//Specifies the unique id for the annotation 
freeText.Name = "freetext1"; 
 
 

Also, please ensure if the below method exists in your PDFViewerController which is responsible for rendering the annotations. 

[AcceptVerbs("Post")]
[HttpPost]
[Route("api/[controller]/RenderAnnotationComments")]
public IActionResult RenderAnnotationComments([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object jsonResult = pdfviewer.GetAnnotationComments(jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}
 


Kindly let us know if the solution helps. 

Regards, 
Shamini 



BE Bernhard November 3, 2021 02:36 PM UTC

Hi Shamini!

RenderAnnotationComments exists.


I added 

freeText.Author = "Guest"; 
freeText.Name = "freetext1"; 

and now its working fine.

Thanks!

Regards,
Bernhard


DM Dhivyabharathi Mohan Syncfusion Team November 4, 2021 04:54 AM UTC

Hi Bernhard, 
 
Thanks for the update. We are glad that your issue has been resolved. 
 
Regards, 
Dhivya 


Loader.
Up arrow icon