### Download Instant JSON Example File (Link) Source: https://www.nutrient.io/guides/nodejs/json/example-json-file This is a direct link to download an example JSON file used in the Node.js LLM guides. It serves as a sample data structure for developers to reference or utilize in their projects. No specific programming language is required to interact with this link, as it's a standard web hyperlink. ```html Download the [Instant JSON](/assets/nutrient-media/guides/nodejs/files/example.instant.json) file example. ``` -------------------------------- ### Verify Node.js and npm Installation Source: https://www.nutrient.io/sdk/nodejs/getting-started This command verifies the installation of Node.js and npm on your system. It's a prerequisite for proceeding with Node.js project setup. Ensure both return version numbers. ```bash node -v npm -v ``` -------------------------------- ### Share to Claude AI (JavaScript) Source: https://www.nutrient.io/guides/nodejs/troubleshooting/license/add-license-key Creates a link to start a new chat with Claude AI, pre-populated with a prompt related to the current Nutrient documentation page. This facilitates users in seeking assistance or clarification on the documentation from Claude. The link opens in a new tab. ```javascript function x(i) { const t = "https://www.nutrient.io"; const o = window.location.pathname; const r = `I'm looking at this Nutrient documentation: ${t}${o} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`; const s = `https://claude.ai/new?q=${encodeURIComponent(r)}`; window.open(s, "_blank"); } ``` -------------------------------- ### Dropdown Actions Setup (JavaScript) Source: https://www.nutrient.io/guides/nodejs/demo Sets up interactive dropdown menus within the documentation. It iterates through elements with IDs starting with 'markdown-actions-container-' and attaches event listeners to toggle the dropdown visibility. Handles keyboard navigation for accessibility. ```javascript function I(){document.querySelectorAll('\[id^="markdown-actions-container-"\]').forEach(t=>{const o=t.getAttribute("aria-controls");if(!o)return;const e=document.getElementById(o),r=t.querySelector(".arrow-dropdown-icon");if(!e)return;t.addEventListener("click",function(n){n.stopPropagation(),t.getAttribute("aria-expanded")==="true"?s():a()}),t.addEventListener("keydown",function(n){if(n.key==="Enter"||n.key===" ")n.preventDefault(),t.getAttribute("aria-expanded")==="true"?s():a();else if(n.key==="ArrowDown"){n.preventDefault(),a();const c=e.querySelector(".markdown-actions-option");c&&c.focus()}}),e.addEventListener("click",function(n){n.target.closest(".markdown-actions-option")&&(n.preventD ``` -------------------------------- ### Open Claude with Prompt Source: https://www.nutrient.io/guides/nodejs/about/system-compatibility Opens Claude AI in a new tab with a pre-formatted prompt. The prompt guides the AI to assist with understanding the current Nutrient documentation page, including its URL and offering help with explanations, examples, or debugging. ```javascript function x(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`; window.open(`https://claude.ai/new?q=${encodeURIComponent(r)}`,"_blank") } ``` -------------------------------- ### Initialize Sidebar Navigation and Active Link Highlighting (JavaScript) Source: https://www.nutrient.io/guides/nodejs/troubleshooting/license/add-license-key This JavaScript code initializes the sidebar navigation for the Node.js LLM guides. It handles collapsing/expanding folders, highlighting the active link based on the current URL, and applies styles to parent folders. It also sets up click handlers for toggling folder visibility. ```javascript (function(){ const sidenavParent = "/troubleshoot"; /* global sidenavParent */ function normalizeUrl(url) { return url.replace(/\/$/, ""); } function getActiveParent(links, normalizedCurrentPath) { let bestMatch = null; let maxMatchLength = 0; for (const link of links) { const linkHref = normalizeUrl(link.getAttribute("href")); // Check if current path starts with link href (more precise than includes) if (normalizedCurrentPath.startsWith(linkHref)) { if (linkHref.length > maxMatchLength) { maxMatchLength = linkHref.length; bestMatch = link; } } } return bestMatch; } document.addEventListener("DOMContentLoaded", () => { // Make all folders collapsed initially document.querySelectorAll(".folder-content").forEach((content) => { content.classList.add("folder-hidden"); }); // Pathname (ex. /guides/android/viewer/zooming) const currentPath = window.location.pathname; const normalizedCurrentPath = normalizeUrl(currentPath); const links = document.querySelectorAll(".sidebar a"); // Find exact URL match first let exactMatch = Array.from(links).find((link) => { const linkHref = normalizeUrl(link.getAttribute("href")); return linkHref === normalizedCurrentPath; }); // If no exact match, try fallback strategies let parentMatch = null; if (!exactMatch) { if (sidenavParent) { exactMatch = document.querySelector( `.sidebar a[href*="${sidenavParent}"]`, ); } else { parentMatch = getActiveParent(links, normalizedCurrentPath); } } // Apply styles and expand folders based on matches if (exactMatch || parentMatch) { // Only add active class for exact matches if (exactMatch) { exactMatch.classList.add("active"); } // Expand parent folders for either match type let parent = (exactMatch || parentMatch).closest(".folder-content"); while (parent) { parent.classList.remove("folder-hidden"); const folderId = parent.id; const header = document.querySelector(`[data-target="${folderId}"]`); if (header) { // Add active class to parent folder headers header.classList.add("active"); const icon = header.querySelector(".folder-chevron"); icon?.classList.toggle("rotate-icon"); } parent = header?.closest(".folder-content"); } } // Click handlers for folder toggles document.querySelectorAll(".folder-header").forEach((header) => { header.addEventListener("click", () => { const targetId = header.getAttribute("data-target"); const content = document.getElementById(targetId); const chevron = header.querySelector(".folder-chevron"); if (content) { content.classList.toggle("folder-hidden"); chevron?.classList.toggle("rotate-icon"); } }); }); }); })(); ``` -------------------------------- ### Bookmark JSON Schema Example Source: https://www.nutrient.io/guides/nodejs/json/schema/bookmarks An example of an Instant JSON schema for a bookmark that triggers a 'GoToAction'. It includes the action type, page index, a unique ID, an optional name, the bookmark type, and the specification version. ```json { "action": { "pageIndex": 0, "type": "goTo" }, "id": "01F46W3SCC92FG68G597N4VHJD", "name": "A page bookmark", "type": "pspdfkit/bookmark", "v": 1 } ``` -------------------------------- ### Share to ChatGPT (JavaScript) Source: https://www.nutrient.io/guides/nodejs/troubleshooting/license/add-license-key Generates a pre-filled ChatGPT chat link that includes context about the current Nutrient documentation page. This allows users to quickly ask questions or get explanations about the documentation content from ChatGPT. The link is opened in a new tab. ```javascript function v(i) { const t = "https://www.nutrient.io"; const o = window.location.pathname; const r = `I'm looking at this Nutrient documentation: ${t}${o} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`; const s = `https://chatgpt.com/?q=${encodeURIComponent(r)}`; window.open(s, "_blank"); } ``` -------------------------------- ### Initialize Markdown Actions Dropdowns (JavaScript) Source: https://www.nutrient.io/guides/nodejs/intro Initializes the markdown actions dropdowns, setting up event listeners to handle opening and closing the dropdowns via click, keyboard, and focus events. ```javascript document.addEventListener("DOMContentLoaded",()=>{I(),A()});function I(){document.querySelectorAll('\[id^="markdown-actions-container-"\]').forEach(t=>{const o=t.getAttribute("aria-controls");if(!o)return;const e=document.getElementById(o),r=t.querySelector(".arrow-dropdown-icon");if(!e)return;t.addEventListener("click",function(n){n.stopPropagation(),t.getAttribute("aria-expanded")==="true"?s():a()}),t.addEventListener("keydown",function(n){if(n.key==="Enter"||n.key===" ")n.preventDefault(),t.getAttribute("aria-expanded")==="true"?s():a();else if(n.key==="ArrowDown"){n.preventDefault(),a();const c=e.querySelector(".markdown-actions-option");c&&c.focus()}}),e.addEventListener("click",function(n){n.target.closest(".markdown-actions-option")&&(n.preventD ``` -------------------------------- ### Install Nutrient SDK for Node.js Source: https://www.nutrient.io/sdk/nodejs/getting-started Installs the '@nutrient-sdk/node' library into your Node.js project. This command should be run from the root directory of your project. It adds the Nutrient SDK as a dependency in your 'package.json' file. ```bash npm install @nutrient-sdk/node ``` -------------------------------- ### Open ChatGPT with Prompt Source: https://www.nutrient.io/guides/nodejs/about/system-compatibility Opens ChatGPT in a new tab with a pre-formatted prompt. The prompt instructs the AI to help understand the current Nutrient documentation page, providing the URL and offering assistance with explanations, examples, or debugging. ```javascript function v(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`; window.open(`https://chatgpt.com/?q=${encodeURIComponent(r)}`,"_blank") } ``` -------------------------------- ### Initialize Kapa.ai Chatbot Widget with Dynamic Configuration (JavaScript) Source: https://www.nutrient.io/guides/nodejs/json This JavaScript function dynamically creates and configures a Kapa.ai chatbot widget. It reads configuration from a global 'n' object based on the current URL path, allowing for context-specific disclaimers and example questions. The script tag is appended to the document's head to load the widget. ```javascript function u(){ const a=d(),t=document.createElement("script"); t.async=!0,t.src="https://widget.kapa.ai/kapa-widget.bundle.js", t.setAttribute("data-website-id","ec76a086-c5ce-409a-91bb-bee358fdb208"), t.setAttribute("data-project-color","#1A1414"), t.setAttribute("data-text-color","#1A1414"), t.setAttribute("data-modal-override-open-id","nutrient-sdk-docs-ai"), t.setAttribute("data-button-hide","false"), t.setAttribute("data-modal-open-by-default","true"), t.setAttribute("data-user-analytics-fingerprint-enabled","true"), t.setAttribute("data-project-name","Nutrient"), t.setAttribute("data-modal-title","Nutrient AI"), t.setAttribute("data-modal-disclaimer",a.modalDisclaimer), t.setAttribute("data-example-questions",a.exampleQuestions), t.setAttribute("data-modal-disclaimer-bg-color","#EFEBE7"), t.setAttribute("data-modal-disclaimer-text-color","#67594B"), t.setAttribute("data-modal-disclaimer-font-size","14px"), t.setAttribute("data-modal-disclaimer-padding","0.875rem"), t.setAttribute("data-query-input-font-size","1rem"), t.setAttribute("data-query-input-text-color","#1A1414"), t.setAttribute("data-query-input-placeholder-text-color","#67594B"), t.setAttribute("data-query-input-border-color","#1A1414"), t.setAttribute("data-query-input-focus-border-color","#DE9DCC"), t.setAttribute("data-submit-query-button-bg-color","#1A1414"), t.setAttribute("data-example-question-button-height","40px"), t.setAttribute("data-example-question-button-padding-x","1.5rem"), t.setAttribute("data-example-question-button-padding-y","0.75rem"), t.setAttribute("data-example-question-button-border","1px solid #C2B8AE !important"), t.setAttribute("data-example-question-button-border-radius","8px"), t.setAttribute("data-example-question-button-text-color","#1A1414"), t.setAttribute("data-example-question-button-box-shadow","none"), t.setAttribute("data-example-question-button-font-size","0.875rem"), t.setAttribute("data-example-question-button-hover-bg-color","#EFEBE7"), t.setAttribute("data-modal-z-index","999999"), t.setAttribute("data-modal-border-radius","1.5rem"), t.setAttribute("data-modal-header-bg-color","#DE9DCC"), t.setAttribute("data-modal-header-border-bottom","none"), t.setAttribute("data-modal-header-padding","1.5rem"), t.setAttribute("data-modal-title-font-weight","400"), t.setAttribute("data-modal-title-font-size","1.5rem"), t.setAttribute("data-modal-title-color","#1A1414"), t.setAttribute("data-button-text","ASK AI"), t.setAttribute("data-button-height","5rem"), t.setAttribute("data-button-width","5rem"), t.setAttribute("data-button-bg-color","#1A1414"), t.setAttribute("data-button-border-radius","1rem"), t.setAttribute("data-button-text-shadow","none"), t.setAttribute("data-button-text-font-weight","400"), t.setAttribute("data-button-text-font-size","0.75rem"), t.setAttribute("data-button-image-height","1.5rem"), t.setAttribute("data-button-image-width","1.5rem"), t.setAttribute("data-thread-clear-button-height","40px"), t.setAttribute("data-thread-clear-button-padding-x","16px"), t.setAttribute("data-thread-clear-button-padding-y","8px"), t.setAttribute("data-thread-clear-button-border","none"), t.setAttribute("data-thread-clear-button-border-radius","8px"), t.setAttribute("data-thread-clear-button-bg-color","#EFEBE7"), t.setAttribute("data-thread-clear-button-hover-bg-color","#E2DBD9"), t.setAttribute("data-thread-clear-button-text-color","#1A1414"), t.setAttribute("data-thread-clear-button-font-size","12px"), t.setAttribute("data-thread-clear-button-icon-size","24px") document.head.appendChild(t)} ``` -------------------------------- ### Node.js SDK: Load Document with License Key Source: https://www.nutrient.io/guides/nodejs/troubleshooting/license/add-license-key Demonstrates how to load a document using the Nutrient.io Node.js SDK, providing a license key for watermark-free processing. If no license is provided, the SDK runs in trial mode. ```javascript import { load } from "@nutrient-sdk/node"; const instance = await load({ license: { key: "your key goes here", appName: "your app name goes here" } }); ``` -------------------------------- ### Node.js LLM Guides Sidebar Navigation (JavaScript) Source: https://www.nutrient.io/guides/nodejs/about/system-compatibility This JavaScript code enhances the navigation sidebar for Node.js LLM guides. It handles collapsing/expanding folders, highlights the active page link, and applies active states to parent folder headers. It relies on DOMContentLoaded to ensure the DOM is ready before manipulation. ```javascript (function(){ const sidenavParent = null; /* global sidenavParent */ function normalizeUrl(url) { return url.replace(/\/$/, ""); } function getActiveParent(links, normalizedCurrentPath) { let bestMatch = null; let maxMatchLength = 0; for (const link of links) { const linkHref = normalizeUrl(link.getAttribute("href")); // Check if current path starts with link href (more precise than includes) if (normalizedCurrentPath.startsWith(linkHref)) { if (linkHref.length > maxMatchLength) { maxMatchLength = linkHref.length; bestMatch = link; } } } return bestMatch; } document.addEventListener("DOMContentLoaded", () => { // Make all folders collapsed initially document.querySelectorAll(".folder-content").forEach((content) => { content.classList.add("folder-hidden"); }); // Pathname (ex. /guides/android/viewer/zooming) const currentPath = window.location.pathname; const normalizedCurrentPath = normalizeUrl(currentPath); const links = document.querySelectorAll(".sidebar a"); // Find exact URL match first let exactMatch = Array.from(links).find((link) => { const linkHref = normalizeUrl(link.getAttribute("href")); return linkHref === normalizedCurrentPath; }); // If no exact match, try fallback strategies let parentMatch = null; if (!exactMatch) { if (sidenavParent) { exactMatch = document.querySelector( `.sidebar a[href*="${sidenavParent}"]`, ); } else { parentMatch = getActiveParent(links, normalizedCurrentPath); } } // Apply styles and expand folders based on matches if (exactMatch || parentMatch) { // Only add active class for exact matches if (exactMatch) { exactMatch.classList.add("active"); } // Expand parent folders for either match type let parent = (exactMatch || parentMatch).closest(".folder-content"); while (parent) { parent.classList.remove("folder-hidden"); const folderId = parent.id; const header = document.querySelector(`[data-target="${folderId}"]`); if (header) { // Add active class to parent folder headers header.classList.add("active"); const icon = header.querySelector(".folder-chevron"); icon?.classList.toggle("rotate-icon"); } parent = header?.closest(".folder-content"); } } // Click handlers for folder toggles document.querySelectorAll(".folder-header").forEach((header) => { header.addEventListener("click", () => { const targetId = header.getAttribute("data-target"); const content = document.getElementById(targetId); const chevron = header.querySelector(".folder-chevron"); if (content) { content.classList.toggle("folder-hidden"); chevron?.classList.toggle("rotate-icon"); } }); }); }); })(); ``` -------------------------------- ### Open Grok AI with Prompt (JavaScript) Source: https://www.nutrient.io/guides/nodejs/conversion/image-to-pdf Launches Grok AI in a new tab with a specific prompt. The prompt references the current documentation URL and requests assistance, making it easier to get context-aware help. ```javascript function C(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`, s=`https://grok.com/c?q=${encodeURIComponent(r)}`; window.open(s,"_blank") } ``` -------------------------------- ### Initialize and Use Nutrient Node.js SDK for Office to PDF Conversion Source: https://www.nutrient.io/guides/nodejs/conversion This snippet demonstrates how to initialize the Nutrient Node.js SDK and perform a conversion of Microsoft Office documents (DOCX, XLSX, PPTX) to PDF. It requires the SDK to be installed and licensed. ```javascript const nutrient = require('nutrient-sdk'); async function convertOfficeToPdf(inputPath, outputPath) { try { const converter = new nutrient.OfficeConverter(); await converter.convertToPdf(inputPath, outputPath); console.log('Office document converted to PDF successfully!'); } catch (error) { console.error('Error converting Office document to PDF:', error); } } // Example usage: // convertOfficeToPdf('/path/to/your/document.docx', '/path/to/output.pdf'); ``` -------------------------------- ### Open Grok with Prompt Source: https://www.nutrient.io/guides/nodejs/about/system-compatibility Opens Grok AI in a new tab with a pre-formatted prompt. The prompt asks the AI to help understand the current Nutrient documentation page, providing the URL and offering assistance with explanations, examples, or debugging. ```javascript function C(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`; window.open(`https://grok.com/c?q=${encodeURIComponent(r)}`,"_blank") } ``` -------------------------------- ### JavaScript Form Field Types and Examples Source: https://www.nutrient.io/guides/nodejs/json/schema/form-fields Illustrates common JavaScript data types and constants used for defining form field behavior and properties. Includes examples for event trigger types, input events, flags, and options. ```javascript // Examples of common types of Instant JSON payloads. // Additional action types.formFieldEventTriggerType = "onChange" // Additional action types for input events.// K — Action to be performed when the user types a keystroke into a text field or combo box or modifies the selection in a scrollable list box.formFieldInputEventTriggerType = "onInput" // Form field flags.formFieldFlags = ["readOnly", "required"] // Form option.formOption = { "label": "name", "value": "John Appleseed"}; ``` ```typescript // Additional action types. declare type FormFieldEventTriggerType = // V — When the field's value is changed. This action can check the new value for validity. | 'onChange' // C — Action to be performed to recalculate the value of a field. | 'onCalculate'; // Additional actions type for input events.declare type FormFieldInputEventTriggerType = // K — Action to be performed when the user types a keystroke into a text field or combo box or modifies the selection in a scrollable list box. | 'onInput' // F — Action to be performed before the field is formatted to display its current value. | 'onFormat'; declare type FormFieldFlags = Array< 'readOnly' | 'required' | 'noExport',>; declare type FormOption = { label: string, value: string, }; ``` -------------------------------- ### Instant JSON Schema for Attachments (JSON) Source: https://www.nutrient.io/guides/nodejs/json/schema/file-attachments An example JSON object illustrating the structure of the attachments payload. It shows how attachments are keyed by their SHA-256 hash and include binary data and content type. ```json { "attachments": { "9e51e601bb7469be642f0b0d60bbb98aeb631353839ab3bc5a25797dbb74622f": { "binary": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYlWNgAAIAAAUAAdafFs0AAAAASUVORK5CYII=", "contentType": "image/png" } } } ``` -------------------------------- ### Initialize Service with Settings and Script Loading in JavaScript Source: https://www.nutrient.io/guides/nodejs/json/schema/form-fields Initializes a service by checking for a disable flag, retrieving settings, and setting a timeout for completion. It constructs a URL for fetching settings and dynamically loads a script either via AJAX or by appending a script tag, depending on the URL query parameters. ```javascript if(d.URL.indexOf('__vwo_disable__')>-1)return; var e=this.settings_tolerance(); w._vwo_settings_timer=setTimeout(function(){ _vwo_code.finish(); stT.removeItem(cK) },e); var o=window._vis_opt_url||d.URL, s='https://dev.visualwebsiteoptimizer.com/j.php?a='+account_id+'&u='+encodeURIComponent(o)+'&vn='+version; if(w.location.search.indexOf('_vwo_xhr')!==-1){ this.addScript({src:s}) }else{ this.load(s+'&x=true') } ``` -------------------------------- ### VWO Initialization and Settings Loading (JavaScript) Source: https://www.nutrient.io/guides/nodejs/conversion This snippet initializes the Visual Website Optimizer (VWO) tracking script. It defines account ID, version, and tolerance settings. It attempts to load existing settings from local storage and prepares to dynamically load the VWO library. This code is typically used for A/B testing and website personalization. ```javascript window._vwo_code || (function() { var account_id = 892495, version = 2.1, settings_tolerance = 2000, hide_element = '', // Don't hide body to prevent flash hide_element_style = '', /* DO NOT EDIT BELOW THIS LINE */ f = false, w = window, d = document, v = d.querySelector('#vwoCode'), cK = '_vwo_' + account_id + '_settings', cc = {}; try { var c = JSON.parse(localStorage.getItem('_vwo_' + account_id + '_config')); cc = c && typeof c === 'object' ? c : {} } catch (e) {} var stT = cc.stT === 'session' ? w.sessionStorage : w.localStorage; code = { nonce: v && v.nonce, library_tolerance: function() { return typeof library_tolerance !== 'undefined' ? library_tolerance : undefined }, settings_tolerance: function() { return cc.sT || settings_tolerance }, hide_element_style: function() { return '{' + (cc.hES || hide_element_style) + '}' }, hide_element: function() { // Always return empty to prevent hiding return ''; }, getVersion: function() { return version }, finish: function(e) { if (!f) { f = true; var t = d.getElementById('_vis_opt_path_hides'); if (t) t.parentNode.removeChild(t); if (e)(new Image).src = 'https://dev.visualwebsiteoptimizer.com/ee.gif?a=' + account_id + e } }, finished: function() { return f }, addScript: function(e) { var t = d.createElement('script'); t.type = 'text/javascript'; if (e.src) { t.src = e.src; t.async = true; // Make async } else { t.text = e.text } v && t.setAttribute('nonce', v.nonce); d.getElementsByTagName('head')[0].appendChild(t) }, load: function(e, t) { var n = this.getSettings(), i = d.createElement('script'), r = this; t = t || {}; if (n) { i.textContent = n; d.getElementsByTagName('head')[0].appendChild(i); if (!w.VWO || VWO.caE) { stT.removeI ``` -------------------------------- ### Initialize VWO Website Optimizer Script (JavaScript) Source: https://www.nutrient.io/guides/nodejs/changelog This snippet initializes the Visual Website Optimizer (VWO) script for A/B testing and website optimization. It includes configuration for account ID, version, and settings tolerance. The script dynamically loads the VWO library and handles settings storage. ```javascript window._vwo_code || (function() { var account_id = 892495, version = 2.1, settings_tolerance = 2000, hide_element = '', // Don't hide body to prevent flash hide_element_style = '', /* DO NOT EDIT BELOW THIS LINE */ f = false, w = window, d = document, v = d.querySelector('#vwoCode'), cK = '_vwo_' + account_id + '_settings', cc = {}; try { var c = JSON.parse(localStorage.getItem('_vwo_' + account_id + '_config')); cc = c && typeof c === 'object' ? c : {} } catch (e) {} var stT = cc.stT === 'session' ? w.sessionStorage : w.localStorage; code = { nonce: v && v.nonce, library_tolerance: function() { return typeof library_tolerance !== 'undefined' ? library_tolerance : undefined }, settings_tolerance: function() { return cc.sT || settings_tolerance }, hide_element_style: function() { return '{' + (cc.hES || hide_element_style) + '}' }, hide_element: function() { // Always return empty to prevent hiding return ''; }, getVersion: function() { return version }, finish: function(e) { if (!f) { f = true; var t = d.getElementById('_vis_opt_path_hides'); if (t) t.parentNode.removeChild(t); if (e) (new Image).src = 'https://dev.visualwebsiteoptimizer.com/ee.gif?a=' + account_id + e } }, finished: function() { return f }, addScript: function(e) { var t = d.createElement('script'); t.type = 'text/javascript'; if (e.src) { t.src = e.src; t.async = true; // Make async } else { t.text = e.text } v && t.setAttribute('nonce', v.nonce); d.getElementsByTagName('head')[0].appendChild(t) }, load: function(e, t) { var n = this.getSettings(), i = d.createElement('script'), r = this; t = t || {}; if (n) { i.textContent = n; d.getElementsByTagName('head')[0].appendChild(i); if (!w.VWO || VWO.caE) { stT.removeI } } } } }()) ``` -------------------------------- ### JSON Schema for Base Form Field Source: https://www.nutrient.io/guides/nodejs/json/schema/form-fields An example of a JSON schema defining a base form field. It includes common properties like type, ID, name, label, and flags, applicable to various form field types. ```json { "type": "pspdfkit/form-field/text", "pdfObjectId": 100, "annotationIds": ["100"], "name": "Email", "label": "Email", "flags": ["required"] } ``` -------------------------------- ### Initialize VWO Code with Settings and Async Loading in JavaScript Source: https://www.nutrient.io/guides/nodejs/json/schema/bookmarks This code initializes the VWO (Visual Website Optimizer) functionality. It retrieves settings, sets up a timer for completion, and dynamically loads the VWO script. Initialization is deferred using `requestIdleCallback` or `setTimeout` for non-blocking behavior. ```javascript var o=window._vis_opt_url||d.URL, s='https://dev.visualwebsiteoptimizer.com/j.php?a='+account_id+'&u='+encodeURIComponent(o)+'&vn='+version; if(w.location.search.indexOf('_vwo_xhr')!==-1){ this.addScript({src:s}) }else{ this.load(s+'&x=true') } w._vwo_code=code; if(d.readyState === 'loading') { d.addEventListener('DOMContentLoaded', function() { code.init(); }); } else { if('requestIdleCallback' in w) { requestIdleCallback(function() { code.init(); }, {timeout: 1000}); } else { setTimeout(function() { code.init(); }, 0); } } ``` -------------------------------- ### Open ChatGPT with Prompt (JavaScript) Source: https://www.nutrient.io/guides/nodejs/conversion Opens ChatGPT in a new tab with a pre-filled prompt. The prompt includes the current page's URL and asks for assistance understanding the documentation. The prompt is URL-encoded. ```javascript function v(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`; const s=`https://chatgpt.com/?q=${encodeURIComponent(r)}`; window.open(s,"_blank") } ``` -------------------------------- ### Initialize Event Listeners JavaScript Source: https://www.nutrient.io/guides/nodejs/json/schema/file-attachments Sets up event listeners for various UI elements on the page, including copy buttons, dropdown items, and a markdown view button. It ensures that these listeners are attached after the DOM is fully loaded. It also triggers initial setup for other functions like I() and A(). ```javascript function E(i={}){ document.addEventListener("DOMContentLoaded",()=>{ const t=document.querySelector(i.buttonSelector||".copy-page-btn"); t&&t.addEventListener("click",r=>{ r.preventDefault(), w(i) }); const o=document.querySelector(i.dropdownSelector||".copy-dropdown-item"); o&&o.addEventListener("click",r=>{ r.preventDefault(), w(i) }); const e=document.querySelector(".view-markdown-item"); e&&e.addEventListener("click",r=>{ r.preventDefault(), k() }) }); } E(); document.addEventListener("DOMContentLoaded",()=>{ I(), A() }); ``` -------------------------------- ### AI Widget Configuration Object (JavaScript) Source: https://www.nutrient.io/guides/nodejs/json This JavaScript object, 'n', stores configuration data for the AI widget across different sections of the Nutrient website. It includes specific paths for workflows and low-code features, along with modal disclaimers and example questions tailored to each section. A default configuration is also provided. ```javascript const n={"paths":{"workflowPaths":["/workflow-automation","/guides/workflow-automation"],"lowCodePaths":["/low-code","/guides/low-code","/guides/document-converter","/guides/document-editor","/guides/document-searchability","/guides/document-automation-server/" ]},"workflow":{"modalDisclaimer":"This is a custom LLM for Nutrient with access to product information, the help center, as well as other resources. For best results please mention the product name when asking technical questions.","exampleQuestions":"What types of Workflow templates are available?,How to create a Workflow Form?"},"lowCode":{"modalDisclaimer":"This is a custom LLM for Nutrient with access to product information, the help center, as well as other resources. For best results please mention the product name when asking technical questions.","exampleQuestions":"Convert Documents to PDF with Power Automate?, How to secure Documents using Power Automate?"},"default":{"modalDisclaimer":"This is a custom LLM for Nutrient with access to product information, [guides]((https://www.nutrient.io/sdk/developers)), API reference as well as other resources. For best results please mention the product name when asking technical questions.","exampleQuestions":"How do I get started with the Web SDK?,What AI features does Nutrient offer?"}}; ``` -------------------------------- ### Initialize and Load Nutrient IO Chat Widget (JavaScript) Source: https://www.nutrient.io/guides/nodejs/json/example-json-file This snippet demonstrates how to dynamically create and append a script element to the document body, which is responsible for loading the Nutrient IO chat widget. It includes event handlers for successful loading and error scenarios, managing button states and text accordingly. The script aims to be loaded once the DOM is ready. ```javascript function t(){const e=document.getElementById("kapa-lazy-button");if(!e)return;const o=document.createElement("script");o.id="kapa-script",o.type="module",o.src="/assets/nutrient-embed.js",o.setAttribute("data-site-id","666f2b741161d10014a0511f"),o.setAttribute("data-form-id","666f2b741161d10014a05120"),o.setAttribute("data-thread-clear-button-box-shadow","none"),o.setAttribute("data-answer-feedback-button-height","40px"),o.setAttribute("data-answer-feedback-button-padding-x","16px"),o.setAttribute("data-answer-feedback-button-padding-y","8px"),o.setAttribute("data-answer-feedback-button-border","none"),o.setAttribute("data-answer-feedback-button-border-radius","8px"),o.setAttribute("data-answer-feedback-button-bg-color","#EFEBE7"),o.setAttribute("data-answer-feedback-button-hover-bg-color","#E2DBD9"),o.setAttribute("data-answer-feedback-button-text-color","#1A1414"),o.setAttribute("data-answer-feedback-button-font-size","12px"),o.setAttribute("data-answer-feedback-button-icon-size","24px"),o.setAttribute("data-answer-feedback-button-box-shadow","none"),o.setAttribute("data-answer-copy-button-height","40px"),o.setAttribute("data-answer-copy-button-padding-x","16px"),o.setAttribute("data-answer-copy-button-padding-y","8px"),o.setAttribute("data-answer-copy-button-border","none"),o.setAttribute("data-answer-copy-button-border-radius","8px"),o.setAttribute("data-answer-copy-button-bg-color","#EFEBE7"),o.setAttribute("data-answer-copy-button-hover-bg-color","#E2DBD9"),o.setAttribute("data-answer-copy-button-text-color","#1A1414"),o.setAttribute("data-answer-copy-button-font-size","12px"),o.setAttribute("data-answer-copy-button-icon-size","24px"),o.setAttribute("data-answer-copy-button-box-shadow","none"),o.setAttribute("data-answer-cta-button-height","40px"),o.setAttribute("data-answer-cta-button-padding-x","16px"),o.setAttribute("data-answer-cta-button-padding-y","8px"),o.setAttribute("data-answer-cta-button-border","none"),o.setAttribute("data-answer-cta-button-border-radius","8px"),o.setAttribute("data-answer-cta-button-bg-color","#EFEBE7"),o.setAttribute("data-answer-cta-button-hover-bg-color","#E2DBD9"),o.setAttribute("data-answer-cta-button-text-color","#1A1414"),o.setAttribute("data-answer-cta-button-font-size","12px"),o.setAttribute("data-answer-cta-button-icon-size","24px"),o.setAttribute("data-answer-copy-button-box-shadow","none"),o.setAttribute("data-modal-image","/assets/nutrient-media/icons/logotype/nutrient-ai-icon.svg"),o.setAttribute("data-project-logo","/assets/nutrient-media/icons/dotted/ai.svg"),o.onload=function(){const e=document.getElementById("kapa-lazy-button");if(e){const o=e,r=o._kapaClickHandler;r&&(e.removeEventListener("click",r),delete o._kapaClickHandler),e.style.display="none"}},o.onerror=function(){console.error("Failed to load Kapa script");const e=document.getElementById("kapa-button-icon"),o=document.getElementById("kapa-button-text");e&&e.classList.remove("animate-spin"),o&&(o.textContent="ASK AI");const r=document.getElementById("kapa-lazy-button");r&&(r.setAttribute("aria-busy","false"),r.setAttribute("aria-label","Ask AI - Click to load chat widget"))},document.body.appendChild(o)}function i(){const a=document.getElementById("kapa-lazy-button");if(!a)return;const t=function(){const e=document.getElementById("kapa-button-icon"),o=document.getElementById("kapa-button-text");e&&e.classList.add("animate-spin"),o&&(o.textContent="LOADING..."),a instanceof HTMLButtonElement&&(a.disabled=!0,a.setAttribute("aria-busy","true"),a.setAttribute("aria-label","Loading AI chat widget")),u()};a.addEventListener("click",t),a._kapaClickHandler=t}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",i):i(); ``` -------------------------------- ### Initialize Document Ready Handlers Source: https://www.nutrient.io/guides/nodejs/troubleshoot Sets up event listeners to run once the DOM is fully loaded. It specifically calls `I()` and `A()` which are assumed to handle other document-ready functionalities. ```javascript document.addEventListener("DOMContentLoaded", () => { I(); A(); }); ``` -------------------------------- ### BaseAnnotation JSON Schema Example Source: https://www.nutrient.io/guides/nodejs/json/schema/annotations An example JSON schema representing the `BaseAnnotation` type. It includes common properties such as version, page index, bounding box, opacity, creator information, timestamps, and flags. This schema is used for defining annotation structures. ```json { "v": 1, "pageIndex": 0, "bbox": [150, 75, 120, 70], "opacity": 1, "pdfObjectId": 100, "flags": ["noZoom", "noRotate"], "creatorName": "John Doe", "createdAt": "2012-04-23T18:25:43.511Z", "updatedAt": "2012-04-23T18:28:05.100Z", "id": "01F46S31WM8Q46MP3T0BAJ0F83", "name": "01F46S31WM8Q46MP3T0BAJ0F83" } ``` -------------------------------- ### Initialize Nutrient AI Chat Widget in Node.js Source: https://www.nutrient.io/guides/nodejs/troubleshooting/license/add-license-key This snippet initializes the Nutrient AI chat widget by creating a script element and appending it to the document body. It sets various attributes to configure the widget's appearance and functionality, including button styles, modal image, and project logo. Error and load handlers are also defined. ```javascript var t=document.createElement("script");t.async=!0,t.src="https://kapa.ai/script.js",t.setAttribute("data-website-id","YOUR_WEBSITE_ID"),t.setAttribute("data-search-key","YOUR_SEARCH_KEY"),t.setAttribute("data-project-key","YOUR_PROJECT_KEY"),t.setAttribute("data-answers-base-color","#1A1414"),t.setAttribute("data-answers-font-color","#FFFFFF"),t.setAttribute("data-answers-border-color","#E2DBD9"),t.setAttribute("data-search-input-placeholder","Ask anything about Nutrient!"),t.setAttribute("data-search-input-bg-color","#EFEBE7"),t.setAttribute("data-search-input-text-color","#1A1414"),t.setAttribute("data-search-input-border-color","#EFEBE7"),t.setAttribute("data-answer-feedback-button-box-shadow","none"),t.setAttribute("data-answer-feedback-button-height","40px"),t.setAttribute("data-answer-feedback-button-padding-x","16px"),t.setAttribute("data-answer-feedback-button-padding-y","8px"),t.setAttribute("data-answer-feedback-button-border","none"),t.setAttribute("data-answer-feedback-button-border-radius","8px"),t.setAttribute("data-answer-feedback-button-bg-color","#EFEBE7"),t.setAttribute("data-answer-feedback-button-hover-bg-color","#E2DBD9"),t.setAttribute("data-answer-feedback-button-text-color","#1A1414"),t.setAttribute("data-answer-feedback-button-font-size","12px"),t.setAttribute("data-answer-feedback-button-icon-size","24px"),t.setAttribute("data-answer-feedback-button-box-shadow","none"),t.setAttribute("data-answer-copy-button-height","40px"),t.setAttribute("data-answer-copy-button-padding-x","16px"),t.setAttribute("data-answer-copy-button-padding-y","8px"),t.setAttribute("data-answer-copy-button-border","none"),t.setAttribute("data-answer-copy-button-border-radius","8px"),t.setAttribute("data-answer-copy-button-bg-color","#EFEBE7"),t.setAttribute("data-answer-copy-button-hover-bg-color","#E2DBD9"),t.setAttribute("data-answer-copy-button-text-color","#1A1414"),t.setAttribute("data-answer-copy-button-font-size","12px"),t.setAttribute("data-answer-copy-button-icon-size","24px"),t.setAttribute("data-answer-copy-button-box-shadow","none"),t.setAttribute("data-answer-cta-button-height","40px"),t.setAttribute("data-answer-cta-button-padding-x","16px"),t.setAttribute("data-answer-cta-button-padding-y","8px"),t.setAttribute("data-answer-cta-button-border","none"),t.setAttribute("data-answer-cta-button-border-radius","8px"),t.setAttribute("data-answer-cta-button-bg-color","#EFEBE7"),t.setAttribute("data-answer-cta-button-hover-bg-color","#E2DBD9"),t.setAttribute("data-answer-cta-button-text-color","#1A1414"),t.setAttribute("data-answer-cta-button-font-size","12px"),t.setAttribute("data-answer-cta-button-icon-size","24px"),t.setAttribute("data-answer-copy-button-box-shadow","none"),t.setAttribute("data-modal-image","/assets/nutrient-media/icons/logotype/nutrient-ai-icon.svg"),t.setAttribute("data-project-logo","/assets/nutrient-media/icons/dotted/ai.svg"),t.onload=function(){const e=document.getElementById("kapa-lazy-button");if(e){const o=e,r=o._kapaClickHandler;r&&(e.removeEventListener("click",r),delete o._kapaClickHandler),e.style.display="none"}},t.onerror=function(){console.error("Failed to load Kapa script");const e=document.getElementById("kapa-button-icon"),o=document.getElementById("kapa-button-text");e&&e.classList.remove("animate-spin"),o&&(o.textContent="ASK AI");const r=document.getElementById("kapa-lazy-button");r&&(r.setAttribute("aria-busy","false"),r.setAttribute("aria-label","Ask AI - Click to load chat widget"))}},document.body.appendChild(t) ``` -------------------------------- ### Sidebar Navigation Logic for LLM Guides (JavaScript) Source: https://www.nutrient.io/guides/nodejs/json/schema/comments This JavaScript code handles the dynamic behavior of the sidebar navigation for LLM guides. It manages active link highlighting, folder expansion/collapse, and event listeners for folder toggles. It relies on DOM manipulation and browser events. ```javascript (function(){ const sidenavParent = null; /* global sidenavParent */ function normalizeUrl(url) { return url.replace(/\/$/, ""); } function getActiveParent(links, normalizedCurrentPath) { let bestMatch = null; let maxMatchLength = 0; for (const link of links) { const linkHref = normalizeUrl(link.getAttribute("href")); // Check if current path starts with link href (more precise than includes) if (normalizedCurrentPath.startsWith(linkHref)) { if (linkHref.length > maxMatchLength) { maxMatchLength = linkHref.length; bestMatch = link; } } } return bestMatch; } document.addEventListener("DOMContentLoaded", () => { // Make all folders collapsed initially document.querySelectorAll(".folder-content").forEach((content) => { content.classList.add("folder-hidden"); }); // Pathname (ex. /guides/android/viewer/zooming) const currentPath = window.location.pathname; const normalizedCurrentPath = normalizeUrl(currentPath); const links = document.querySelectorAll(".sidebar a"); // Find exact URL match first let exactMatch = Array.from(links).find((link) => { const linkHref = normalizeUrl(link.getAttribute("href")); return linkHref === normalizedCurrentPath; }); // If no exact match, try fallback strategies let parentMatch = null; if (!exactMatch) { if (sidenavParent) { exactMatch = document.querySelector( `.sidebar a[href*="${sidenavParent}"]`, ); } else { parentMatch = getActiveParent(links, normalizedCurrentPath); } } // Apply styles and expand folders based on matches if (exactMatch || parentMatch) { // Only add active class for exact matches if (exactMatch) { exactMatch.classList.add("active"); } // Expand parent folders for either match type let parent = (exactMatch || parentMatch).closest(".folder-content"); while (parent) { parent.classList.remove("folder-hidden"); const folderId = parent.id; const header = document.querySelector(`[data-target="${folderId}"]`); if (header) { // Add active class to parent folder headers header.classList.add("active"); const icon = header.querySelector(".folder-chevron"); icon?.classList.toggle("rotate-icon"); } parent = header?.closest(".folder-content"); } } // Click handlers for folder toggles document.querySelectorAll(".folder-header").forEach((header) => { header.addEventListener("click", () => { const targetId = header.getAttribute("data-target"); const content = document.getElementById(targetId); const chevron = header.querySelector(".folder-chevron"); if (content) { content.classList.toggle("folder-hidden"); chevron?.classList.toggle("rotate-icon"); } }); }); }); })(); ```