screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.0/html2canvas.min.js"></script> </head> <body> <div id="app" class="container"> <h1>Vue Div Convert to base64 image</h1> <div ref="myDiv"> <h1>Hello World!</h1> <p>This is some sample content.</p> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> </div> <button @click="convertToBase64">Convert to Base64</button> <img :src="base64Image" v-if="base64Image" /> </div> <script type="module"> const app = Vue.createApp({ data() { return { base64Image: null }; }, methods: { async convertToBase64() { try { const div = this.$refs.myDiv; const canvas = await html2canvas(div, { useCORS: true, // Set this to true if you're capturing content from other domains backgroundColor: null, // Use the default background color scale: 2, // Increase the scale for higher quality dpi: 300, // Set the DPI to improve print quality letterRendering: true // Use higher quality text rendering }); const base64Image = canvas.toDataURL(); this.base64Image = base64Image; } catch (error) { console.error(error); } } } }) app.mount('#app') </script> <style scoped> /* CSS styles go here */ .container { margin: 0 auto; max-width: 800px; padding: 20px; background-color: #f7f7f7; font-family: Arial, sans-serif; } h1 { color: #333; font-size: 2.4rem; margin-bottom: 20px; } p { color: #666; font-size: 1.6rem; line-height: 1.5; margin-bottom: 10px; } ul { list-style: none; padding: 0; margin: 0; } li { color: #666; font-size: 1.6rem; line-height: 1.5; margin-bottom: 5px; } button { background-color: #0074d9; color: #fff; border: none; padding: 10px 20px; font-size: 1.6rem; cursor: pointer; border-radius: 4px; margin-top: 20px; } img { max-width: 100%; height: auto; margin-top: 20px; } </style> </body> </html>