diff --git a/composables/useWorkingTimePDFGenerator.js b/composables/useWorkingTimePDFGenerator.js index 000d937..a3d2404 100644 --- a/composables/useWorkingTimePDFGenerator.js +++ b/composables/useWorkingTimePDFGenerator.js @@ -160,29 +160,66 @@ export const useCreateWorkingTimesPdf = async (input,backgroundSourceBuffer) => let rowHeight = 115 - input.times.forEach(time => { - pages[pageCounter - 1].drawText(`${dayjs(time.startDate).format("HH:mm DD.MM.YY")}`,{ - x: getCoordinatesForPDFLib(20,rowHeight,pages[pageCounter -1]).x, - y: getCoordinatesForPDFLib(20,rowHeight,pages[pageCounter -1]).y, - size: 10, + + let splitted = [] + + let reversedInput = input.times.slice().reverse() + + const splittedLength = Math.floor((reversedInput.length - 25) / 40) + + splitted.push(reversedInput.slice(0,25)) + + let lastIndex = 25 + for (let i = 0; i < splittedLength; ++i ) { + splitted.push(reversedInput.slice(lastIndex, lastIndex + (i + 1) * 40)) + lastIndex = lastIndex + (i + 1) * 40 + 1 + } + + splitted.push(reversedInput.slice(lastIndex, reversedInput.length)) + + + splitted.forEach((chunk,index) => { + if(index > 0) { + const page = pdfDoc.addPage() + + page.drawPage(secondPageBackground, { + x: 0, + y: 0, + }) + + pages.push(page) + pageCounter++ + rowHeight = 20 + + } + + chunk.forEach(time => { + pages[pageCounter - 1].drawText(`${dayjs(time.startDate).format("HH:mm DD.MM.YY")}`,{ + x: getCoordinatesForPDFLib(20,rowHeight,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(20,rowHeight,pages[pageCounter -1]).y, + size: 10, + }) + + pages[pageCounter - 1].drawText(`${dayjs(time.endDate).format("HH:mm DD.MM.YY")}`,{ + x: getCoordinatesForPDFLib(60,rowHeight,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(60,rowHeight,pages[pageCounter -1]).y, + size: 10, + }) + + pages[pageCounter - 1].drawText(`${getDuration(time).composed}`,{ + x: getCoordinatesForPDFLib(100,rowHeight,pages[pageCounter -1]).x, + y: getCoordinatesForPDFLib(100,rowHeight,pages[pageCounter -1]).y, + size: 10, + }) + + rowHeight += 6 + }) - - pages[pageCounter - 1].drawText(`${dayjs(time.endDate).format("HH:mm DD.MM.YY")}`,{ - x: getCoordinatesForPDFLib(60,rowHeight,pages[pageCounter -1]).x, - y: getCoordinatesForPDFLib(60,rowHeight,pages[pageCounter -1]).y, - size: 10, - }) - - pages[pageCounter - 1].drawText(`${getDuration(time).composed}`,{ - x: getCoordinatesForPDFLib(100,rowHeight,pages[pageCounter -1]).x, - y: getCoordinatesForPDFLib(100,rowHeight,pages[pageCounter -1]).y, - size: 10, - }) - - rowHeight += 6 - }) + + + uri.value = await pdfDoc.saveAsBase64({dataUri: true}) }