{"id":23757555,"url":"https://github.com/scientanl/pdf-extractor","last_synced_at":"2025-10-14T15:13:13.366Z","repository":{"id":27096367,"uuid":"112467252","full_name":"ScientaNL/pdf-extractor","owner":"ScientaNL","description":"Node.js module for rendering pdf pages to images, svgs, html files, text files and json metadata","archived":false,"fork":false,"pushed_at":"2023-05-16T08:41:05.000Z","size":4406,"stargazers_count":100,"open_issues_count":2,"forks_count":22,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-09-19T21:58:02.163Z","etag":null,"topics":["html-generation","image-generation","nodejs","pdf-parsing","pdfjs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ScientaNL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2017-11-29T11:29:38.000Z","updated_at":"2025-06-05T21:20:39.000Z","dependencies_parsed_at":"2024-06-19T22:51:16.144Z","dependency_job_id":"a60188cd-0989-44bf-bc0d-ca95f8c15930","html_url":"https://github.com/ScientaNL/pdf-extractor","commit_stats":null,"previous_names":["syslogicnl/pdf-extractor"],"tags_count":31,"template":false,"template_full_name":null,"purl":"pkg:github/ScientaNL/pdf-extractor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScientaNL%2Fpdf-extractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScientaNL%2Fpdf-extractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScientaNL%2Fpdf-extractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScientaNL%2Fpdf-extractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScientaNL","download_url":"https://codeload.github.com/ScientaNL/pdf-extractor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScientaNL%2Fpdf-extractor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019302,"owners_count":26086709,"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-14T02:00:06.444Z","response_time":60,"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":["html-generation","image-generation","nodejs","pdf-parsing","pdfjs"],"created_at":"2024-12-31T19:48:48.731Z","updated_at":"2025-10-14T15:13:13.341Z","avatar_url":"https://github.com/ScientaNL.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pdf-extractor\n\nPdf-extractor is a wrapper around [pdf.js](https://github.com/mozilla/pdf.js) to generate \nimages, svgs, html files, text files and json files from a pdf on node.js.\n\n- Image: A DOM Canvas is used to render and export the graphical layer of the pdf.\n    Canvas exports *.png as a default but can be extended to export to other file types like *.jpg.\n- SVG: Pdf objects are converted to svg using the\n    [SVGGraphics parser](https://github.com/mozilla/pdf.js/blob/master/src/display/svg.js) of pdf.js.\n- HTML: Pdf text is converted to HTML. This can be used as a (transparent) layer over the image\n    to enable text selection.\n- Text: Pdf text is extracted to a text file for different usages (e.g. indexing the text).\n\n## PDF.js on Node.js\nThis library is in it's most basic form a node.js wrapper for pdf.js.\nIt has default renderers to generate a default output, but is easily extended to incorporate custom logic or\nto generate different output. It uses a node.js DOM and the node domstub from pdf.js do make pdf parsing \navailable on node.js without a browser.\n\n## Box View / Crocodoc\nThis project is inspired by the Box View / Crocodoc way of converting documents (with this tool pdfs) \nto web-assets: images and html. The generated files match the files of Box View. \nThis makes this library an option to transition from the Box View API to an open-source solution.\n\n## Examples\nThis library can be used as-is to generate assets from a pdf. The only requirements are a pdf as input and \na writable directory as output. The extractor can also be used for rendering in different ways.\nThe renderers can be extended or new ones can be injected into the extractor to render a pdf in new ways.\n\n### Extractor\nHow to use the default extractor to render png, html and text files for pdf pages:\n\n```javascript\nconst PdfExtractor = require('pdf-extractor').PdfExtractor;\n\nlet outputDir = '/path/to/output',\n\npdfExtractor = new PdfExtractor(outputDir, {\n    viewportScale: (width, height) =\u003e {\n        //dynamic zoom based on rendering a page to a fixed page size \n        if (width \u003e height) {\n            //landscape: 1100px wide\n            return 1100 / width;\n        }\n        //portrait: 800px wide\n        return 800 / width;\n    },\n    pageRange: [1,5],\n});\n\npdfExtractor.parse('/path/to/dummy.pdf').then(function () {\n\tconsole.log('# End of Document');\n}).catch(function (err) {\n\tconsole.error('Error: ' + err);\n});\n```\n\nThis results in these generated files:\n```\ninfo.json\npage-1.png\npage-2.png\npage-3.png\npage-4.png\npage-5.png\nstylesheet.css\ntext-1.html\ntext-1.txt\ntext-2.html\ntext-2.txt\ntext-3.html\ntext-3.txt\ntext-4.html\ntext-4.txt\ntext-5.html\ntext-5.txt\n```\n\n### Using a custom renderer\nIt is relatively easy to extend or create new renderers/writers.\nBelow an example to use the Canvas capability for *.jpg file generation.\n\n```javascript\nconst PdfExtractor = require('pdf-extractor').PdfExtractor;\nconst CanvasRenderer = require('pdf-extractor').CanvasRenderer;\nconst SvgRenderer = require('pdf-extractor').SvgRenderer;\nconst FileWriter = require('pdf-extractor').FileWriter;\n\nclass JPGWriter extends FileWriter\n{\n\tgetFilePathForPage(page) {\n\t\treturn super.getPagePath(page.pageNumber, 'png');\n\t}\n\n\twriteCanvasPage(page, viewport, canvas) {\n\t\treturn this.writeStreamToFile(canvas.jpgStream(), this.getFilePathForPage(page))\n\t}\n}\n\nclass JPGCanvasRenderer extends CanvasRenderer\n{\n\tgetWriters(writerOptions) {\n\t\tlet writers = super.getWriters(writerOptions);\n\t\twriters.push(new JPGWriter(this.outputDir, writerOptions));\n\t\treturn writers;\n\t}\n}\n\nlet outputDir = '/path/to/output',\n\npdfExtractor = new PdfExtractor(outputDir, {\n\trenderers: [\n\t\tnew JPGCanvasRenderer(outputDir, rendererOptions),\n\t\tnew SvgRenderer(outputDir, rendererOptions)\n\t]\n});\n\npdfExtractor.parse('/path/to/dummy.pdf').then(function () {\n\tconsole.log('# End of Document');\n}).catch(function (err) {\n\tconsole.error('Error: ' + err);\n});\n```\n\nThis adds jpg images to the generated files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscientanl%2Fpdf-extractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscientanl%2Fpdf-extractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscientanl%2Fpdf-extractor/lists"}