{"id":21960356,"url":"https://github.com/adrienjoly/npm-pdfreader-example","last_synced_at":"2025-10-05T17:05:47.585Z","repository":{"id":141957766,"uuid":"85483442","full_name":"adrienjoly/npm-pdfreader-example","owner":"adrienjoly","description":"Example of use of pdfreader: parse a PDF résumé","archived":false,"fork":false,"pushed_at":"2022-05-01T09:49:03.000Z","size":916,"stargazers_count":16,"open_issues_count":1,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-30T15:32:04.974Z","etag":null,"topics":["example","pdf-parsing"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/pdfreader","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adrienjoly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-19T14:43:26.000Z","updated_at":"2025-03-01T06:39:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"d0424686-a5f5-4d45-9b0d-c7ea7cc6df2a","html_url":"https://github.com/adrienjoly/npm-pdfreader-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/adrienjoly/npm-pdfreader-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrienjoly%2Fnpm-pdfreader-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrienjoly%2Fnpm-pdfreader-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrienjoly%2Fnpm-pdfreader-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrienjoly%2Fnpm-pdfreader-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adrienjoly","download_url":"https://codeload.github.com/adrienjoly/npm-pdfreader-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrienjoly%2Fnpm-pdfreader-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278486308,"owners_count":25994945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example","pdf-parsing"],"created_at":"2024-11-29T09:58:25.253Z","updated_at":"2025-10-05T17:05:47.580Z","avatar_url":"https://github.com/adrienjoly.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Examples of use of [pdfreader](https://github.com/adrienjoly/npm-pdfreader)\n\n## How to install and run\n\n```sh\ngit clone https://github.com/adrienjoly/npm-pdfreader-example.git\ncd npm-pdfreader-example\nnpm install\nnode parseItems.js\n```\n\n## 1. Parsing lines of text\n\n![example cv resume parse convert pdf to text](parseRows.png)\n\nHere is the code required to convert this PDF file into text:\n\n```js\nvar pdfreader = require('pdfreader');\n\nvar rows = {}; // indexed by y-position\n\nfunction printRows() {\n  Object.keys(rows) // =\u003e array of y-positions (type: float)\n    .sort((y1, y2) =\u003e parseFloat(y1) - parseFloat(y2)) // sort float positions\n    .forEach((y) =\u003e console.log((rows[y] || []).join('')));\n}\n\nnew pdfreader.PdfReader().parseFileItems('CV_ErhanYasar.pdf', function(err, item){\n  if (!item || item.page) {\n    // end of file, or page\n    printRows();\n    console.log('PAGE:', item.page);\n    rows = {}; // clear rows for next page\n  }\n  else if (item.text) {\n    // accumulate text items into rows object, per line\n    (rows[item.y] = rows[item.y] || []).push(item.text);\n  }\n});\n```\n\n## 2. Parsing a table\n\n![example cv resume parse convert pdf table to text](parseTable.png)\n\nHere is the code required to convert this PDF file into a textual table:\n\n```js\nvar pdfreader = require('pdfreader');\n\nconst nbCols = 2;\nconst cellPadding = 40; // each cell is padded to fit 40 characters\nconst columnQuantitizer = (item) =\u003e parseFloat(item.x) \u003e= 20;\n\nconst padColumns = (array, nb) =\u003e\n  Array.apply(null, {length: nb}).map((val, i) =\u003e array[i] || []);\n  // .. because map() skips undefined elements\n\nconst mergeCells = (cells) =\u003e (cells || [])\n  .map((cell) =\u003e cell.text).join('') // merge cells\n  .substr(0, cellPadding).padEnd(cellPadding, ' '); // padding\n\nconst renderMatrix = (matrix) =\u003e (matrix || [])\n  .map((row, y) =\u003e padColumns(row, nbCols)\n    .map(mergeCells)\n    .join(' | ')\n  ).join('\\n');\n\nvar table = new pdfreader.TableParser();\n\nnew pdfreader.PdfReader().parseFileItems(filename, function(err, item){\n  if (!item || item.page) {\n    // end of file, or page\n    console.log(renderMatrix(table.getMatrix()));\n    console.log('PAGE:', item.page);\n    table = new pdfreader.TableParser(); // new/clear table for next page\n  } else if (item.text) {\n    // accumulate text items into rows object, per line\n    table.processItem(item, columnQuantitizer(item));\n  }\n});\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrienjoly%2Fnpm-pdfreader-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadrienjoly%2Fnpm-pdfreader-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrienjoly%2Fnpm-pdfreader-example/lists"}