Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions examples/vite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# jsPDF + Vite Test Project

This test project demonstrates that jsPDF now works correctly with Vite after the compatibility fix.

## Setup

```bash
npm install
```

## Development

```bash
npm run dev
```

Open http://localhost:5173 and click "Generate PDF" to test.

## Production Build

```bash
npm run build
npm run preview
```

Open http://localhost:4173 and test the production build.

## What's Tested

- βœ… ES module import: `import { jsPDF } from "jspdf"`
- βœ… PDF generation and download
- βœ… Development server compatibility
- βœ… Production build success

This confirms that GitHub issue #3851 has been resolved.
17 changes: 17 additions & 0 deletions examples/vite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + jsPDF Test</title>
</head>
<body>
<div id="app">
<h1>jsPDF + Vite Test</h1>
<button id="generate-pdf">Generate PDF</button>
<div id="status"></div>
</div>
<script type="module" src="/main.js"></script>
</body>
</html>
41 changes: 41 additions & 0 deletions examples/vite/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { jsPDF } from "jspdf";

document.addEventListener("DOMContentLoaded", () => {
const button = document.getElementById("generate-pdf");
const status = document.getElementById("status");

button.addEventListener("click", () => {
try {
// Test that jsPDF import works
const doc = new jsPDF();

doc.text(
"Hello, this is a test PDF generated with jsPDF and Vite!",
10,
10
);
doc.text("If you can see this, the import issue has been fixed.", 10, 20);

// Save the PDF
doc.save("test-vite-jspdf.pdf");

status.innerHTML =
'<span style="color: green;">βœ… Success! PDF generated successfully.</span>';
status.innerHTML += "<br>jsPDF version: " + (doc.version || "unknown");
} catch (error) {
status.innerHTML =
'<span style="color: red;">❌ Error: ' + error.message + "</span>";
console.error("jsPDF Error:", error);
}
});

// Test that the import worked
try {
const testDoc = new jsPDF();
status.innerHTML =
'<span style="color: blue;">πŸ“¦ jsPDF imported successfully! Click the button to test PDF generation.</span>';
} catch (error) {
status.innerHTML =
'<span style="color: red;">❌ Import Error: ' + error.message + "</span>";
}
});
Loading