{"id":16993271,"url":"https://github.com/mp70/pdf-lib-draw-table","last_synced_at":"2025-03-17T09:30:38.357Z","repository":{"id":146296271,"uuid":"615784410","full_name":"MP70/pdf-lib-draw-table","owner":"MP70","description":"pdf-lib based tool for drawing tables on new or existing PDFs with TS/JS, server or client side. Simple playground - https://pdf-lib-table-demo.vercel.app/ ","archived":false,"fork":false,"pushed_at":"2024-06-13T22:32:58.000Z","size":590,"stargazers_count":17,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-07T16:54:32.599Z","etag":null,"topics":["nodejs","pdf","pdf-editing","pdf-generation","pdf-lib","react"],"latest_commit_sha":null,"homepage":"https://mp70.github.io/pdf-lib-draw-table/modules.html","language":"TypeScript","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/MP70.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["mp70"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-03-18T17:08:15.000Z","updated_at":"2025-03-02T08:48:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d3fd200-e289-45f2-b420-432af9ab5f73","html_url":"https://github.com/MP70/pdf-lib-draw-table","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MP70%2Fpdf-lib-draw-table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MP70%2Fpdf-lib-draw-table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MP70%2Fpdf-lib-draw-table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MP70%2Fpdf-lib-draw-table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MP70","download_url":"https://codeload.github.com/MP70/pdf-lib-draw-table/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243858393,"owners_count":20359253,"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":["nodejs","pdf","pdf-editing","pdf-generation","pdf-lib","react"],"created_at":"2024-10-14T03:32:49.684Z","updated_at":"2025-03-17T09:30:37.791Z","avatar_url":"https://github.com/MP70.png","language":"TypeScript","funding_links":["https://github.com/sponsors/mp70"],"categories":[],"sub_categories":[],"readme":"# Beta - pdf-lib-draw-table\n\n[![codecov](https://codecov.io/gh/MP70/pdf-lib-draw-table/branch/main/graph/badge.svg?token=BMJ2WXX5EV)](https://codecov.io/gh/MP70/pdf-lib-draw-table)[![Tests](https://github.com/MP70/pdf-lib-draw-table/actions/workflows/runTests.yml/badge.svg)](https://github.com/MP70/pdf-lib-draw-table/actions/workflows/runTests.yml)\n[![TypeScript](https://img.shields.io/badge/TypeScript-%5E5.0.2-blue)](https://mp70.github.io/pdf-lib-draw-table)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue)](https://mp70.github.io/pdf-lib-draw-table)\n#### A library for drawing tables in PDFs using pdf-lib.\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Example](#example)\n- [Documentation](#documentation)\n- [License](#license)\n\n## Installation\n\n```sh\nnpm install pdf-lib-draw-table-beta\n```\n\nIf you don't already have pdf-lib then\n\n```sh\nnpm install pdf-lib pdf-lib-draw-table\n```\n\n## Example\nThis is a *very* simple example (server side as we are using fs). Exactly the same code (minus fs!) will also work client side for example in a react component. The options are fairly extensive for [formatting and styling](https://mp70.github.io/pdf-lib-draw-table/interfaces/DrawTableOptions.html), we just show a couple here. You can also pass us a [JSON table](https://mp70.github.io/pdf-lib-draw-table/interfaces/TableObject.html) if you prefer, either that or array as below is fine. Either can contain any of the following within each cell:\nstring - As in the example below. This is drawn as wrapped text, no word splitting.\n[Image](https://mp70.github.io/pdf-lib-draw-table/types/Image.html),\n[Link](https://mp70.github.io/pdf-lib-draw-table/types/Link.html),\n[CustomSyledText](https://mp70.github.io/pdf-lib-draw-table/interfaces/CustomStyledText.html)\n**OR AN ARRAY OF ANY COMBO OF THE ABOVE**\nIf you provide an array we automatically put each item on its own line, as such if you need to manually new line text, this is a way of doing that.\n```\nimport { PDFDocument } from 'pdf-lib';\nimport { drawTable } from 'pdf-lib-draw-table';\nimport fs from 'fs';\n\n(async () =\u003e {\n  // Create a new PDFDocument\n  const pdfDoc = await PDFDocument.create();\n\n  // Add a new page\n  const page = pdfDoc.addPage([600, 800]);\n\n  // Define the table data\n  const tableData = [\n    ['Name', 'Age', 'City'],\n    ['Alice', '24', 'New York'],\n    ['Bob', '30', 'San Francisco'],\n    ['Charlie', '22', 'Los Angeles'],\n  ];\n\n  // Set the starting X and Y coordinates for the table\n  const startX = 50;\n  const startY = 750;\n\n  // Set the table options\n  const options = {\n    header: {\n      hasHeaderRow: true,\n      backgroundColor: rgb(0.9, 0.9, 0.9),\n    },\n  };\n\n  try {\n    // Draw the table\n    const tableDimensions = await drawTable(pdfDoc, page, tableData, startX, startY, options);\n\n    console.log('Table dimensions:', tableDimensions);\n\n    // Serialize the PDF to bytes and write to a file\n    const pdfBytes = await pdfDoc.save();\n    fs.writeFileSync('table-example.pdf', pdfBytes);\n  } catch (error) {\n    console.error('Error drawing table:', error);\n  }\n})();\n```\n\nMassive thanks to [PDF lib](https://github.com/Hopding/pdf-lib) for creating a powerful PDF manipulation library.\n\nAlso, big thanks to Typedoc for providing the amazing documentation generator tool that makes /docs: \nhttps://github.com/TypeStrong/typedoc\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmp70%2Fpdf-lib-draw-table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmp70%2Fpdf-lib-draw-table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmp70%2Fpdf-lib-draw-table/lists"}