{"id":17948868,"url":"https://github.com/blikblum/pdfmake-utils","last_synced_at":"2025-03-24T22:35:40.303Z","repository":{"id":33169309,"uuid":"153896027","full_name":"blikblum/pdfmake-utils","owner":"blikblum","description":"Helper classes to use with PdfMake","archived":false,"fork":false,"pushed_at":"2024-06-20T20:34:05.000Z","size":1251,"stargazers_count":8,"open_issues_count":29,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T05:07:08.378Z","etag":null,"topics":["javascript","pdf","pdfkit","pdfmake"],"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/blikblum.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","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":"2018-10-20T10:51:51.000Z","updated_at":"2024-08-07T17:40:27.000Z","dependencies_parsed_at":"2023-11-06T03:33:17.454Z","dependency_job_id":"e2240494-a5d8-4347-81bb-74074c133432","html_url":"https://github.com/blikblum/pdfmake-utils","commit_stats":{"total_commits":38,"total_committers":5,"mean_commits":7.6,"dds":0.4473684210526315,"last_synced_commit":"ba94740b6a8b7b37e948af78ff35ed8f79c1aab6"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blikblum%2Fpdfmake-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blikblum%2Fpdfmake-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blikblum%2Fpdfmake-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blikblum%2Fpdfmake-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blikblum","download_url":"https://codeload.github.com/blikblum/pdfmake-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245366205,"owners_count":20603438,"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":["javascript","pdf","pdfkit","pdfmake"],"created_at":"2024-10-29T09:10:26.388Z","updated_at":"2025-03-24T22:35:35.288Z","avatar_url":"https://github.com/blikblum.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PdfMake Utils\n\n[![NPM version](https://img.shields.io/npm/v/pdfmake-utils.svg?style=flat-square)](https://www.npmjs.com/package/pdfmake-utils)\n[![NPM downloads](https://img.shields.io/npm/dm/pdfmake-utils.svg?style=flat-square)](https://www.npmjs.com/package/pdfmake-utils)\n[![Dependency Status](https://img.shields.io/david/dev/blikblum/pdfmake-utils.svg?style=flat-square)](https://david-dm.org/blikblum/pdfmake-utils#info=devDependencies)\n\n\u003e PdfMake Utils provides helper classes to use with PdfMake\n\n\n### Features\n\n\u0026nbsp; \u0026nbsp; ✓ Custom element class to display pdf document\u003cbr\u003e\n\u0026nbsp; \u0026nbsp; ✓ Load assets dynamically\u003cbr\u003e\n\n\n### Documentation\n\n#### PdfAssetsLoader\n\nA class to load dynamically fonts and arbitrary files.\n\n##### Properties\n * `ready`: Becomes true when assets loading is done\n * `vfs`: a hash containing loaded files data\n * `fonts`: a hash containing loaded fonts data\n * `pdfMake`: pdfMake instance (optional) \n\n##### Methods\n * `registerFile`\n   Register a file to be loaded. Accepts a hash with following properties:\n   * `name`: the file name\n   * `URL`: URL where the file should be loaded from. If not set it will use `name`\n * `registerFont`\n   Register a font to be loaded. Accepts a hash with following properties:\n   * `name`: the font name\n   * `fileName`: the font file name\n   * `URL`: URL where the file should be loaded from. If not set it will use `fileName`\n   * `styles`: an array with the styles that this file will be associated with\n * `configurePdfMake`\n   Configure pdfMake `vfs` and `fonts` properties with the loaded data. Accepts the pdfMake instance as argument   \n * `load`: loads the registered fonts / files and configure pdfMake if pdfMake property is assigned. Returns a promise that is\n   resolved if all files loaded correctly or is rejected if any file fails to load.\n\n\n\n##### Usage\n```javascript\nimport pdfmake from 'pdfmake/build/pdfmake'\nimport { PdfAssetsLoader } from 'pdfmake-utils'\n\nconst assetsLoader = new PdfAssetsLoader()\npdfmake.fonts = assetsLoader.fonts\npdfmake.vfs = assetsLoader.vfs\n\n// register Roboto font, normal variant. Roboto-Regular.woff must be in root path\nassetsLoader.registerFont({name: 'Roboto', fileName: 'Roboto-Regular.woff', styles: ['normal']})\n// register Roboto font, bolditalics variant using a custom file location\nassetsLoader.registerFont({name: 'Roboto', fileName: 'Roboto-MediumItalic.woff', URL: 'fonts/Roboto-MediumItalic.woff', styles: ['bolditalics']})\n\n// register a file to be loaded in the root path\nassetsLoader.registerFile({name: 'MyLogo.png'})\n// register a file with a custom location\nassetsLoader.registerFile({name: 'MyHeader.png', URL: 'images/sunshine.png'})\n\nassetsLoader.load().then(() =\u003e {\n  console.log('assets loaded')\n}).catch(errors =\u003e {\n  // errors -\u003e array with all file loading errors\n  console.error('assets loading', errors);\n})\n\n```\n\n##### Standard fonts\n\nThe [Pdf standard fonts](https://en.wikipedia.org/wiki/PDF#Standard_Type_1_Fonts_(Standard_14_Fonts)) can be loaded by setting `fileName` to\nthe font name without extension, e.g., 'Courier' or 'Courier-Bold'. By default, it will load the respective [*.afm file](https://github.com/foliojs/pdfkit/tree/master/lib/font/data) in root path.\n\n\u003e To use standard fonts is necessary to call `configurePdfMake`\n\n##### Usage\n```javascript\nimport pdfmake from 'pdfmake/build/pdfmake'\nimport { PdfAssetsLoader } from 'pdfmake-utils'\n\nconst assetsLoader = new PdfAssetsLoader()\n\n// register a Times font that will use the standard Times-Roman font. Times-Roman.afm must be in root path\nassetsLoader.registerFont({name: 'Times', fileName: 'Times-Roman', styles: ['normal']})\n// registering standard Times-Italic with a custom afm file location\nassetsLoader.registerFont({name: 'Times', fileName: 'Times-Italic', URL: 'fonts/Times-Italic.afm', styles: ['italics']})\n\n// all possible standard fonts\nassetsLoader.registerFont({name: 'Times', fileName: 'Times-Roman', styles: ['normal']})\nassetsLoader.registerFont({name: 'Times', fileName: 'Times-Italic', styles: ['italics']})\nassetsLoader.registerFont({name: 'Times', fileName: 'Times-Bold', styles: ['bold']})\nassetsLoader.registerFont({name: 'Times', fileName: 'Times-BoldItalic', styles: ['bolditalics']})\n\nassetsLoader.registerFont({name: 'Courier', fileName: 'Courier', styles: ['normal']})\nassetsLoader.registerFont({name: 'Courier', fileName: 'Courier-Oblique', styles: ['italics']})\nassetsLoader.registerFont({name: 'Courier', fileName: 'Courier-Bold', styles: ['bold']})\nassetsLoader.registerFont({name: 'Courier', fileName: 'Courier-BoldOblique', styles: ['bolditalics']})\n\nassetsLoader.registerFont({name: 'Helvetica', fileName: 'Helvetica', styles: ['normal']})\nassetsLoader.registerFont({name: 'Helvetica', fileName: 'Helvetica-Oblique', styles: ['italics']})\nassetsLoader.registerFont({name: 'Helvetica', fileName: 'Helvetica-Bold', styles: ['bold']})\nassetsLoader.registerFont({name: 'Helvetica', fileName: 'Helvetica-BoldOblique', styles: ['bolditalics']})\n\nassetsLoader.registerFont({name: 'Symbol', fileName: 'Symbol'})\n\nassetsLoader.registerFont({name: 'ZapfDingbats', fileName: 'ZapfDingbats'})\n\nassetsLoader.load().then(() =\u003e {\n  assetsLoader.configurePdfMake(pdfMake)\n}).catch(errors =\u003e {\n  // will fail if one of the files fails to load \n  // configure pdfMake with the files that loaded correctly\n  assetsLoader.configurePdfMake(pdfMake)\n  console.error('assets loading', errors);\n})\n\n```\n\n\n#### PdfViewer\n\nA Custom Element class that creates and displays a pdf in an iframe.\n\n \u003e The assets and the pdfmake packages are loaded dynamically the first time an instance is created\n\n \u003e By default, it uses `window.pdfMake`. Configure the pdfMake instance using `getPdfMake` callback\n\n\n##### Properties\n * `data`\n   The pdf document definition to be generated \n\n##### Static Properties\n * `getPdfMake`\n   Accepts a function that returns a pdfMake instance or a promise that resolves to a pdfMake instance\n\n##### Static Methods\n * `registerFile`\n   Register a file to be loaded. Same signature as PdfAssetsLoader registerFile method\n * `registerFont`\n   Register a font to be loaded. Same signature as PdfAssetsLoader registerFont method\n\n\n##### Usage\n```javascript\nimport { PdfViewer } from 'pdfmake-utils'\n\n// lazy load pdfmake (webpack will do code split automatically)\nPdfViewer.getPdfMake = () =\u003e import('pdfmake/build/pdfmake')\n\nPdfViewer.registerFont({name: 'Roboto', fileName: 'Roboto-Regular.woff', styles: ['normal']})\nPdfViewer.registerFont({name: 'Roboto', fileName: 'Roboto-Italic.woff', styles: ['italics']})\nPdfViewer.registerFile({name: 'MyLogo.png'})\n\ncustomElements.define('pdf-viewer', PdfViewer)\n\n// use pdf-viewer element with, e.g, lit-html:\n// \u003cpdf-viewer .data=${docDefinition}\u003e\u003c/pdf-viewer\u003e\n\n```\n\n### License\n\nCopyright © 2019 Luiz Américo. This source code is licensed under the MIT license found in\nthe [LICENSE.txt](https://github.com/blikblum/pdfmake-utils/blob/master/LICENSE.txt) file.\nThe documentation to the project is licensed under the [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)\nlicense.\n\n---\nMade with ♥ by Luiz Américo and [contributors](https://github.com/blikblum/pdfmake-utils/graphs/contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblikblum%2Fpdfmake-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblikblum%2Fpdfmake-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblikblum%2Fpdfmake-utils/lists"}