@@ -3205,6 +3205,58 @@ describe("api", function () {
32053205 } ) ;
32063206 } ) ;
32073207 } ) ;
3208+
3209+ describe ( "Get annotations by their types in the document" , function ( ) {
3210+ it ( "gets editable annotations" , async function ( ) {
3211+ const loadingTask = getDocument (
3212+ buildGetDocumentParams ( "tracemonkey_with_editable_annotations.pdf" )
3213+ ) ;
3214+ const pdfDoc = await loadingTask . promise ;
3215+
3216+ // Get all the editable annotations in the document.
3217+ let editableAnnotations = (
3218+ await pdfDoc . getAnnotationsByType (
3219+ new Set ( [
3220+ AnnotationType . FREETEXT ,
3221+ AnnotationType . STAMP ,
3222+ AnnotationType . INK ,
3223+ AnnotationType . HIGHLIGHT ,
3224+ ] ) ,
3225+ null
3226+ )
3227+ ) . map ( annotation => ( {
3228+ id : annotation . id ,
3229+ subtype : annotation . subtype ,
3230+ pageIndex : annotation . pageIndex ,
3231+ } ) ) ;
3232+ editableAnnotations . sort ( ( a , b ) => a . id . localeCompare ( b . id ) ) ;
3233+ expect ( editableAnnotations ) . toEqual ( [
3234+ { id : "1000R" , subtype : "FreeText" , pageIndex : 12 } ,
3235+ { id : "1001R" , subtype : "Stamp" , pageIndex : 12 } ,
3236+ { id : "1011R" , subtype : "Stamp" , pageIndex : 13 } ,
3237+ { id : "997R" , subtype : "Ink" , pageIndex : 13 } ,
3238+ { id : "998R" , subtype : "Highlight" , pageIndex : 13 } ,
3239+ ] ) ;
3240+
3241+ // Get all the editable annotations but the ones on page 12.
3242+ editableAnnotations = (
3243+ await pdfDoc . getAnnotationsByType (
3244+ new Set ( [ AnnotationType . STAMP , AnnotationType . HIGHLIGHT ] ) ,
3245+ new Set ( [ 12 ] )
3246+ )
3247+ ) . map ( annotation => ( {
3248+ id : annotation . id ,
3249+ subtype : annotation . subtype ,
3250+ pageIndex : annotation . pageIndex ,
3251+ } ) ) ;
3252+ editableAnnotations . sort ( ( a , b ) => a . id . localeCompare ( b . id ) ) ;
3253+ expect ( editableAnnotations ) . toEqual ( [
3254+ { id : "1011R" , subtype : "Stamp" , pageIndex : 13 } ,
3255+ { id : "998R" , subtype : "Highlight" , pageIndex : 13 } ,
3256+ ] ) ;
3257+ await loadingTask . destroy ( ) ;
3258+ } ) ;
3259+ } ) ;
32083260 } ) ;
32093261
32103262 describe ( "Page" , function ( ) {
0 commit comments