Skip to content

Commit 2c84406

Browse files
authored
Merge pull request #168 from LibreSign/fix/only-accept-multiple-files
Fix/only accept multiple files
2 parents 898afe4 + 2c12798 commit 2c84406

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ https://www.npmjs.com/package/@libresign/vue-pdf-editor
3131
:show-line-size-select = 'false' <!--Select the default TRUE of the line spacing-->
3232
:show-font-size-select= 'false' <!--Select the default TRue-->
3333
:show-font-select="false" <!--Select the default true font-->
34-
:show-rename="true" <!--Show the rename column default TRUE-->
34+
:show-rename="true" <!--Show the rename column default TRUE (hidden when multiple PDFs)-->
3535
:show-save-btn="false" <!--Show the saving button default TRUE-->
3636
:save-to-upload="true" <!--False directly download; TRUE trigger onsave2upload event default FALSe->
37-
:init-file-src="'【pdf url】'" <!--Initialization file address-->
38-
:init-file=File <!--Initialization file object (supports multiple PDFs when using show-choose-file-btn)-->
39-
:init-file-name="initFileName" <!--Initialized file name-->
37+
:init-files="[File, File, ...]" <!--Array of File objects to initialize with-->
38+
:init-file-names="['name1.pdf', 'name2.pdf', ...]" <!--Array of file names corresponding to initFiles-->
4039
:init-text-fields = "【text array】" <!--Initialized text array-->
4140
:init-image-urls = "【image url array】" <!--Initialized picture array-->
4241
:init-image-scale = "0.2" <!--The zoom level of the initialized picture defaults to 0.2 times the original size-->

examples/App.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
:show-font-select="true"
1515
:show-rename="true"
1616
:show-save-btn="true"
17-
:init-file-src="initFile"
18-
:init-file-name="initFileName"
17+
:init-files="initFiles"
18+
:init-file-names="initFileNames"
1919
:init-text-fields = "this.textFields"
2020
:init-image-urls = "this.imageUrls"
2121
:init-image-scale = "1"
@@ -37,8 +37,8 @@ export default {
3737
name: 'App',
3838
data(){
3939
return {
40-
initFileName: 'test.pdf',
41-
initFile :'',
40+
initFileNames: ['test.pdf'],
41+
initFiles: [],
4242
textFields: ['initial text'],
4343
imageUrls: [],
4444
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@libresign/vue-pdf-editor",
33
"description": "vue2 pdf editor component",
4-
"version": "1.6.2",
4+
"version": "1.6.3",
55
"author": "LibreCode",
66
"private": false,
77
"main": "dist/vue-pdf-editor.umd.js",

src/VuePdfEditor.vue

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,13 @@ export default {
292292
type: Boolean,
293293
default: false,
294294
},
295-
initFileSrc: {
296-
type: String,
297-
default: '',
298-
},
299-
initFile: {
300-
type: [File, Blob, ArrayBuffer],
301-
default: null,
295+
initFiles: {
296+
type: Array,
297+
default: () => [],
302298
},
303-
initFileName: {
304-
type: String,
305-
default: '',
299+
initFileNames: {
300+
type: Array,
301+
default: () => [],
306302
},
307303
initTextFields: {
308304
type: Array,
@@ -415,13 +411,16 @@ export default {
415411
this.scale = parseFloat((this.scale - 0.1).toFixed(1))
416412
},
417413
async init() {
418-
const file = this.initFile || this.initFileSrc
419-
if (!file) {
420-
console.log('init file is not exist')
414+
if (this.initFiles.length === 0) {
415+
console.log('init files do not exist')
421416
return
422417
}
418+
423419
try {
424-
await this.addPDF(file)
420+
for (let i = 0; i < this.initFiles.length; i++) {
421+
const fileName = this.initFileNames[i] || ''
422+
await this.addPDF(this.initFiles[i], fileName)
423+
}
425424
this.selectedDocIndex = 0
426425
this.selectedPageIndex = 0
427426
fetchFont(this.currentFont)
@@ -609,7 +608,7 @@ export default {
609608
this.pdfDocuments = []
610609
this.selectedDocIndex = -1
611610
},
612-
async addPDF(file) {
611+
async addPDF(file, fileName = '') {
613612
try {
614613
// Don't reset if we're adding to existing documents
615614
if (this.pdfDocuments.length === 0) {
@@ -618,8 +617,8 @@ export default {
618617
619618
const originalFile = file
620619
let pdfName = ''
621-
if (this.initFileName && this.pdfDocuments.length === 0) {
622-
pdfName = this.initFileName
620+
if (fileName) {
621+
pdfName = fileName
623622
} else if (file instanceof File && file.name) {
624623
pdfName = file.name
625624
} else {

0 commit comments

Comments
 (0)