Skip to content

I propose to add a builderΒ #2

@pleshevskiy

Description

@pleshevskiy

It seems to me that the builder design pattern is most suitable for this library.

const brandInvoiceBuilder = new InvoiceBuilder()
   .useStyles(
       new StyleBulder()
           .withDocument({ marginLeft: 30, marginRight: 30, marginTop: 30 })
           .withFonts({ ... })
           .withHeader({ ... })
       // or use style objects as well
       // if you pass style builder, invoice builder will build your styles automatically
   );

// then in any business logic
brandInvoiceBuilder.generate(invoiceData, 'path/to/your/invoice.pdf');

If you don't use custom styles, it will generate an invoice with default styles. Also if you use StyleBuilder with no or partial use of its methods, it will create default styles or your styles that have been merged with the default styles

const defaultInvoiceBuilder = new InvoiceBuilder();
// or new InvoiceBuilder().useStyles(new StyleBuilder())
defaultInvoiceBuilder.generate(invoiceData, 'path/to/your/invoice.pdf'); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions