Please give a brief summary of your issue: Unable to get the page numbers for specific text in the PDF
Please describe your issue and provide steps to reproduce it:
In Web Project using WebViewer to display documents with different view depending on which API i’m using, i’m creating a custom ToC based on document’s Header sections (h1,h2,etc or ##, ###) and need to find their page numbers so that to display them in that ToC and use setCurrentPage to navigate to that page.
Hi Luke, thanks for your answer. Do I need to specify the header pattern since i was getting data in .md format that’s being converted to PDF in WebViewer and wanted to display header texts (like ##, ###, etc) in my custom ToC sidepanel
Hi luke, i know that there is outlines implementation but i still wanted to do separate side panel that extracts headers from coming .md file and generate them as TOC but I’m having issue with it’s page numbers since when converted to PDF, it adds white-spaces and paddings and becomes different from original .md file page number.
So, how to actually, find the page numbers of these header texts in PDF and use their page number to put as tags when clicked it should navigate to that page?
sample snippet of my code:
React.useEffect(() => {
if (webViewerInstance) {
const { documentViewer } = webViewerInstance.Core;
documentViewer.addEventListener('documentLoaded', async () => {
const pageNumbers: number[] = [];
await documentViewer.textSearchInit(
'##\\s.*', // search for headers
webViewerInstance.Core.Search.Mode.PAGE_STOP | webViewerInstance.Core.Search.Mode.HIGHLIGHT,
{
fullSearch: true,
onResult: (result) => {
if (result.resultCode === webViewerInstance.Core.Search.ResultCode.FOUND) {
// result.pageNum contains the page number of the found header
pageNumbers.push(result.pageNum);
console.log('Found header on page:', result.pageNum);
}
},
}
);
setHeaderPageNumbers(pageNumbers);
});
}
}, [webViewerInstance]);