Created
May 1, 2025 11:25
-
-
Save cnp96/fd205b7b0d42f234522eb318f5ece66a to your computer and use it in GitHub Desktop.
Download from resume.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let script = document.createElement('script'); | |
script.src = "https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"; | |
script.onload = function() { | |
// Step 1: Select the canvas element | |
const canvas = document.querySelectorAll('canvas')[1]; // Adjust selector if needed | |
// Step 2: Convert canvas to image | |
const imgData = canvas.toDataURL('image/png'); | |
// Step 3: Create PDF and add image | |
const { jsPDF } = window.jspdf; | |
const pdf = new jsPDF({ | |
orientation: 'portrait', | |
unit: 'pt', | |
format: 'a4', | |
}); | |
// Adjust dimensions to fit A4 | |
const pdfWidth = pdf.internal.pageSize.getWidth(); | |
const pdfHeight = pdf.internal.pageSize.getHeight(); | |
// Calculate image size proportionally | |
const imgWidth = canvas.width; | |
const imgHeight = canvas.height; | |
const ratio = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight); | |
pdf.addImage(imgData, 'PNG', 0, 0, imgWidth * ratio, imgHeight * ratio); | |
pdf.save('Resume.pdf'); | |
} | |
document.head.appendChild(script); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment