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

PDFTron WebViewer如何默认显示评论框并隐藏回复框?

Solution for Default Comment Box & Hiding Reply Box in PDFTron WebViewer

Hey there! Let me walk you through a reliable approach to fix this using WebViewer's native APIs and targeted DOM controls—no fragile manual HTML injection required:

1. Override Default Reply Panel Behavior for New Annotations

When you use the Comment tool to create a new annotation, WebViewer defaults to opening the Reply panel. We can intercept this behavior and switch directly to the Comment (edit) panel instead:

// Wait for WebViewer to finish initializing
instance.Core.documentViewer.addEventListener('documentLoaded', () => {
  const annotationManager = instance.Core.documentViewer.getAnnotationManager();
  
  // Listen for new annotations being added to the document
  annotationManager.addEventListener('annotationAdded', (annotations) => {
    const newAnnotation = annotations[0];
    // Target annotations created with the default Comment tool (adjust for other types if needed)
    if (newAnnotation instanceof instance.Core.Annotations.FreeTextAnnotation) {
      // Close the default Reply panel first
      instance.UI.closeElements(['notesPanel']);
      // Reopen the notes panel and switch to edit mode for the new annotation
      instance.UI.openElements(['notesPanel']);
      instance.UI.setNoteEditing(newAnnotation);
    }
  });
});

2. Permanently Hide the Reply Box

Since the Reply box doesn't have a data-element attribute, we can combine WebViewer's panel lifecycle events with CSS to reliably hide it:

// Listen for when the notes panel opens
instance.UI.addEventListener('panelOpened', (panelName) => {
  if (panelName === 'notesPanel') {
    // Wait a brief moment for the DOM to fully render
    setTimeout(() => {
      // Target the Reply container (adjust selector if your WebViewer version's DOM differs)
      const replyBox = document.querySelector('.NotesPanel__reply-container');
      if (replyBox) {
        replyBox.style.display = 'none';
      }
    }, 100);
  }
});

// Add persistent CSS to ensure the Reply box stays hidden through panel refreshes
const hideReplyStyle = document.createElement('style');
hideReplyStyle.textContent = `
  .NotesPanel__reply-container {
    display: none !important;
  }
`;
document.head.appendChild(hideReplyStyle);

3. Preserve Correct Submission Logic

This method keeps the original Comment box submission logic intact, so you won't run into mismatched API requests between Reply and Comment modes. The edit mode uses WebViewer's native annotation update flow, while the Reply box is completely hidden from user view.

Quick Tips:

  • If you're using annotation types other than the default Comment tool (like sticky notes), adjust the annotation type check in the annotationAdded listener.
  • Double-check the DOM selector for the Reply box by inspecting the element if your WebViewer version uses a slightly different class name.
  • Using WebViewer's native APIs (setNoteEditing, openElements) ensures compatibility with future updates, unlike fragile manual DOM manipulation.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:46:39