ts-pdf
ts-pdf copied to clipboard
How can i detect events ?
How can i detect the events that happend to the page ?
like i want to extract the annotations as a json.. is it possible ?
and how can i add images ?
Last thins.. thank you so much for this amazing job !
Hello. Thank you!
-
You can assign the handler to the annotChangeCallback field of the TsPdfViewerOptions object used for instantiating the viewer. It'll execute the handler with the AnnotEventDetail object each time the interaction with annotations happens. You can filter out the events you don't need to handle by checking the type field of the object. The object will also contain an array of the AnnotationDto objects having all the details about the annotation involved in the event.
-
You can call the exportAnnotationsToJsonAsync method of the viewer instance after you have your file opened in it to get all the annotations as JSON. With the current implementation, it'll export only the annotations, added using TsPdf during the current session (not the ones loaded from the file). I did not expose the option to export all the supported annotations including the ones that are already stored in the PDF file, as I'm not sure about how useful it can be. Just in case, to do the opposite (import), you can call the importAnnotationsFromJsonAsync method.
-
Embedded images are a part of the main PDF file content and its layout, same as text. They are not considered to be annotations according to the PDF specification. Therefore, they are outside of the scope of this module. However, if you just want to add some images on top of the existing content, you can use a custom stamp for that. It's available from the UI in the context menu when adding the stamp annotation.