From 1f260790433a5df81af9cf0ab51241b1544a50e2 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 31 Dec 2025 01:43:21 -0300 Subject: [PATCH] feat: auto-adjust PDF zoom to fit container width Implements automatic zoom calculation to ensure PDFs fit horizontally within the viewer container, preventing overflow. - Calculates optimal scale based on widest page and container width - Handles PDFs with multiple pages of different widths - Adapts zoom on window resize - Uses 200ms delay to avoid PDF.js render conflicts Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/Components/PdfEditor/PdfEditor.vue | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Components/PdfEditor/PdfEditor.vue b/src/Components/PdfEditor/PdfEditor.vue index 8185e482f2..9e0d0b863d 100644 --- a/src/Components/PdfEditor/PdfEditor.vue +++ b/src/Components/PdfEditor/PdfEditor.vue @@ -64,8 +64,36 @@ export default { default: false, }, }, + mounted() { + window.addEventListener('resize', this.adjustZoomToFit) + }, + beforeDestroy() { + window.removeEventListener('resize', this.adjustZoomToFit) + }, methods: { + calculateOptimalScale(maxPageWidth) { + const containerWidth = this.$el?.clientWidth || 0 + if (!containerWidth || !maxPageWidth) return 1 + + const availableWidth = containerWidth - 80 + return Math.max(0.1, Math.min(2, availableWidth / maxPageWidth)) + }, + adjustZoomToFit() { + const vuePdfEditor = this.$refs.vuePdfEditor + const canvases = this.$el?.querySelectorAll('canvas') + if (!vuePdfEditor?.pdfDocuments?.length || !canvases?.length) return + + const maxCanvasWidth = Math.max(...Array.from(canvases).map(canvas => + canvas.width / (vuePdfEditor.scale || 1) + )) + + const optimalScale = this.calculateOptimalScale(maxCanvasWidth) + if (Math.abs(optimalScale - vuePdfEditor.scale) > 0.01) { + vuePdfEditor.scale = optimalScale + } + }, endInit(event) { + setTimeout(() => this.adjustZoomToFit(), 200) this.$emit('pdf-editor:end-init', { ...event }) }, onDeleteSigner(object) {