0% found this document useful (0 votes)
10 views1 page

JavaScript Guide Beginners

java script

Uploaded by

jetawam887
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

JavaScript Guide Beginners

java script

Uploaded by

jetawam887
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

JavaScript Guide for Beginners: Creating a PDF

### JavaScript for Beginners: Create PDF

Creating a PDF with JavaScript can be done using libraries like jsPDF.
Below is a step-by-step guide.

#### Step 1: Include jsPDF Library


First, include the jsPDF library in your project. You can use a CDN:

<script src='https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.4.0/jspdf.umd.min.js'></script>

#### Step 2: Write the JavaScript Code


Here’s an example of how to create a simple PDF:

<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Create PDF with JavaScript</title>
</head>
<body>
<button id='download'>Download PDF</button>
<script>
document.getElementById('download').addEventListener('click', function () {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.text('Hello, this is a PDF created using JavaScript!', 10, 10);
doc.save('example.pdf');
});
</script>
</body>
</html>

#### Step 3: Run the Code


1. Copy the code into an .html file.
2. Open the file in a browser.
3. Click the 'Download PDF' button, and your PDF will be downloaded.

You might also like