File tree 4 files changed +85
-0
lines changed
4 files changed +85
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,47 @@ class Catalog {
152
152
return shadow ( this , "metadata" , metadata ) ;
153
153
}
154
154
155
+ get markInfo ( ) {
156
+ let markInfo = null ;
157
+ try {
158
+ markInfo = this . _readMarkInfo ( ) ;
159
+ } catch ( ex ) {
160
+ if ( ex instanceof MissingDataException ) {
161
+ throw ex ;
162
+ }
163
+ warn ( "Unable to read mark info." ) ;
164
+ }
165
+ return shadow ( this , "markInfo" , markInfo ) ;
166
+ }
167
+
168
+ /**
169
+ * @private
170
+ */
171
+ _readMarkInfo ( ) {
172
+ const obj = this . _catDict . get ( "MarkInfo" ) ;
173
+ if ( ! isDict ( obj ) ) {
174
+ return null ;
175
+ }
176
+
177
+ const markInfo = Object . create ( {
178
+ Marked : false ,
179
+ UserProperties : false ,
180
+ Suspects : false ,
181
+ } ) ;
182
+ for ( const key in markInfo ) {
183
+ if ( ! obj . has ( key ) ) {
184
+ continue ;
185
+ }
186
+ const value = obj . get ( key ) ;
187
+ if ( ! isBool ( value ) ) {
188
+ continue ;
189
+ }
190
+ markInfo [ key ] = value ;
191
+ }
192
+
193
+ return markInfo ;
194
+ }
195
+
155
196
get toplevelPagesDict ( ) {
156
197
const pagesObj = this . _catDict . get ( "Pages" ) ;
157
198
if ( ! isDict ( pagesObj ) ) {
Original file line number Diff line number Diff line change @@ -499,6 +499,10 @@ class WorkerMessageHandler {
499
499
] ) ;
500
500
} ) ;
501
501
502
+ handler . on ( "GetMarkInfo" , function wphSetupGetMarkInfo ( data ) {
503
+ return pdfManager . ensureCatalog ( "markInfo" ) ;
504
+ } ) ;
505
+
502
506
handler . on ( "GetData" , function wphSetupGetData ( data ) {
503
507
pdfManager . requestLoadedStream ( ) ;
504
508
return pdfManager . onLoadedStream ( ) . then ( function ( stream ) {
Original file line number Diff line number Diff line change @@ -805,6 +805,24 @@ class PDFDocumentProxy {
805
805
return this . _transport . getMetadata ( ) ;
806
806
}
807
807
808
+ /**
809
+ * @typedef {Object } MarkInfo
810
+ * Properties correspond to Table 321 of the PDF 32000-1:2008 spec. Values
811
+ * are null if not defined by the PDF.
812
+ * @property {boolean } Marked
813
+ * @property {boolean } UserProperties
814
+ * @property {boolean } Suspects
815
+ */
816
+
817
+ /**
818
+ * @returns {Promise<MarkInfo | null> } A promise that is resolved with
819
+ * a {MarkInfo} object that contains the MarkInfo flags for the PDF
820
+ * document, or `null` when no MarkInfo values are present in the PDF file.
821
+ */
822
+ getMarkInfo ( ) {
823
+ return this . _transport . getMarkInfo ( ) ;
824
+ }
825
+
808
826
/**
809
827
* @returns {Promise<TypedArray> } A promise that is resolved with a
810
828
* {TypedArray} that has the raw data from the PDF.
@@ -2646,6 +2664,10 @@ class WorkerTransport {
2646
2664
} ) ;
2647
2665
}
2648
2666
2667
+ getMarkInfo ( ) {
2668
+ return this . messageHandler . sendWithPromise ( "GetMarkInfo" , null ) ;
2669
+ }
2670
+
2649
2671
getStats ( ) {
2650
2672
return this . messageHandler . sendWithPromise ( "GetStats" , null ) ;
2651
2673
}
Original file line number Diff line number Diff line change @@ -1192,6 +1192,24 @@ describe("api", function () {
1192
1192
. catch ( done . fail ) ;
1193
1193
} ) ;
1194
1194
1195
+ it ( "gets markInfo" , function ( done ) {
1196
+ const loadingTask = getDocument (
1197
+ buildGetDocumentParams ( "annotation-line.pdf" )
1198
+ ) ;
1199
+
1200
+ loadingTask . promise
1201
+ . then ( function ( pdfDoc ) {
1202
+ return pdfDoc . getMarkInfo ( ) ;
1203
+ } )
1204
+ . then ( function ( info ) {
1205
+ expect ( info . Marked ) . toEqual ( true ) ;
1206
+ expect ( info . UserProperties ) . toEqual ( false ) ;
1207
+ expect ( info . Suspects ) . toEqual ( false ) ;
1208
+ done ( ) ;
1209
+ } )
1210
+ . catch ( done . fail ) ;
1211
+ } ) ;
1212
+
1195
1213
it ( "gets data" , function ( done ) {
1196
1214
var promise = pdfDocument . getData ( ) ;
1197
1215
promise
You can’t perform that action at this time.
0 commit comments