Skip to content

How to get it to work without nodejs #30

@abdurahmanshiine

Description

@abdurahmanshiine

Hi there,

I'm trying to use this module without nodejs, but I'm getting an error telling me PdfContext is undefined. Here is my code for reference:

(index.html)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="blob-stream.js"></script>
    <script src="file-saver.min.js"></script>
    <script src="canvas2pdf.min.js"></script>
    <script src="./index.js"></script>
</head>

<body>
...
</body>

</html>

The file canvas2pdf.min.js above is the /dist/canvas2pdf.js file

(index.js)

// Create a new PDF canvas context.
const ctxPdf = new PdfContext(blobStream());

// draw your canvas like you would normally
ctxPdf.fillStyle = "yellow";
ctxPdf.fillRect(100, 100, 100, 100);
// more canvas drawing, etc...

// convert your PDF to a Blob and save to file
ctxPdf.stream.on("finish", function () {
  var blob = ctxPdf.stream.toBlob("application/pdf");
  saveAs(blob, "example.pdf", true);
});
ctxPdf.end();

And this is the error the browser is throwing Uncaught ReferenceError: PdfContext is not defined

Any idea what I'm doing wrong?

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