File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -73,7 +73,9 @@ async function map(pdfFile, options = {}) {
7373
7474		// update the form with each input ID `key` filled as unique index `i` 
7575		log ( 'calling fillFormWithFlattenAsync' ,  pdfFile ) ; 
76- 		await  pdfDoc . fillForm ( template ,  filledFile ) ; 
76+ 		await  pdfDoc . fillForm ( template ) ; 
77+ 
78+ 		await  pdfDoc . save ( filledFile ,  false ) ; 
7779
7880		return  { 
7981			map : mapFile , 
Original file line number Diff line number Diff line change @@ -63,9 +63,18 @@ export default class PDF {
6363				try  { 
6464					field . setText ( filledTemplate [ key ] ) ; 
6565				}  catch  ( ex )  { 
66- 					if  ( `${ ex }  ` . indexOf ( ' must be of type `string`' )  >=  0 )  { 
66+ 					const  msg  =  `${ ex }  ` ; 
67+ 					if  ( msg . indexOf ( ' must be of type `string`' )  >=  0 )  { 
6768						// automatically convert numbers to strings 
6869						field . setText ( `${ filledTemplate [ key ] }  ` ) ; 
70+ 					}  else  if  ( msg . indexOf ( 'Attempted to set text with length=' ) )  { 
71+ 						// the field value is too big for the field. truncate. 
72+ 						// TODO: there should probably be two modes. when filling examples 
73+ 						// this can happen, but when filling for real, it should error. 
74+ 						const  matched  =  / m a x L e n g t h = ( \d + )   / . exec ( msg ) ; 
75+ 						const  limit  =  parseInt ( matched [ 1 ] ,  10 ) ; 
76+ 						const  value  =  `${ filledTemplate [ key ] }  ` ; 
77+ 						field . setText ( value . slice ( 0 ,  limit ) ) ; 
6978					}  else  { 
7079						throw  Error ( 
7180							`${ ex }  , form=${ this . name }   key=${ key }  , value="${ filledTemplate [ key ] }  "` ) ; 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments