- Creazione PDF Temporanei (Generati)

- Assegnazione di questi su PDF OnLine e PDF per Stampa
This commit is contained in:
Surya Paolo
2025-05-12 18:43:25 +02:00
parent 89bbda59b3
commit 85faf11d27
4 changed files with 279 additions and 137 deletions

View File

@@ -1727,12 +1727,32 @@ export default defineComponent({
optcatalogo.value.indebug = !optcatalogo.value.indebug;
}
const preparePDF = async () => {
optcatalogo.value.generazionePDFInCorso = true;
optcatalogo.value.areadistampa!.scale = optcatalogo.value.areadistampa!.scale_printable;
const preparePDF = () => {
$q.dialog({
message: 'Generare il PDF ?',
ok: {
label: t('dialog.yes'),
push: true,
},
cancel: {
label: t('dialog.cancel'),
},
title: 'Generazione PDF',
}).onOk(async () => {
optcatalogo.value.generazionePDFInCorso = true;
optcatalogo.value.areadistampa!.scale = optcatalogo.value.areadistampa!.scale_printable;
setTimeout(() => {
optcatalogo.value.generazionePDFInCorso = true;
setTimeout(() => {
generatePDF();
}, 500);
}, 500);
});
};
const terminaPDF = async () => {
const terminaPDF = () => {
optcatalogo.value.generazionePDFInCorso = false;
optcatalogo.value.areadistampa!.scale = 1;
};
@@ -1831,103 +1851,143 @@ export default defineComponent({
const generatePDF = async () => {
await nextTick();
$q.dialog({
message: 'Generare il PDF ?',
ok: {
label: t('dialog.yes'),
push: true,
},
cancel: {
label: t('dialog.cancel'),
},
title: 'Generazione PDF',
}).onOk(async () => {
$q.loading.show({
message: 'Caricamento immagini e generazione PDF in corso...',
});
try {
let defaultMargin = 0.1;
if (optcatalogo.value.printable) {
defaultMargin = 0;
} else {
defaultMargin = 0;
}
const unit = optcatalogo.value.areadistampa!.unit;
let myformat = { ...optcatalogo.value.areadistampa!.format };
const scale = tools.getScale(optcatalogo.value);
const scalecanvas = optcatalogo.value.areadistampa!.scalecanvas;
if (tools.isObject(myformat) && scale > 0) {
} else {
myformat = [210, 297];
}
const formatwidth = myformat[0] * scale;
const formatheight = myformat[1] * scale;
let myfile = getPdfFilename();
// myfile += '_' + tools.getDateYYYYMMDD_Today();
myfile += '.pdf';
let file_out = myfile;
const element = document.getElementById('pdf-content');
const opt = {
margin: [defaultMargin, defaultMargin, defaultMargin, defaultMargin],
filename: myfile,
image: {
type: 'jpeg',
quality: 0.98,
},
html2canvas: {
scale: scalecanvas,
useCORS: true,
letterRendering: true,
},
jsPDF: {
unit: unit,
format: [formatwidth, formatheight],
orientation: optcatalogo.value.areadistampa!.orientation,
compress: optcatalogo.value.areadistampa!.compress,
},
enableLinks: true,
pagebreak: { mode: 'avoid-all', before: '.card-page' },
};
console.log('opt di stampa', opt);
// a4: [595.28, 841.89]
if (true) {
await generateLargePDF(opt, '.pdf-section', false, 'upload/cataloghi/', file_out);
} else {
await html2pdf().set(opt).from(element).save();
}
optcatalogo.value.generazionePDFInCorso = false;
optcatalogo.value.areadistampa!.scale = 1;
$q.loading.hide();
$q.notify({
color: 'positive',
message: 'PDF generato con successo!',
icon: 'check',
});
} catch (error) {
$q.loading.hide();
$q.notify({
color: 'negative',
message: 'Errore nella generazione del PDF',
icon: 'error',
});
console.error('Errore nella generazione del PDF:', error);
}
$q.loading.show({
message: 'Caricamento immagini e generazione PDF in corso...',
});
try {
let defaultMargin = 0.1;
if (optcatalogo.value.printable) {
defaultMargin = 0;
} else {
defaultMargin = 0;
}
const unit = optcatalogo.value.areadistampa!.unit;
let myformat = { ...optcatalogo.value.areadistampa!.format };
const scale = tools.getScale(optcatalogo.value);
const scalecanvas = optcatalogo.value.areadistampa!.scalecanvas;
if (tools.isObject(myformat) && scale > 0) {
} else {
myformat = [210, 297];
}
const formatwidth = myformat[0] * scale;
const formatheight = myformat[1] * scale;
let myfile = getPdfFilename();
// myfile += '_' + tools.getDateYYYYMMDD_Today();
myfile += '.pdf';
let file_out = myfile;
const element = document.getElementById('pdf-content');
const opt = {
margin: [defaultMargin, defaultMargin, defaultMargin, defaultMargin],
filename: myfile,
image: {
type: 'jpeg',
quality: 0.98,
},
html2canvas: {
scale: scalecanvas,
useCORS: true,
letterRendering: true,
},
jsPDF: {
unit: unit,
format: [formatwidth, formatheight],
orientation: optcatalogo.value.areadistampa!.orientation,
compress: optcatalogo.value.areadistampa!.compress,
},
enableLinks: true,
pagebreak: { mode: 'avoid-all', before: '.card-page' },
};
console.log('opt di stampa', opt);
// a4: [595.28, 841.89]
if (true) {
await generateLargePDF(opt, '.pdf-section', false, 'upload/cataloghi/', file_out);
} else {
await html2pdf().set(opt).from(element).save();
}
optcatalogo.value.generazionePDFInCorso = false;
optcatalogo.value.areadistampa!.scale = 1;
$q.loading.hide();
$q.notify({
color: 'positive',
message: 'PDF generato con successo!',
icon: 'check',
});
} catch (error) {
$q.loading.hide();
$q.notify({
color: 'negative',
message: 'Errore nella generazione del PDF',
icon: 'error',
});
console.error('Errore nella generazione del PDF:', error);
}
};
const pubblicaPDF = async () => {
const catalog = getCatalogoByMyPage.value;
const ris = await globalStore.execOnlinePDF({ id_catalog: catalog._id, stampa: false });
if (ris) {
if (ris.catalog?.pdf_online) {
catalog.pdf_online = ris.catalog.pdf_online;
catalog.data_online = ris.catalog.data_online;
}
$q.notify({
color: 'positive',
message: 'PDF inviato ONLINE!',
icon: 'check',
});
} else {
$q.loading.hide();
$q.notify({
color: 'negative',
message: "Errore nell'invio del PDF OnLine",
icon: 'error',
});
}
};
const pubblicaPDFStampa = async () => {
const catalog = getCatalogoByMyPage.value;
const ris = await globalStore.execOnlinePDF({ id_catalog: catalog._id, stampa: true });
if (ris) {
if (ris.catalog.pdf_online_stampa) {
catalog.pdf_online_stampa = ris.catalog.pdf_online_stampa;
catalog.data_online_stampa = ris.catalog.data_online_stampa;
}
$q.notify({
color: 'positive',
message: 'PDF STAMPA inviato ONLINE!',
icon: 'check',
});
} else {
$q.loading.hide();
$q.notify({
color: 'negative',
message: "Errore nell'invio del PDF STAMPA OnLine",
icon: 'error',
});
}
// await saveCatalog();
};
onMounted(mounted);
@@ -2007,6 +2067,8 @@ export default defineComponent({
getPdfFilename,
filtroStrApplicato,
getCollane,
pubblicaPDF,
pubblicaPDFStampa,
};
},
});