title: Not able to read special character from pdf using node.js
body: <p>I have some pdf file which I need to upload in my system and read all the data properly and I have done that in node.js but I have one problem 1. Am not able to read special character which is present in pdf Below is the code and pdf</p>
  <pre><code>    var express = require('express');
  var app = express();
  var fs = require(&quot;fs&quot;);
  var util = require('util');
  reader = require('xlsx');
  const unlinkAsync = util.promisify(fs.unlink)
  pdf2excel = require('pdf-to-excel');
  var bodyParser = require('body-parser');
  var multer  = require('multer');
  
  app.use(express.static('public'));
  app.use(bodyParser.urlencoded({ extended: false }));
   
  const storage = multer.diskStorage({
      destination: (req, file, cb) =&gt; {
        cb(null, &quot;./tmp&quot;)
      },
      filename: (req, file, cb) =&gt; {
        cb(null, 'sample.pdf')
      },
    })
    
    const upload = multer({ storage: storage })
  
  app.get('/', function (req, res) {
      res.sendFile( __dirname + &quot;/&quot; + &quot;button.html&quot; );
   });
   app.get('/convert2excel', function (req, res) {
      res.sendFile( __dirname + &quot;/&quot; + &quot;convert.html&quot; );
   });
  
   app.get('/download', function(req, res){
      const file = `${__dirname}/final.xls`;
      res.download(file); // Set disposition and send it.
      
    });
  
   app.get('/convert', function (req, res) {
  
      var result = __dirname +&quot;/&quot;+'temp.xlsx';
      console.log(result);
  
      if (fs.existsSync(result)) {
          //file exists
          console.log('i am working'+result); 
      
       const file = reader.readFile(result); 
       let data = [] ; let dataRow = [];   var AqlArray = []; var dimnumArray = []; var SpecificationArray = [];   var MDeviceArray = []; 
       const sheets = file.SheetNames;
       var Family = '';
       var productnmber = '';
        var writeStream = fs.createWriteStream(&quot;final.xls&quot;);
       var header=&quot;Product  Family&quot;+&quot;\t&quot;+&quot; Part Number&quot;+&quot;\t&quot;+&quot;Dim No&quot;+&quot;\t&quot;+&quot;Specification&quot;+&quot;\t&quot;+&quot;Measuring device&quot;  +&quot;\t&quot;+&quot;Gage Id&quot;  +&quot;\t&quot;+&quot;Number Rejected&quot;  +&quot;\t&quot;+&quot;AQL&quot;+&quot;\n&quot;;
       for(let i = 0; i &lt; sheets.length; i++)
       {
          const temp = reader.utils.sheet_to_json(
               file.Sheets[file.SheetNames[i]])
          temp.forEach((res,i) =&gt; {
            console.log(i);
            // data[49] // productfamily
            // data[197] // part no;
      
            if(i==0){
              console.log('condition matched');
            }
      
            console.log(res);
      
             var dimno = ''; var row1 = '';
           
             if(i==53 || i==55 || i== 57|| i==59 || i==61 || i==63|| i==65|| i==68|| i== 70|| i== 72){
                dimno = temp[i].A;  
                dimnumArray.push(dimno);
             }  
             
            var specifi = '';
             if(i==99 || i==101 || i==103 || i== 109|| i==115|| i==75|| i==77|| i==79|| i==81|| i==84|| i==87){
              specifi = temp[i].A; 
      
              if(i==99)
              SpecificationArray[0] =specifi ;
              if(i==101)
              SpecificationArray[1] =specifi ;
              if(i==103)
              SpecificationArray[2] =specifi ;
      
              SpecificationArray[3] = '';
              SpecificationArray[4] = '';
              SpecificationArray[5] = '';
      
              if(i==109)
              SpecificationArray[6] =specifi ;
      
              SpecificationArray[7] = '';
              SpecificationArray[8] = '';
      
      
              if(i==115)
              SpecificationArray[9] =specifi ;
              if(i==75)
              SpecificationArray[10] =specifi ;
              if(i==77)
              SpecificationArray[11] =specifi ;
              if(i==79)
              SpecificationArray[12] =specifi ;
              if(i==81)
              SpecificationArray[13] =specifi ;
              if(i==84)
              SpecificationArray[14] =specifi ;
              if(i==87)
              SpecificationArray[15] =specifi ;
             }
      
             var aql = '';
             if(i==156 || i==158|| i==160 || i==162|| i==164 || i==166|| i==168|| i==171|| i==173 || i==175 || i==178 || i==180 || i== 182|| i==185 || i==188|| i==190|| i==195){
              aql = temp[i].A; 
              AqlArray.push(aql);
             }
      
           var mdevice = '';
             if(i==116 || i==118 || i==120|| i==122|| i==124|| i==126|| i==128|| i==129|| i==131|| i==133|| i==135|| i==136|| i==138|| i==140|| i==142|| i==144|| i==147|| i==150){
              
                  mdevice = temp[i].A; 
      
                  if(i==116)
                  MDeviceArray[0] =mdevice ;
                  if(i==118)
                  MDeviceArray[1] =mdevice ;
                  if(i==120)
                  MDeviceArray[2] =mdevice ;
                  if(i==122)
                  MDeviceArray[3] =mdevice ;
                  if(i==124)
                  MDeviceArray[4] =mdevice ;
                  if(i==126)
                  MDeviceArray[5] =mdevice ;
                  if(i==128)
                  MDeviceArray[6] = temp[128].A + temp[129].A;  ;
                  if(i==131)
                  MDeviceArray[7] =mdevice ;
                  if(i==133)
                  MDeviceArray[8] =mdevice ;
                  if(i==135)
                  MDeviceArray[9] = temp[135].A + temp[136].A;  ;
                  if(i==138)
                  MDeviceArray[10] =mdevice ;
                  if(i==140)
                  MDeviceArray[11] =mdevice ;
                  if(i==142)
                  MDeviceArray[12] =mdevice ;
                  if(i==144)
                  MDeviceArray[13] =mdevice ;
                  if(i==147)
                  MDeviceArray[14] =mdevice ;
                  if(i==150)
                  MDeviceArray[15] =mdevice ;
        
      
             }
      
      
      
               Family = temp[49].A;
               productnmber = temp[197].A;
             
             data.push(res); 
             
            // Dm// 53 , 55 , 57,59 , 61 , 63, 65,68, 70 , 72
            // specifi : 99 , 101,103, 109,115, 75 , 77,79,81,84,87
            //M Device 116 , 118 , 120 , 122 , 124 , 126 , 128.129 , 131, 133 , 135.136, 138,140 ,142,144,147,150
            // aql : 156 , 158, 160 , 162 , 164 , 166 , 168, 171, 173,175,178 , 180 , 182,185 , 188,190,195
          })
       }
       // console.log(data);
       
       // console.log(data[119]); // 51
      //  console.log(data[38]); // 40
      //  console.log(data[52]);  
       
      
      // console.log(MDeviceArray);
      // console.log(dimnumArray);
      // console.log(SpecificationArray);
      
      for(var i = 0 ; i&lt;MDeviceArray.length;i++){
      
       var dim = '';
       if(dimnumArray[i]){
           dim = dimnumArray[i];
       }
      
       var sip = '';
       if(SpecificationArray[i]){
         sip = SpecificationArray[i];
       }
      
       var aql ='';
       if(AqlArray[i]){
        aql = AqlArray[i];
      }
       
       row1 =  Family+&quot;\t&quot;+productnmber+&quot;\t&quot;+dim+&quot;\t&quot;+sip+&quot;\t&quot;+MDeviceArray[i]+&quot;\t&quot;+'-'+&quot;\t&quot;+'-'+&quot;\t&quot;+aql+&quot;\n&quot;;
       dataRow.push(row1);  
       
      }
      
      
      //  var row1 = &quot;0&quot;+&quot;\t&quot;+&quot; 21&quot;+&quot;\t&quot;+&quot;Rob&quot;+&quot;\n&quot;;
      //  var row2 = &quot;1&quot;+&quot;\t&quot;+&quot; 22&quot;+&quot;\t&quot;+&quot;bob&quot;+&quot;\n&quot;;
       
         writeStream.write(header);
         dataRow.forEach(function(element) 
      { 
        writeStream.write(element);
      });
        
      //  writeStream.write(row2); 
        writeStream.close();
      
        }
  
       res.json('done');
   });
  
   app.post('/file_upload',upload.single('pdf_file') ,async function (req, res) {
        console.log('req');
        console.log(req.file.path); 
   
      var file = __dirname +&quot;/&quot;+req.file.path;
  
      try {
          const options = {
            // when current pdf page number changes call this function(optional)
          // onProcess: (e) =&gt; console.warn(`${e.numPage} / ${e.numPages}`),
            // pdf start page number you want to convert (optional, default 1)
          // start: 1,
            // pdf end page number you want to convert (optional, default )
            //end: 2,
          }
          // input pdf and out put excel file 
          pdf2excel.genXlsx(file, 'temp.xlsx', options);
          res.redirect('/convert2excel');
            //resolve('bar.xlsx');
           // Delete the file like normal
          //  await unlinkAsync(file);
        } catch (err) {
          console.error(err);
        } 
  
   });
   
  var server = app.listen(8081, function () {
     var host = server.address().address
     var port = server.address().port
     
     console.log(&quot;Example app listening at http://%s:%s&quot;, host, port)
  })
  </code></pre>
  <p>[And here is the pdf image]<a href="https://i.stack.imgur.com/YkaOy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YkaOy.png" alt="enter image description here" /></a></p>
  <p>As you can see in pdf file, There is special character present that I am not able to read other than able to read properly. I am using pdftoexcel library-Will be very grateful if someone can help</p>