File tree Expand file tree Collapse file tree
src/components/BootstrapBlazor.PdfReader Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -155,6 +155,9 @@ const loadPdf = async pdf => {
155155 pdfViewer . setDocument ( pdfDocument ) ;
156156
157157 pdfDocument . getMetadata ( ) . then ( metadata => {
158+ if ( metadata . contentLength === null ) {
159+ metadata . contentLength = options . data . length ;
160+ }
158161 loadMetadata ( el , pdfViewer , metadata ) ;
159162 } ) ;
160163
@@ -293,18 +296,24 @@ function parsePdfDate(pdfDateString) {
293296
294297const getFilesize = metadata => {
295298 const length = metadata . contentLength ;
299+ let val = 0 ;
300+ let unit = 'B' ;
296301 if ( length < 1024 ) {
297- return ` ${ Math . round ( length ) } B` ;
302+ val = length ;
298303 }
299304 else if ( length < 1024 * 1024 ) {
300- return `${ Math . round ( length / 1024 ) } KB` ;
305+ unit = 'KB' ;
306+ val = length / 1024 ;
301307 }
302308 else if ( length < 1024 * 1024 * 1024 ) {
303- return `${ length / 1024 / 1024 } MB` ;
309+ unit = 'MB' ;
310+ val = length / 1024 / 1024 ;
304311 }
305312 else if ( length < 1024 * 1024 * 1024 * 1024 ) {
306- return `${ length / 1024 / 1024 / 1024 } GB` ;
313+ unit = 'GB' ;
314+ val = length / 1024 / 1024 / 1024 ;
307315 }
316+ return `${ Math . round ( val * 100 ) / 100 } ${ unit } ` ;
308317}
309318
310319const setObserver = el => {
You can’t perform that action at this time.
0 commit comments