Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vedantroy/571d36c2767f3f570b865c528c0f9525 to your computer and use it in GitHub Desktop.
Save vedantroy/571d36c2767f3f570b865c528c0f9525 to your computer and use it in GitHub Desktop.
Save Rent Cafe Lease As Image
function findActivePageAndSaveCanvas() {
// Get all document pages
const pages = document.querySelectorAll('.document-page');
// Loop through all pages to find the active one (with a canvas)
for (let i = 0; i < pages.length; i++) {
const canvas = pages[i].querySelector('canvas');
// If this page has a canvas, it's active
if (canvas) {
console.log(`Active page found: Page ${i + 1}`);
// Save the canvas as an image
try {
// Convert canvas to data URL (PNG format by default)
const dataURL = canvas.toDataURL('image/png');
// Create a download link
const downloadLink = document.createElement('a');
downloadLink.href = dataURL;
downloadLink.download = `page_${i + 1}_canvas.png`;
// Append to body, click programmatically, then remove
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
console.log(`Canvas from page ${i + 1} saved as image`);
} catch (error) {
console.error(`Error saving canvas from page ${i + 1}:`, error);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment