Convert PDF to Excel in Node.js

Creating spreadsheets from PDF using Node.js

Aspose.PDF for Node.js via C++ support the feature of converting PDF files to Excel file.

Convert PDF to XLSX

In case you want to convert PDF document, you can use AsposePdfToXlsX function. Please check the following code snippet in order to convert in Node.js environment.

CommonJS:

  1. Call require and import asposepdfnodejs module as AsposePdf variable.
  2. Specify the name of the PDF file that will be converted.
  3. Call AsposePdf as Promise and perform the operation for converting file. Receive the object if successful.
  4. Call the function AsposePdfToXlsX.
  5. Convert PDF file. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultPDFtoXlsX.xlsx”. If the json.errorCode parameter is not 0 and, accordingly, an error appears in your file, the error information will be contained in ‘json.errorText’.

  const AsposePdf = require('asposepdfnodejs');
  const pdf_file = 'Aspose.pdf';
  AsposePdf().then(AsposePdfModule => {
      /*Convert a PDF-file to XlsX and save the "ResultPDFtoXlsX.xlsx"*/
      const json = AsposePdfModule.AsposePdfToXlsX(pdf_file, "ResultPDFtoXlsX.xlsx");
      console.log("AsposePdfToXlsX => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);
  });

ECMAScript/ES6:

  1. Import the asposepdfnodejs module.
  2. Specify the name of the PDF file that will be converted.
  3. Initialize the AsposePdf module. Receive the object if successful.
  4. Call the function AsposePdfToXlsX.
  5. Convert PDF file. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultPDFtoXlsX.xlsx”. If the json.errorCode parameter is not 0 and, accordingly, an error appears in your file, the error information will be contained in ‘json.errorText’.

  import AsposePdf from 'asposepdfnodejs';
  const AsposePdfModule = await AsposePdf();
  const pdf_file = 'Aspose.pdf';
  /*Convert a PDF-file to XlsX and save the "ResultPDFtoXlsX.xlsx"*/
  const json = AsposePdfModule.AsposePdfToXlsX(pdf_file, "ResultPDFtoXlsX.xlsx");
  console.log("AsposePdfToXlsX => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);