Proximity Search Demo

This example demonstrates how to use proximity search to find phrases or terms within a specified word distance in a document. The user is presented with a pre-filled search query in the search dialog and can execute the search to see highlighted results.

// Viewer instance: Represents the PDF viewer instance used for document rendering and interaction. var viewer; // Execute code when the window has fully loaded: window.onload = async function () { //DsPdfViewer.LicenseKey = "***key***"; viewer = new DsPdfViewer('#viewer', { restoreViewStateOnLoad: false }); viewer.addDefaultPanels(); var pdf = "/document-solutions/javascript-pdf-viewer/demos/product-bundles/assets/pdf/wetlands.pdf"; // Open the document and set the zoom mode to 1 (Fit Width): await viewer.open(pdf); viewer.zoom = { mode: 1 }; var findOptions = { Text: 'existence ONEAR(5) "wildlife species"', MatchCase: true, Proximity: true, HighlightAll: true, WholeWord: true }; viewer.plugin.floatingSearchBar.then(f => { f.setOptions(findOptions); f.show(); }); }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Proximity Search</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="./src/styles.css"> <script src="/document-solutions/javascript-pdf-viewer/demos/product-bundles/build/dspdfviewer.js"></script> <script src="/document-solutions/javascript-pdf-viewer/demos/product-bundles/build/wasmSupportApi.js"></script> <script src="/document-solutions/javascript-pdf-viewer/demos/resource/js/init.js"></script> <script src="./src/app.js"></script> </head> <body> <div id="viewer"></div> </body> </html>
#viewer { height: 100%; } #viewer .search-query-control .query-input { width: 300px; }