- Generazione PDF e per Stampa

This commit is contained in:
Surya Paolo
2025-05-12 16:33:58 +02:00
parent 6ed648f8b3
commit ef48d7e741
9 changed files with 142 additions and 79 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

View File

@@ -38,7 +38,7 @@ const firstPage = {
path: '/',
materialIcon: 'home',
name: 'pages.home',
component: () => import('@src/root/mainview/mainview/home.vue'),
component: () => import('@src/root/mainview/mainview.vue'),
reqauth: false,
inmenu: true,
infooter: true,

View File

@@ -767,6 +767,11 @@ export default defineComponent({
globalStore.myselector.data = { _id: 0, comune: '' }
}
} else {
const rec = searchList.value.find((rec) => rec.table === table && rec.bool)
if (rec) {
tools.setCookieBool(tools.COOK_SEARCH + costanti.FILTER_SEP + table + costanti.FILTER_SEP + rec.key, rec.value)
}
}
@@ -2839,7 +2844,7 @@ export default defineComponent({
}
function getisDettagliByCatalog() {
const rec = searchList.value.find((myrec) => myrec.table === shared_consts.TABLES_CATALOG && myrec.key === 'dettagli')
const rec = searchList.value.find((myrec) => myrec.table === ('finto_' + myrec.key) && myrec.key === 'dettagli')
if (rec) {
return rec.value
}

View File

@@ -253,7 +253,7 @@
v-else-if="item.type === costanti.FieldType.boolean"
:label="item.label"
v-model="item.value"
@update:model-value="refresh"
@update:model-value="searchval(item.value, item.table)"
color="green"
/>
</div>
@@ -923,7 +923,7 @@
v-else-if="item.type === costanti.FieldType.boolean"
:label="item.label"
v-model="item.value"
@update:model-value="refresh"
@update:model-value="searchval(item.value, item.table)"
color="green"
/>
</span>

View File

@@ -38,7 +38,7 @@ const firstPage = {
path: '/',
materialIcon: 'home',
name: 'pages.home',
component: () => import('@src/root/mainview/mainview/home.vue'),
component: () => import('@src/root/mainview/mainview.vue'),
reqauth: false,
inmenu: true,
infooter: true,

View File

@@ -4482,6 +4482,14 @@ export const tools = {
return def
}
},
getCookieBool(mytok: any, def?: any) {
const ris = Cookies.get(mytok)
if (ris === 'null')
return def
return ris === '1' ? true : false
},
localStSetItem(item: string, value: string) {
if (localStorage.getItem('cookie-id') === 'decline')
@@ -4502,6 +4510,13 @@ export const tools = {
return Cookies.set(mytok, value)
},
setCookieBool(mytok: any, valbool: boolean) {
if (localStorage.getItem('cookie-id') === 'decline')
return null
return Cookies.set(mytok, valbool ? '1' : '0')
},
removeCookie(mytok: any) {
return Cookies.remove(mytok)
},
@@ -9846,11 +9861,13 @@ export const tools = {
icon: 'fas fa-user'
},
{
table: 'finto_active',
visible: !this.isUtente(),
label: 'Pubblicati OnLine',
key: 'active',
type: costanti.FieldType.boolean,
value: this.isUtente() ? true: this.getCookie(this.COOK_SEARCH + costanti.FILTER_SEP + shared_consts.TABLES_CATALOG + costanti.FILTER_SEP + 'active', true),
value: this.isUtente() ? true: this.getCookieBool(this.COOK_SEARCH + costanti.FILTER_SEP + 'finto_active' + costanti.FILTER_SEP + 'active', true),
bool: true,
keycookie: '',
addall: true,
arrvalue: [],
@@ -9859,11 +9876,13 @@ export const tools = {
icon: 'fas fa-globe'
},
{
table: 'finto_isCatalogoGenerale',
visible: !this.isUtente(),
label: 'Solo Catalogo Generale',
key: 'isCatalogoGenerale',
type: costanti.FieldType.boolean,
value: this.isUtente() ? isCatalogoGenerale: this.getCookie(this.COOK_SEARCH + costanti.FILTER_SEP + shared_consts.TABLES_CATALOG + costanti.FILTER_SEP + 'isCatalogoGenerale', isCatalogoGenerale),
value: this.isUtente() ? isCatalogoGenerale: this.getCookieBool(this.COOK_SEARCH + costanti.FILTER_SEP + 'finto_isCatalogoGenerale' + costanti.FILTER_SEP + 'isCatalogoGenerale', isCatalogoGenerale),
bool: true,
keycookie: '',
addall: true,
arrvalue: [],
@@ -9874,11 +9893,12 @@ export const tools = {
{
visible: !this.isUtente(),
label: 'Dettagli',
table: shared_consts.TABLES_CATALOG,
table: 'finto_dettagli',
key: 'dettagli',
bool: true,
notinsearch: true, // non usarlo nella ricerca filtro
type: costanti.FieldType.boolean,
value: this.isUtente() ? false: this.getCookie(this.COOK_SEARCH + costanti.FILTER_SEP + shared_consts.TABLES_CATALOG + costanti.FILTER_SEP + 'dettagli', true),
value: this.isUtente() ? false: this.getCookieBool(this.COOK_SEARCH + costanti.FILTER_SEP + 'finto_dettagli' + costanti.FILTER_SEP + 'dettagli', true),
keycookie: '',
addall: true,
arrvalue: [],

View File

@@ -2538,6 +2538,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
file_out: string = '',
print: boolean = false,
optcatalogo: IOptCatalogo | null = null,
salvasufiledascaricare
) {
try {
if (!pdfFile) {
@@ -2567,16 +2568,20 @@ export const useGlobalStore = defineStore('GlobalStore', {
const response = await this.execConvertPDF(formData);
if (response) {
const blob = new Blob([response], { type: 'application/pdf' });
const downloadUrl = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = downloadUrl;
link.setAttribute('download', filenameToDownload);
document.body.appendChild(link);
link.click();
link.remove();
if (salvasufiledascaricare) {
const blob = new Blob([response], { type: 'application/pdf' });
const downloadUrl = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = downloadUrl;
link.setAttribute('download', filenameToDownload);
document.body.appendChild(link);
link.click();
link.remove();
window.URL.revokeObjectURL(downloadUrl);
window.URL.revokeObjectURL(downloadUrl);
} else {
return response
}
} else {
console.error('No data returned from the server.');
}

View File

@@ -1747,66 +1747,85 @@ export default defineComponent({
const pages = document.querySelectorAll(pagesSelector);
const pdfs = [];
for (let i = 0; i < pages.length; i++) {
const page = pages[i];
try {
for (let i = 0; i < pages.length; i++) {
const page = pages[i];
// Nascondi altre pagine
pages.forEach((p) => p.classList.add('hidden'));
page.classList.remove('hidden');
// Nascondi altre pagine
pages.forEach((p) => p.classList.add('hidden'));
page.classList.remove('hidden');
await new Promise((resolve) => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 100));
// Genera singolo PDF
const pdfBlob = await new Promise<Blob | null>((resolve) => {
html2pdf()
.set(opt)
.from(page)
.toPdf()
.output('blob', { compress: true })
.then(resolve)
.catch(() => resolve(null));
});
// Genera singolo PDF
const pdfBlob = await new Promise<Blob | null>((resolve) => {
html2pdf()
.set(opt)
.from(page)
.toPdf()
.output('blob', { compress: true })
.then(resolve)
.catch(() => resolve(null));
});
if (pdfBlob) {
pdfs.push(pdfBlob);
if (pdfBlob) {
pdfs.push(pdfBlob);
}
}
// Unisci PDF
const finalPdf = await PDFDocument.create();
for (const blob of pdfs) {
const pdf = await PDFDocument.load(await blob.arrayBuffer());
const copiedPages = await finalPdf.copyPages(pdf, pdf.getPageIndices());
copiedPages.forEach((p) => finalPdf.addPage(p));
}
const finalPdfBytes = await finalPdf.save(); // Uint8Array
// ✅ Conversione in Blob
const blob = new Blob([finalPdfBytes], { type: 'application/pdf' });
// ✅ Download
if (salvasufiledascaricare) {
saveAs(blob, opt.filename);
} else {
// ✅ Crea un oggetto File da Blob
const pdfFile = new File([blob], 'report.pdf', { type: 'application/pdf' });
// Converti il file appena generato
const ris = await globalStore.convertPdf(
pdfFile,
widthpdf.value,
heightpdf.value,
compressionepdf.value,
dir_out,
file_out,
true,
optcatalogo.value,
salvasufiledascaricare
);
if (ris) {
const catalog = getCatalogoByMyPage.value;
if (ris.pdf_generato) {
catalog.pdf_generato = ris.pdf_generato;
catalog.data_generato = tools.getDateNow();
}
if (ris.pdf_generato_stampa) {
catalog.pdf_generato_stampa = ris.pdf_generato_stampa;
catalog.data_generato_stampa = tools.getDateNow();
}
await saveCatalog();
}
}
// Ripristina visibilità
pages.forEach((p) => p.classList.remove('hidden'));
} catch (e) {
console.error('Err', e.message);
}
// Unisci PDF
const finalPdf = await PDFDocument.create();
for (const blob of pdfs) {
const pdf = await PDFDocument.load(await blob.arrayBuffer());
const copiedPages = await finalPdf.copyPages(pdf, pdf.getPageIndices());
copiedPages.forEach((p) => finalPdf.addPage(p));
}
const finalPdfBytes = await finalPdf.save(); // Uint8Array
// ✅ Conversione in Blob
const blob = new Blob([finalPdfBytes], { type: 'application/pdf' });
// ✅ Download
if (salvasufiledascaricare) {
saveAs(blob, opt.filename);
} else {
// ✅ Crea un oggetto File da Blob
const pdfFile = new File([blob], 'report.pdf', { type: 'application/pdf' });
// Converti il file appena generato
await globalStore.convertPdf(
pdfFile,
widthpdf.value,
heightpdf.value,
compressionepdf.value,
dir_out,
file_out,
true,
optcatalogo.value,
);
}
// Ripristina visibilità
pages.forEach((p) => p.classList.remove('hidden'));
}
const generatePDF = async () => {
@@ -1860,12 +1879,7 @@ export default defineComponent({
const element = document.getElementById('pdf-content');
const opt = {
margin: [
defaultMargin,
defaultMargin,
defaultMargin,
defaultMargin,
],
margin: [defaultMargin, defaultMargin, defaultMargin, defaultMargin],
filename: myfile,
image: {
type: 'jpeg',
@@ -1890,7 +1904,7 @@ export default defineComponent({
// a4: [595.28, 841.89]
if (true) {
await generateLargePDF(opt, '.pdf-section', false, 'upload/', file_out);
await generateLargePDF(opt, '.pdf-section', false, 'upload/cataloghi/', file_out);
} else {
await html2pdf().set(opt).from(element).save();
}

View File

@@ -432,6 +432,25 @@
:color="optcatalogo.indebug ? `positive` : 'primary'"
></q-btn>
</div>
<div v-if="getCatalogoByMyPage.pdf_generato" class="column justify-center q-ma-sm q-pa-sm">
<div >
PDF:
<a :href="tools.getHost() + getCatalogoByMyPage.pdf_generato" target="_blank" v-if="getCatalogoByMyPage.pdf_generato" class="text-bold">
{{tools.getHost() + getCatalogoByMyPage.pdf_generato}}
</a>
<span v-else>-</span>
<br>(Generato il {{ tools.getstrDateTime(getCatalogoByMyPage.data_generato)}})
</div>
<br>
<div>
PDF Stampa:
<a :href="tools.getHost() + getCatalogoByMyPage.pdf_generato_stampa" target="_blank" v-if="getCatalogoByMyPage.pdf_generato_stampa" class="text-bold">
{{tools.getHost() + getCatalogoByMyPage.pdf_generato_stampa}}
</a>
<span v-else>-</span>
<br>(Generato il {{ tools.getstrDateTime(getCatalogoByMyPage.data_generato_stampa) }})
</div>
</div>
</q-tab-panel>
<q-tab-panel name="ricerca">
<div