I want to add some annotation when the pdf is loaded:
public IActionResult Load([FromBody] Dictionary
{
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?
|
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.
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. |
|
// Specifies the author name
freeText.Author = "Guest";
//Specifies the unique id for the annotation
freeText.Name = "freetext1";
|
|
[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)); } |
Hi Shamini!
RenderAnnotationComments exists.
I added