From e660e3b13c6fcc27222cc4fa5222cf1dcba3fe49 Mon Sep 17 00:00:00 2001 From: CarliPinell Date: Tue, 14 Oct 2025 09:11:39 -0400 Subject: [PATCH 1/2] Solving issue reported with Print pdf screen --- .../js/requests/components/screenDetail.vue | 242 ++++++++++++++---- 1 file changed, 193 insertions(+), 49 deletions(-) diff --git a/resources/js/requests/components/screenDetail.vue b/resources/js/requests/components/screenDetail.vue index eb4af674c1..500b453cdd 100644 --- a/resources/js/requests/components/screenDetail.vue +++ b/resources/js/requests/components/screenDetail.vue @@ -1,27 +1,26 @@ @@ -106,13 +104,10 @@ } }, printablePages() { - const pages = [0]; - if (this.rowData.config instanceof Array) { - this.rowData.config.forEach(page => { - this.findPagesInNavButtons(page, pages); - }); - } - return pages; + // New strategy: always return only page 0 + // This avoids any problem with the detection of pages + console.log('🔍 printablePages devuelve: [0] (forzado)'); + return [0]; }, component() { if ('renderComponent' in this.rowData.config) { @@ -157,11 +152,10 @@ }, loadPages() { this.$nextTick(() => { - this.$refs.print.forEach((page, index) => { - if (page.setCurrentPage) { - page.setCurrentPage(this.printablePages[index]); - } - }); + if (this.$refs.print && this.$refs.print.setCurrentPage) { + // Force page 0 + this.$refs.print.setCurrentPage(0); + } }); }, findPagesInNavButtons(object, found = []) { @@ -175,7 +169,72 @@ }); } else if (object.config && object.config.event === 'pageNavigate' && object.config.eventData) { const page = parseInt(object.config.eventData); - found.indexOf(page) === -1 ? found.push(page) : null; + if (found.indexOf(page) === -1) { + found.push(page); + } + } + // Also search in the structure of pages of the form + if (object.component === 'FormMultiColumn' && object.config && object.config.pages) { + object.config.pages.forEach((page, index) => { + if (found.indexOf(index) === -1) { + found.push(index); + } + }); + } + // Search in components that can have pagination + if (object.component === 'FormPage' && object.config && object.config.page) { + const page = parseInt(object.config.page); + if (found.indexOf(page) === -1) { + found.push(page); + } + } + }, + hasRealContent(item) { + // Verify if the element has real content that should be shown + if (!item) return false; + + // If it is a component that should not be shown in print, it does not have content + if (item.component === 'FormButton' || item.component === 'FileUpload' || item.component === 'PhotoVideo') { + return false; + } + + // If it has items, verify if any of them has content + if (item.items && item.items.length > 0) { + return item.items.some(child => this.hasRealContent(child)); + } + + // If it is an array, verify if any of them has content + if (item instanceof Array) { + return item.some(child => this.hasRealContent(child)); + } + + // If it has a valid component, it has content + if (item.component && item.component !== 'FormButton' && item.component !== 'FileUpload' && item.component !== 'PhotoVideo') { + return true; + } + + return false; + }, + findAllPagesWithContent(config, pages) { + if (config instanceof Array) { + config.forEach((item, index) => { + if (this.hasRealContent(item)) { + if (pages.indexOf(index) === -1) { + pages.push(index); + } + } + // Search recursively in the items + if (item.items) { + this.findAllPagesWithContent(item.items, pages); + } + }); + } else if (config.items) { + this.findAllPagesWithContent(config.items, pages); + } else if (config.component && config.component !== 'FormButton' && config.component !== 'FileUpload' && config.component !== 'PhotoVideo') { + // If it is a valid component, include page 0 + if (pages.indexOf(0) === -1) { + pages.push(0); + } } }, /** @@ -212,7 +271,25 @@ ProcessMaker.EventBus.$emit('form-data-updated', data); }, print() { - window.print(); + // Ensure that the content is rendered completely before printing + this.$nextTick(() => { + // Force the re-rendering of all components + this.$forceUpdate(); + + // Small delay to ensure that the DOM is updated + setTimeout(() => { + // Apply specific styles for print + document.body.classList.add('printing'); + + // Open the print dialog + window.print(); + + // Clean the class after a time + setTimeout(() => { + document.body.classList.remove('printing'); + }, 1000); + }, 100); + }); return true; } }, @@ -230,3 +307,70 @@ } + + From 32da9944b2a544cb749cf7dfdfa49529402c628c Mon Sep 17 00:00:00 2001 From: CarliPinell Date: Tue, 14 Oct 2025 15:02:18 -0400 Subject: [PATCH 2/2] removing console.log --- resources/js/requests/components/screenDetail.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/js/requests/components/screenDetail.vue b/resources/js/requests/components/screenDetail.vue index 500b453cdd..576c475a64 100644 --- a/resources/js/requests/components/screenDetail.vue +++ b/resources/js/requests/components/screenDetail.vue @@ -106,7 +106,6 @@ printablePages() { // New strategy: always return only page 0 // This avoids any problem with the detection of pages - console.log('🔍 printablePages devuelve: [0] (forzado)'); return [0]; }, component() {