+ :style="{transform: `scale(${pagesScale[currentPage]})`}">
+
@@ -140,7 +143,7 @@
:height="object.height"
:origin-width="object.originWidth"
:origin-height="object.originHeight"
- :page-scale="pagesScale[pIndex]"
+ :page-scale="pagesScale[currentPage]"
@onUpdate="updateObject(object.id, $event)"
@onDelete="deleteObject(object.id)" />
@@ -156,7 +159,7 @@
:line-height="object.lineHeight"
:font-family="object.fontFamily"
:current-page="object.currentPage"
- :page-scale="pagesScale[pIndex]"
+ :page-scale="pagesScale[currentPage]"
@onUpdate="updateObject(object.id, $event)"
@onDelete="deleteObject(object.id)"
@onSelectFont="selectFontFamily" />
@@ -168,7 +171,7 @@
:width="object.width"
:origin-width="object.originWidth"
:origin-height="object.originHeight"
- :page-scale="pagesScale[pIndex]"
+ :page-scale="pagesScale[currentPage]"
@onUpdate="updateObject(object.id, $event)"
@onDelete="deleteObject(object.id)" />
@@ -193,6 +196,7 @@
import { fetchFont } from './utils/prepareAssets.js'
import PDFPage from './Components/PDFPage.vue'
+import Pagination from './Components/Pagination.vue'
import ImageItem from './Components/Image.vue'
import TextItem from './Components/TextItem.vue'
import Drawing from './Components/Drawing.vue'
@@ -216,6 +220,7 @@ export default {
TextIcon,
GestureIcon,
PencilIcon,
+ Pagination,
},
props: {
msg: String,
@@ -227,6 +232,10 @@ export default {
type: String,
default: '100%',
},
+ showPagination:{
+ type: Boolean,
+ default: false
+ },
showChooseFileBtn: {
type: Boolean,
default: false,
@@ -323,6 +332,7 @@ export default {
numPages: null,
pdfDocument: null,
pages: [],
+ currentPage: 0,
pagesScale: [],
allObjects: [],
currentFont: 'Courier',
@@ -375,7 +385,7 @@ export default {
}
try {
await this.addPDF(this.initFileSrc)
- this.selectedPageIndex = 0
+ this.currentPage = 0
fetchFont(this.currentFont)
this.narrowEnlargeShow = true
this.initTextField()
@@ -390,17 +400,17 @@ export default {
}
},
initTextField() {
- if (this.selectedPageIndex < 0 || this.initTextFields === null || this.initTextFields.length === 0) {
+ if (this.currentPage < 0 || this.initTextFields === null || this.initTextFields.length === 0) {
return
}
for (let i = 0; i < this.pages.length; i++) {
- this.selectedPageIndex = i
+ this.currentPage = i
for (let j = 0; j < this.initTextFields.length; j++) {
const text = this.initTextFields[j]
- this.addTextField(text, 0, j * 60, this.selectedPageIndex)
+ this.addTextField(text, 0, j * 60, this.currentPage)
}
}
- this.selectedPageIndex = 0
+ this.currentPage = 0
const checker = setInterval(() => {
if (this.$refs.textItem.length === this.initTextFields.length * this.pages.length) {
document.getElementById('pdfBody').dispatchEvent(new MouseEvent('mousedown', {
@@ -414,11 +424,11 @@ export default {
},
async initImages() {
- if (this.selectedPageIndex < 0) {
+ if (this.currentPage < 0) {
return
}
for (let i = 0; i < this.pages.length; i++) {
- this.selectedPageIndex = i
+ this.currentPage = i
let y = 0
if (this.initImageUrls !== null && this.initImageUrls.length !== 0) {
// Need to initialize pictures
@@ -437,7 +447,7 @@ export default {
await this.addImage(await res.blob(), 0, (y + 1) * 100, 0.4, true)
}
}
- this.selectedPageIndex = 0
+ this.currentPage = 0
},
onFinishDrawingCanvas(e) {
@@ -462,11 +472,11 @@ export default {
const files = e.target.files || (e.dataTransfer && e.dataTransfer.files)
const file = files[0]
if (!file || file.type !== 'application/pdf') return
- this.selectedPageIndex = -1
+ this.currentPage = -1
try {
await this.addPDF(file)
this.narrowEnlargeShow = true
- this.selectedPageIndex = 0
+ this.currentPage = 0
} catch (e) {
console.log(e)
}
@@ -516,7 +526,7 @@ export default {
},
async onUploadImage(e) {
const file = e.target.files[0]
- if (file && this.selectedPageIndex >= 0) {
+ if (file && this.currentPage >= 0) {
await this.addImage(file)
}
e.target.value = null
@@ -536,7 +546,7 @@ export default {
const { canvasWidth, canvasHeight }
= this.$refs[
- `page${this.selectedPageIndex}`
+ `page${this.currentPage}`
][0].getCanvasMeasurement()
const object = {
@@ -560,12 +570,12 @@ export default {
}
},
onAddTextField() {
- if (this.selectedPageIndex >= 0) {
+ if (this.currentPage >= 0) {
this.addTextField()
}
},
- addTextField(text = 'Please enter here', x = 0, y = 0, currentPage = this.selectedPageIndex) {
+ addTextField(text = 'Please enter here', x = 0, y = 0, currentPage = this.currentPage) {
const id = this.genID()
fetchFont(this.currentFont)
const object = {
@@ -584,7 +594,7 @@ export default {
},
onAddDrawing() {
- if (this.selectedPageIndex >= 0) {
+ if (this.currentPage >= 0) {
this.addingDrawing = true
}
},
@@ -607,7 +617,7 @@ export default {
addObject(object) {
this.allObjects = this.allObjects.map((objects, pIndex) =>
- pIndex === this.selectedPageIndex ? [...objects, object] : objects,
+ pIndex === this.currentPage ? [...objects, object] : objects,
)
},
@@ -617,13 +627,9 @@ export default {
this.currentFont = name
},
- selectPage(index) {
- this.selectedPageIndex = index
- },
-
updateObject(objectId, payload) {
this.allObjects = this.allObjects.map((objects, pIndex) =>
- pIndex === (payload.currentPage !== undefined ? payload.currentPage : this.selectedPageIndex)
+ pIndex === (payload.currentPage !== undefined ? payload.currentPage : this.currentPage)
? objects.map(object =>
object.id === objectId ? { ...object, ...payload } : object,
)
@@ -633,7 +639,7 @@ export default {
deleteObject(objectId) {
this.allObjects = this.allObjects.map((objects, pIndex) =>
- pIndex === this.selectedPageIndex
+ pIndex === this.currentPage
? objects.filter(object => object.id !== objectId)
: objects,
)
@@ -680,7 +686,10 @@ export default {
this.saving = false
}
},
- },
+ onPageChange(page){
+ this.currentPage = page
+ }
+ }
}