async countPptxSlides(file) {
const zip = new JSZip()
const zipFile = await zip.loadAsync(file)
const presentationEntry = Object.values(zipFile.files).find(file => file.name === 'ppt/presentation.xml')
if (!presentationEntry) {
throw new Error('Failed to find presentation.xml file in PPTX archive')
}
const presentationXml = await zipFile.file(presentationEntry.name).async('string')
const parser = new DOMParser()
const presentationDoc = parser.parseFromString(presentationXml, 'application/xml')
const slideCount = presentationDoc.getElementsByTagName('p:sldId').length
this.form.cpage = slideCount
},
async countPdfPages(file) {
const pdfBytes = await file.arrayBuffer()
const pdfDoc = await PDFDocument.load(pdfBytes)
const pageCount = pdfDoc.getPageCount()
this.form.cpage = pageCount
},
function write_zip_type(wb, opts) {
var o = opts||{};
style_builder = new StyleBuilder(opts);
var z = write_zip(wb, o);
try {
switch(o.type) {
case "base64": return z.generate({type:"base64"});
case "binary": return z.generate({type:"string"});
case "buffer": return z.generate({type:"nodebuffer"});
case "file": return _fs.writeFileSync(o.file, z.generate({type:"nodebuffer"}));
default: throw new Error("Unrecognized type " + o.type);
}
} catch (error) {
switch(o.type) {
case "base64": return z.generateAsync({type:"base64"}).then(res => {
// console.log(res)
return res
});
case "binary": return z.generateAsync({type:"string"}).then( res => {
// console.log(res)
return res
});
case "buffer": return z.generateAsync({type:"nodebuffer"}).then( res => {
// console.log(res)
return res
});
case "file": return z.generateAsync({type:"nodebuffer"}).then( res => {
// console.log(res)
return _fs.writeFileSync(o.file,res)
// return res
});
default: throw new Error("Unrecognized type " + o.type);
}
}
}