betterwrite / pdfeasy

📕 A JavaScript Client/Server Side PDF-Generator based in PDFKit
https://betterwrite.github.io/pdfeasy
MIT License
76 stars 4 forks source link

TypeError: r.readFileSync is not a function #15

Closed 9M6 closed 11 months ago

9M6 commented 11 months ago

I am getting the following issue:

TypeError: r.readFileSync is not a function
    at It.open (client.esm.js?v=e477b2ae:23717:119)
    at PDFDocumentWithTables.font (client.esm.js?v=e477b2ae:23717:851)
    at u (resolvers.ts:127:8)
    at uK (resolvers.ts:408:27)
    at Qo.pipeline (runner.ts:160:13)
------------------------------
- Operating System: Darwin
- Node Version:     v18.16.0
- Nuxt Version:     3.6.5
- Nitro Version:    2.5.2
- Package Manager:  npm@9.5.1
- Builder:          vite
- User Config:      experimental, vite, nitro, devtools, debug, ssr, css, imports, runtimeConfig, modules, apiParty
- Runtime Modules:  @pinia/nuxt@0.4.11, @nuxtjs/tailwindcss@6.8.0, @nuxtjs/i18n@8.0.0-beta.13, @vueuse/nuxt@10.3.0, nuxt-typed-router@3.2.5, nuxt-lodash@2.5.0, nuxt-api-party@0.13.0, nuxt-icon@0.4.2, nuxt-pdfeasy@1.4.0
- Build Modules:    -
------------------------------
onMounted(() => {
  const { $pdf } = useNuxtApp();
  if (process.client) {
    $pdf.new();
    $pdf.add([
      { raw: "Hello PDFEasy!", text: { font: "Roboto" } }, // text with custom font,
      { raw: "https://i.imgur.com/path.png", image: {} }, // external image
      {
        stack: [
          // stack for paragraph's
          { raw: "A ", text: {} },
          { raw: "Simple", text: { bold: true, italic: true } },
          { raw: " Stack!", text: {} },
        ],
      },
      { pageBreak: {} }, // page break
      { lineBreak: {} }, // line break
      { raw: "A checkbox!", checkbox: {} }, // checkbox
      { raw: "A list!", list: { style: "circle" } }, // list
      { raw: "https://link", qrcode: {} }, // use qrcode.js lib
      {
        table: {
          // table. Check pdfkit-table package for more explanations
          body: {
            title: "Title",
            subtitle: "subtitle",
            headers: ["Item 1", "Item 2"],
            rows: [
              ["A", "100%"],
              ["B", "50%"],
            ],
          },
          options: {},
        },
      },
      {
        form: [
          // dynamic forms
          {
            name: "button-field",
            type: "button",
            options: { label: "Click here!" },
          },
          { name: "text-field", type: "text", options: { value: "" } },
        ],
      },
    ]);

    $pdf
      .run({
        type: "client",
        // 'blob' | 'save' | 'open-link' | 'none'
        clientEmit: "save",
      })
      .then(() => {})
      .catch((err) => {
        console.error(err);
      });
  }
});
Novout commented 11 months ago

For use custom font's like { raw: "Hello PDFEasy!", text: { font: "Roboto" } } it's necessary to insert this custom font in the flow $pdf.addFonts(). This example is only to demonstrate some use examples.

9M6 commented 11 months ago

@Novout I have done that, but the addFonts functionality does not work. I went ahead and debugged your library, and seems the fs library is not shimmed correctly for the pdfkit.standalone.js as instead of returning the fs-virtual.js it returns an empty object due to the other shim libraries you have used.

9M6 commented 11 months ago

I tried to fix it but I didn't have much time to try different things.