@@ -42,39 +42,36 @@ class PDFReference extends PDFAbstractReference {
4242 }
4343
4444 finalize ( ) {
45- return setTimeout ( ( ) => {
46- this . offset = this . document . _offset ;
45+ this . offset = this . document . _offset ;
4746
48- const encryptFn = this . document . _security ? this . document . _security . getEncryptFn ( this . id , this . gen ) : null ;
47+ const encryptFn = this . document . _security ? this . document . _security . getEncryptFn ( this . id , this . gen ) : null ;
4948
50- if ( this . buffer . length ) {
51- this . buffer = Buffer . concat ( this . buffer ) ;
52- if ( this . compress ) {
53- this . buffer = zlib . deflateSync ( this . buffer ) ;
54- }
55-
56- if ( encryptFn ) {
57- this . buffer = encryptFn ( this . buffer ) ;
58- }
49+ if ( this . buffer . length ) {
50+ this . buffer = Buffer . concat ( this . buffer ) ;
51+ if ( this . compress ) {
52+ this . buffer = zlib . deflateSync ( this . buffer ) ;
53+ }
5954
60- this . data . Length = this . buffer . length ;
55+ if ( encryptFn ) {
56+ this . buffer = encryptFn ( this . buffer ) ;
6157 }
6258
63- this . document . _write ( ` ${ this . id } ${ this . gen } obj` ) ;
64- this . document . _write ( PDFObject . convert ( this . data , encryptFn ) ) ;
59+ this . data . Length = this . buffer . length ;
60+ }
6561
66- if ( this . buffer . length ) {
67- this . document . _write ( 'stream' ) ;
68- this . document . _write ( this . buffer ) ;
62+ this . document . _write ( `${ this . id } ${ this . gen } obj` ) ;
63+ this . document . _write ( PDFObject . convert ( this . data , encryptFn ) ) ;
6964
70- this . buffer = [ ] ; // free up memory
71- this . document . _write ( '\nendstream ' ) ;
72- }
65+ if ( this . buffer . length ) {
66+ this . document . _write ( 'stream ' ) ;
67+ this . document . _write ( this . buffer ) ;
7368
74- this . document . _write ( 'endobj' ) ;
75- return this . document . _refEnd ( this ) ;
69+ this . buffer = [ ] ; // free up memory
70+ this . document . _write ( '\nendstream' ) ;
7671 }
77- , 0 ) ;
72+
73+ this . document . _write ( 'endobj' ) ;
74+ this . document . _refEnd ( this ) ;
7875 }
7976 toString ( ) {
8077 return `${ this . id } ${ this . gen } R` ;
0 commit comments