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

export type HookData #1075

Open
aynuayex opened this issue Nov 6, 2024 · 0 comments
Open

export type HookData #1075

aynuayex opened this issue Nov 6, 2024 · 0 comments

Comments

@aynuayex
Copy link

aynuayex commented Nov 6, 2024

export the type HookData from the library so that we can use it?

// eslint-disable-next-line new-cap
    const doc = new jsPDF()

    // Define the header and footer content
    const header = () => {
      doc.setFontSize(14)
      doc.text('Company Name: Alem Expect Solution', 14, 22) // Custom header
      doc.text(
        'Address: Addis Ababa Ethiopia, Gerji Mebrat Hail, Mag Building 204 office',
        14,
        27,
      ) // Custom footer
    }

    // Define the footer content
    const footer = (pdfdata: HookData) => {
      // const pageCount = doc.internal.getNumberOfPages()
      // const pageCount = doc.internal.pages.length - 1
      const pageCount = doc.getNumberOfPages()
      doc.setFontSize(10)
      doc.text(
        `Page ${pdfdata.pageNumber} of ${pageCount}`,
        pdfdata.settings.margin.left,
        doc.internal.pageSize.height - 10,
      ) // Footer with page count
    }

    // Safely map over data rows or use an empty array if data is undefined
    const dataRows =
      data?.data?.map((row) =>
        columns.map((col) => {
          const accessor = col.accessorKey as keyof FinanceReportType // Assert accessorKey as a key of FinanceReportType
          return accessor ? row[accessor] : ''
        }),
      ) || []
    // Create the table with data
    autoTable(doc, {
      head: [columns.map((c) => c.header)], // Table header
      body: dataRows, // Table body
      startY: 40, // Start the table below the header
      didDrawPage: (pdfdata) => {
        header() // Add header when drawing the page
        footer(pdfdata) // Add footer when drawing the page
      },
    })

    // Save the PDF to the browser
    doc.save('example.pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants