[英]PDFKIT - NODEJS: How to get current page number?
我正在為 pdf 代使用 pdfkit 模塊 (nodejs)。 我需要根據某些條件切換頁面並將數據寫入文件。 切換頁面寫入數據后,根據內容長度跳轉到另一頁。 我需要找到當前頁碼來構建邏輯。 eg:(有10頁,如果把writer/process切換到Page 4寫了一些內容,process會根據content type跳到Page 5 / 6,我想知道哪個是當前process page)May我知道如何獲取當前頁碼? TIA!
我遇到了同樣的問題並找到了解決方法。
getCurrentPageNumber(): number {
const pageBuffer: PDFKit.PDFPage[] = (this.doc as any)._pageBuffer
const currentPage = this.doc.page
let currentPageNumber: number | null = null
pageBuffer.forEach((page: PDFKit.PDFPage, i: number) => {
if (page === currentPage) {
currentPageNumber = i
}
})
if (currentPageNumber === null) {
throw new Error('Unable to get current page number')
}
return currentPageNumber
}
我在 repo https://github.com/foliojs/pdfkit/issues/1408上提出了一個功能請求
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.