Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Add support for tables #1577

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

hollandjake
Copy link

@hollandjake hollandjake commented Dec 24, 2024

What kind of change does this PR introduce?

  • Add doc.table() support
  • Tables can have each cell individually customised

Checklist:

  • Unit Tests
  • Documentation
  • Update CHANGELOG.md
  • Ready to be merged

Resolves #29

Builds off #1576 (allowing a cell to set a temporary font inside the context of its contents, reverting back after)

- Enable defining sizes using any units (defaulting to Points)
- This also allows us to define sizes based on the current font context i.e. em's
- The new public `sizeToPoint` method allows users to also interact with these sizes to generate the correct point sizes
- Tables support cell customization (including colors)
- Add handy alias for pages to define the contentWidth and contentHeight
@hollandjake
Copy link
Author

I've just noticed @blikblum had added some visual test for pdfmake, was there any indication as to if we were wanting the table interface to be similar to pdfmakes?

@MatthijsReyers
Copy link

Great feature! Tables are really the one thing I was missing in pdfkit, I've pulled your branch to play around a bit and I was just wondering if there is any way to create tables with columns of different widths? That seems like it should be pretty core functionality, but I can't figure out how to do it, intuitively I would expect the API to use one of these properties, but it does not seem to work:

await doc.table({ 
        rows: 2, 
        height: 100,
        width: 10 + 20 + 30,
        cellWidth: [10, 20, 30],
    })
    .row([
        {
            value: 'A', 
            cellWidth: 10,
            width: 10,
        },
        {
            value: 'B', 
            cellWidth: 20,
            width: 20,
        },
        {
            value: 'C', 
            cellWidth: 30,
            width: 30,
        },
    ])
    .row([
        'D', 
        'E',
        'F'
    ])

@hollandjake
Copy link
Author

No way to do column width atm but there is colspan support

@hollandjake
Copy link
Author

@MatthijsReyers originally I implemented the table logic to follow along with how HTML tables are generated, but I'm thinking of rewriting the table generation logic to follow more along with the pdfmake approach, allowing us to define column widths instead of number of columns (with auto support of course).

@hollandjake hollandjake changed the title Add support for tables wip: Add support for tables Jan 2, 2025
@hollandjake hollandjake marked this pull request as draft January 2, 2025 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tables
2 participants