{"id":24532555,"url":"https://github.com/andytango/mupdf-js","last_synced_at":"2025-04-05T08:09:49.778Z","repository":{"id":37753992,"uuid":"278898777","full_name":"andytango/mupdf-js","owner":"andytango","description":"📰 Yet another Webassembly PDF renderer for node and the browser ","archived":false,"fork":false,"pushed_at":"2024-06-28T05:47:34.000Z","size":7226,"stargazers_count":189,"open_issues_count":22,"forks_count":21,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T19:48:05.820Z","etag":null,"topics":["mupdf","pdf","pdf-converter","pdf-viewer","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://andytango.github.io/mupdf-js-demo/index.html","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andytango.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2020-07-11T16:23:56.000Z","updated_at":"2025-03-10T14:51:15.000Z","dependencies_parsed_at":"2024-06-18T21:23:07.555Z","dependency_job_id":"fdc5a396-95d5-472e-aefa-eef1ee6f6042","html_url":"https://github.com/andytango/mupdf-js","commit_stats":{"total_commits":69,"total_committers":5,"mean_commits":13.8,"dds":"0.37681159420289856","last_synced_commit":"ab338f62fb315eb92710f9c9cc77b2b0a7bc9216"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andytango%2Fmupdf-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andytango%2Fmupdf-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andytango%2Fmupdf-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andytango%2Fmupdf-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andytango","download_url":"https://codeload.github.com/andytango/mupdf-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305935,"owners_count":20917208,"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","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":["mupdf","pdf","pdf-converter","pdf-viewer","wasm","webassembly"],"created_at":"2025-01-22T10:17:13.573Z","updated_at":"2025-04-05T08:09:49.757Z","avatar_url":"https://github.com/andytango.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📰 MuPDF.js \n\n\u003e ## 📢 **IMPORTANT NOTE**\n\u003e \n\u003e __There is now an official package supported by the MuPDF developers, \n\u003e which is likely to be more up-to-date and better maintained.__ \n\u003e \n\u003e 👉 __[You can find it here](https://www.npmjs.com/package/mupdf).__ \n\u003e \n\u003e __I recommend migrating to the official package, as I am no longer \n\u003e maintaining this one due to time constraints.__\n\u003e \n\u003e To nudge you in the right direction, I've pushed a major version of this \n\u003e package that is a stub and will throw an error if you try to use it.\n\u003e \n\u003e If you *really* want to use this package, (or if you need it to run legacy \n\u003e code that depends on it, and you can't update that code for some reason) \n\u003e you can still install it by manually installing version 1.1.1.\n\n\n[![npm](https://img.shields.io/npm/v/mupdf-js)](https://www.npmjs.com/package/mupdf-js)\n[![npm](https://img.shields.io/npm/dt/mupdf-js)](https://www.npmjs.com/package/mupdf-js)\n[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/andrew-t/mupdf-js/Node.js%20CI)]\n\nThis is a port of [MuPDF](https://mupdf.com/docs/) to javascript and webassembly, giving you the following:\n\n- 🔥 **Blazing fast** rendering of PDFs to **PNG**, **SVG** and even **HTML**\n- 💼 Run in the **web browser** or your **server**. Basically any platform that supports Webassembly!\n- ☑ Supports Typescript\n- 🗺️ A super **simple** API that's also **completely flexible**, see below...\n\n# 🏁 Getting Started\n\n```bash\nyarn add mupdf-js\n# or\nnpm i mupdf-js\n```\n\n## Basic Usage\n\nBefore you do any processing, you'll need to initialise the MuPdf library:\n\n```js\nimport { createMuPdf } from \"mupdf-js\";\n\nasync function handleSomePdf(file: File) {\n  const mupdf = await createMuPdf();\n  \n  //...\n}\n```\n\nIn the *browser*, you'll most likely retrieve a [File](https://developer.mozilla.org/en-US/docs/Web/API/File) or [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object from an html [`\u003cinput type=\"file\"\u003e`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file) tag, supplied by a user.\n\nYou'll need to convert the file firstly to an `ArrayBuffer`, then to a `Uint8Array`:\n\n```js\nimport { createMuPdf } from \"mupdf-js\";\n\nasync function handleSomePdf(file) {\n  const mupdf = await createMuPdf();\n  const buf = await file.arrayBuffer();\n  const arrayBuf = new Uint8Array(buf);\n  \n  //...\n}\n```\n\nOnce you have this, you can *load* the file into the MuPdf environment, creating a MuPdf *document*:\n\n```js\nimport { createMuPdf } from \"mupdf-js\";\n\nasync function handleSomePdf(file) {\n  const mupdf = await createMuPdf();\n  const buf = await file.arrayBuffer();\n  const arrayBuf = new Uint8Array(buf);\n  const doc = mupdf.load(arrayBuf);\n}\n```\n\nYou now have three different options to render the PDF document:\n\n```js\nimport { createMuPdf } from \"mupdf-js\";\n\nasync function handleSomePdf(file) {\n  const mupdf = await createMuPdf();\n  const buf = await file.arrayBuffer();\n  const arrayBuf = new Uint8Array(buf);\n  const doc = mupdf.load(arrayBuf);\n  \n  // Each of these returns a string:\n  \n  const png = mupdf.drawPageAsPNG(doc, 1, 300);\n  const svg = mupdf.drawPageAsSVG(doc, 1);\n  const html = mupdf.drawPageAsHTML(doc, 1);\n}\n```\n\n## Conversion Options\n\n### PNG\n\n```js\nmupdf.drawPageAsPNG(document, page, resolution);\n```\n\nArguments:\n- document: *a MuPdf document object*\n- page: *the page number to be rendered, starting from 1*\n- resolution: *the DPI to use for rendering the file*\n\nReturns: *an uncompressed PNG image, encoded as a base64 data URI.*\n\n### SVG\n\n```js\nmupdf.drawPageAsSVG(document, page);\n```\n\nArguments:\n- document: *a MuPdf document object*\n- page: *the page number to be rendered, starting from 1*\n\nReturns: *an SVG file with the PDF document rendered as image tiles.*\n\n### HTML\n\n```js\nmupdf.drawPageAsHTML(document, page);\n```\n\nArguments:\n- document: *a MuPdf document object*\n- page: *the page number to be rendered, starting from 1*\n\nReturns: *an HTML file that uses absolute positioned elements for layout.*\n\n## Text operations\n\n### Get text from page\n\n```js\nmupdf.getPageText(document, page);\n```\n\nArguments:\n- document: *a MuPdf document object*\n- page: *the page number to be rendered, starting from 1*\n\nReturns: *string containing all text collected from page*\n\n### Search on the page\n\n```js\nmupdf.searchPageText(document, page, searchString, maxHits);\n```\n\nArguments:\n- document: *a MuPdf document object*\n- page: *the page number to be rendered, starting from 1*\n- searchString: *string to search*\n- maxHits: *the maximum possible number of matches (it stops search when reaches this limit)*\n\nReturns: *array of found rectangles of text matches ({x: number, y: number, w: number, h: number}[])*\n\nYou should set `maxHits` to an appropriate level that a user would expect (for example 100), or allow users to set their own limit. Alternatively, if you want to allow effectively unlimited search hits (and risk running out of memory), you can set it to C's maximum unsigned 32-bit integer size, which is 4294967295.\n\n# Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md)\n\n# License\n\nAGPL, subject to the [MuPDF license](https://www.mupdf.com/licensing/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandytango%2Fmupdf-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandytango%2Fmupdf-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandytango%2Fmupdf-js/lists"}