stafyniaksacha / facturx

Generate and extract Factur-X and Order-X invoices
https://www.npmjs.com/package/@stafyniaksacha/facturx
0 stars 1 forks source link

Support of type PDFDocumentWithTables #1

Closed loresclement closed 3 weeks ago

loresclement commented 1 month ago

Hello ! Thank you for your package. I'm trying to use it but I have an issue.

I'm using the package pdfkit-table (which is an extension of pdf-kit). It has the type of PDFDocumentWithTables

Could you add the support of this type ? Otherwise does a workaround exists ?

stafyniaksacha commented 1 month ago

Hello!

You should be able to do it via:

const { writeFile } = require("node:fs/promises");
const { buffer } = require('node:stream/consumers');
const { generate } = require('@stafyniaksacha/facturx');
const PDFDocument = require("pdfkit-table");

const xml = `<?xml version="1.0" encoding="UTF-8"?>...`

function createPdfKitStream() {
  const doc = new PDFDocument({ margin: 30, size: 'A4' });

  // ...

  doc.end()

  // return doc without using pipe()
  return doc
}

async function main() {
  const stream = createPdfKitStream();
  // consume pdfkit stream to buffer
  const pdf = await buffer(stream);

  await writeFile("./document.pdf", pdf);

  const facturx = await generate({
    pdf,
    xml,
  })

  await writeFile("./document-facturx.pdf", facturx);
}

main().catch(console.error);
loresclement commented 3 weeks ago

It's working ! Thank you