This a very simple example code that I wrote following the documentation of the path function for NodeJS. I basically want to draw a shape and have the border one color and be filled with anoter color. I thought path was the way to go. But it doesn't work:
//import { jsPDF } from "jspdf";
const { jsPDF } = require("jspdf"); // will automatically load the node version
// Default export is a4 paper, portrait, using millimeters for units
const doc = new jsPDF();
// Getting the page width and size
var PAGE_WIDTH = doc.internal.pageSize.getWidth();
var PAGE_HEIGHT = doc.internal.pageSize.getHeight();
doc.setDrawColor("#ff0000")
doc.setFillColor("#00ff00")
var h = PAGE_HEIGHT/2;
var w = PAGE_WIDTH/2;
var path = [];
path.push({op: "m", c: [0,0]})
path.push({op: "l", c: [w,0]})
path.push({op: "l", c: [w,h]})
path.push({op: "l", c: [0,h]})
path.push({op: "h", c: []})
doc.path(path);
doc.save("a4.pdf");
Can anyone suggest me why this doesn't draw anything?