#Next js App router and PDF generate from objects

1 messages · Page 1 of 1 (latest)

sonic void
#

guys i need to know which is the latest method to create PDF in next js Approuter . i was searching different library some of them are deprecated other people are saying different problems so which is the right one

vivid adderBOT
#

Hi @sonic void. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Hmm, I don't know enough to give you a confident answer yet. The information extracts provided do not contain specific details about creating PDFs in Next.js using the App Router. However, there is a discussion on a Github issue (https://github.com/vercel/next.js/issues/58313) about problems with importing pdfjs-dist in Next.js, which might be related to your question.

For more information, you might want to check the Next.js documentation (https://nextjs.org/docs) or the Next.js GitHub repository (https://github.com/vercel/next.js) for more details or potential solutions.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@sonic void kapa.ai is still learning and improving, please let us know how it did by reacting below

sonic void
#

like when i submit a form i will create an object base on the object i need to make a bill pdf which contain table of data .

final tendon
#

You can use jspdf and html2canvas modules for generating PDF.
This is the example code
`const createPDFDataForEmailAttachment = async () => {

  const pdf = new jsPDF("p", "pt", "letter");

  // First, capture the first page.
  const page1Element = document.querySelector(".pdf-preview-wrapper-page-1");
  const page1Canvas = await html2canvas(page1Element, {
    dpi: 144,
    scale: 2,
    quality: 10,
    windowWidth: 1800,
    WindowHeight: 1800 * (11 / 8.5),
    letterRendering: false,
    useCORS: true,
  });

  // Add the first page to the PDF.
  pdf.addImage(
    page1Canvas.toDataURL("image/jpeg", 0.5),
    "JPEG",
    0,
    0,
    pdf.internal.pageSize.getWidth(),
    pdf.internal.pageSize.getHeight()
  );

};`
I hope this will help you.