File tree 1 file changed +14
-4
lines changed
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -243,10 +243,21 @@ function getDocument(src) {
243
243
} else if ( key === "worker" ) {
244
244
worker = source [ key ] ;
245
245
continue ;
246
- } else if ( key === "data" && ! ( source [ key ] instanceof Uint8Array ) ) {
246
+ } else if ( key === "data" ) {
247
247
// Converting string or array-like data to Uint8Array.
248
248
const pdfBytes = source [ key ] ;
249
- if ( typeof pdfBytes === "string" ) {
249
+ if (
250
+ typeof PDFJSDev !== "undefined" &&
251
+ PDFJSDev . test ( "GENERIC" ) &&
252
+ isNodeJS &&
253
+ typeof Buffer !== "undefined" && // eslint-disable-line no-undef
254
+ pdfBytes instanceof Buffer // eslint-disable-line no-undef
255
+ ) {
256
+ params [ key ] = new Uint8Array ( pdfBytes ) ;
257
+ } else if ( pdfBytes instanceof Uint8Array ) {
258
+ // Use the data as-is when it's already a Uint8Array.
259
+ params [ key ] = pdfBytes ;
260
+ } else if ( typeof pdfBytes === "string" ) {
250
261
params [ key ] = stringToBytes ( pdfBytes ) ;
251
262
} else if (
252
263
typeof pdfBytes === "object" &&
@@ -259,8 +270,7 @@ function getDocument(src) {
259
270
} else {
260
271
throw new Error (
261
272
"Invalid PDF binary data: either typed array, " +
262
- "string or array-like object is expected in the " +
263
- "data property."
273
+ "string, or array-like object is expected in the data property."
264
274
) ;
265
275
}
266
276
continue ;
You can’t perform that action at this time.
0 commit comments