Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Components/PdfEditor/PdfEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,36 @@ export default {
default: false,
},
},
mounted() {
window.addEventListener('resize', this.adjustZoomToFit)
},
beforeDestroy() {
window.removeEventListener('resize', this.adjustZoomToFit)
},
methods: {
Comment thread
vitormattos marked this conversation as resolved.
calculateOptimalScale(maxPageWidth) {
const containerWidth = this.$el?.clientWidth || 0
if (!containerWidth || !maxPageWidth) return 1

const availableWidth = containerWidth - 80
Comment thread
vitormattos marked this conversation as resolved.
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) {
Comment thread
vitormattos marked this conversation as resolved.
Comment thread
vitormattos marked this conversation as resolved.
vuePdfEditor.scale = optimalScale
}
},
endInit(event) {
setTimeout(() => this.adjustZoomToFit(), 200)
Comment thread
vitormattos marked this conversation as resolved.
this.$emit('pdf-editor:end-init', { ...event })
},
onDeleteSigner(object) {
Expand Down