You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Forge Viewer加载PDF后,如何切换工具实现文本选择与内容提取?

Extracting Text from PDFs in Forge Viewer

Absolutely! You can select and extract text from PDF drawings loaded in the Forge Viewer—let’s walk through fixing that pan-tool issue and getting the text extraction working:

  • Switch from Pan Tool to Selection Tool
    The default hand cursor means you’re in the PanTool mode, which only lets you drag the view around. To enable selection, activate the built-in selection tool with this code:

    viewer.toolController.activateTool('selection');
    

    Your cursor will switch to an arrow, and you’ll be able to click and drag to select text elements.

  • Ensure Text is Enabled for Interaction
    When loading your PDF, make sure you haven’t disabled text rendering in the viewer options. By default, text is enabled, but if you’re using custom load settings, double-check that disablePDFText isn’t set to true in your viewer initialization config.

  • Extract Selected Text Content
    Once you’ve selected text, use the viewer’s selection event to grab the text data. Here’s a code snippet to listen for selection changes and extract the text:

    // Listen for when the user selects something
    viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, (event) => {
      if (event.selections.length === 0) return; // Exit if nothing is selected
    
      const firstSelection = event.selections[0];
      firstSelection.dbIdArray.forEach(dbId => {
        // Fetch properties for the selected text element
        viewer.getProperties(dbId, (props) => {
          // Look for the text property (field name may vary slightly)
          const textProp = props.properties.find(prop => prop.displayName === 'Text');
          if (textProp) {
            console.log('Extracted Text:', textProp.value);
            // You can display this text in your UI or process it further here
          }
        });
      });
    });
    
  • Note on Image-Based PDFs
    If your PDF is a scanned image (not vector-based text), the viewer won’t recognize text elements natively. In that case, you’d need to integrate an OCR solution alongside the viewer to extract text from the image layers.

内容的提问来源于stack exchange,提问作者Trung Tran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:29:57