- aggiornato la visualoizzazione per scaricare il PDF e per aprirlo
This commit is contained in:
@@ -23,7 +23,9 @@ class GenPdf {
|
||||
}
|
||||
|
||||
async launch() {
|
||||
this.browser = await puppeteer.launch();
|
||||
this.browser = await puppeteer.launch({
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
||||
});
|
||||
}
|
||||
|
||||
async close() {
|
||||
@@ -47,23 +49,30 @@ class GenPdf {
|
||||
|
||||
async autoScroll(page) {
|
||||
console.log('inizia a scrollare');
|
||||
|
||||
// Esegui lo scroll fino a quando tutta la pagina non è stata scrollata
|
||||
await page.evaluate(async () => {
|
||||
await new Promise((resolve) => {
|
||||
let totalHeight = 0;
|
||||
console.log('autoScroll...');
|
||||
const distance = 100;
|
||||
const timer = setInterval(() => {
|
||||
const distance = 100; // distanza dello scroll ad ogni intervallo
|
||||
const delay = 40; // tempo di intervallo in ms
|
||||
|
||||
const scroll = async () => {
|
||||
// Esegui lo scroll
|
||||
window.scrollBy(0, distance);
|
||||
totalHeight += distance;
|
||||
|
||||
if (totalHeight >= document.body.scrollHeight) {
|
||||
clearInterval(timer);
|
||||
resolve();
|
||||
// Verifica se è stato scrollato tutto il corpo della pagina
|
||||
if (totalHeight < document.body.scrollHeight) {
|
||||
setTimeout(scroll, delay); // Se non è finito lo scroll, continua
|
||||
} else {
|
||||
resolve(); // Scroll terminato
|
||||
}
|
||||
}, 40);
|
||||
};
|
||||
|
||||
scroll(); // Avvia lo scroll
|
||||
});
|
||||
});
|
||||
console.log(' FINE: autoScroll...');
|
||||
}
|
||||
|
||||
async generatePdfFromUrl(url, filenameOut, options = {}) {
|
||||
@@ -77,7 +86,14 @@ class GenPdf {
|
||||
try {
|
||||
console.log(`caricamento pagina: ${url}`);
|
||||
await page.goto(url, { waitUntil: 'networkidle0' });
|
||||
await tools.attendiNSecondi(5);
|
||||
|
||||
page.on('console', (msg) => {
|
||||
if (msg.type() === 'error') {
|
||||
console.error('Errore nella pagina:', msg.text());
|
||||
}
|
||||
});
|
||||
|
||||
await tools.attendiNSecondi(8);
|
||||
let success = false;
|
||||
let numTentativi1 = 0;
|
||||
while (numTentativi1 < maxTentativi) {
|
||||
@@ -166,9 +182,6 @@ class GenPdf {
|
||||
|
||||
console.log(`PDF finale generato: ${finalFilePath}`);
|
||||
|
||||
if (options.compressione) {
|
||||
}
|
||||
|
||||
return finalFilePath;
|
||||
} catch (error) {
|
||||
console.error('Errore durante generazione PDF:', error);
|
||||
@@ -394,7 +407,12 @@ class GenPdf {
|
||||
const catalog = await Catalog.findById(options.idCatalog);
|
||||
if (catalog) {
|
||||
const url =
|
||||
tools.getHostByIdApp(this.idapp) + '/cataloghi?id=' + catalog._id + '&stampa=' + (stampa ? '1' : '0') + '&hideHeader=1';
|
||||
tools.getHostByIdApp(this.idapp) +
|
||||
'/cataloghi?id=' +
|
||||
catalog._id +
|
||||
'&stampa=' +
|
||||
(stampa ? '1' : '0') +
|
||||
'&hideHeader=1';
|
||||
|
||||
if (url) {
|
||||
const myfilenameout = await this.getPathByPage(catalog.idPageAssigned);
|
||||
@@ -419,6 +437,7 @@ class GenPdf {
|
||||
fileout_compressed: filenamerelative_compressed,
|
||||
filesize: await tools.getSizeFile(fullnamepath),
|
||||
filesize_compressed: await tools.getSizeFile(fullnamepath_compr),
|
||||
error: '',
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Errore durante la generazione del PDF dal catalogo ID:', error);
|
||||
@@ -429,7 +448,7 @@ class GenPdf {
|
||||
};
|
||||
}
|
||||
|
||||
return { fileout: '', filesize: 0 };
|
||||
return { fileout: '', filesize: 0, error: '' };
|
||||
}
|
||||
|
||||
async compressPdf(inputPath, outputPath, compressione = 'printer') {
|
||||
@@ -439,7 +458,7 @@ class GenPdf {
|
||||
const outputFile = path.resolve(outputPath);
|
||||
|
||||
const validQualities = ['screen', 'ebook', 'printer', 'prepress', 'default'];
|
||||
if (!validQualities.includes(compressione)) compressione = 'screen';
|
||||
if (!validQualities.includes(compressione)) compressione = 'screen';
|
||||
|
||||
// Comando Ghostscript per compressione - impostazione per web (/screen)
|
||||
const gsCommand = `gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/${compressione} -dNOPAUSE -dBATCH -dQUIET -sOutputFile="${outputFile}" "${inputFile}"`;
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.2.50
|
||||
1.2.52
|
||||
Reference in New Issue
Block a user