Question, I want to display the document after applyRedactions

WebViewer Version:
10.3.0
Do you have an issue with a specific file(s)?
No.
Can you reproduce using one of our samples or online demos?
No.
Are you using the WebViewer server?
No.
Does the issue only happen on certain browsers?
No.
Is your issue related to a front-end framework?
No.
Is your issue related to annotations?
Yes.
Please give a brief summary of your issue:
(Think of this as an email subject)
Question, I want to display the document after applyRedactions.

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

I want to display the document after applyRedactions.
However, the document before redaction is displayed for a few milliseconds.
SampleCode.

pdftronStylesheets.css 
{
  // Hide viewer until redaction is applied
  .content {
    visibility: hidden;
  }
}
------------------------------------------------------------------

WebViewer({
  licenseKey: 'licensekey', 
  enableRedaction: true, 
  initialDoc: 'downloadUrl',
  loadAsPdf: true,
  css: '/assets/stylesheets/pdftronStylesheets.css',
  fullAPI: true,
  ...
}).then((instance: WebViewerInstance) => {
  const { annotationManager, documentViewer } = instance.Core;

  documentViewer.addEventListener('documentLoaded', async () => {
    const redactAnnotationXFDFs = DB.GetRedactAnnotationXFDFs();
    
    redactAnnotationXFDFs .forEach(xfdf => {
      const annots = await instance.Core.annotationManager.importAnnotations(xfdf);

      instance.Core.annotationManager. redrawAnnotation(annots[0]);
    });   

    // ***** apply *****
    await instance.Core.annotationManager.applyRedactions();    

    const documentContent =
      instance.UI.iframeWindow.document.querySelector(
        '.content'
      );

      // ***** View in viewer after applying redaction *****
      documentContent?.setAttribute('style', 'visibility: visible');
  });
});

Result of sample code

What should I do?
Please give me some advice.

Best Regards.
Please provide a link to a minimal sample where the issue is reproducible:

1 Like

Hi,

We’re looking into this. Thanks.

1 Like

You may want to save the document with redactions applied, then the next time when the document is loaded, the content will be hidden right away.

1 Like

Hi,
Thank you for reply.

For now, I have to take workaround.
So I added the sample code below.

    let count = 0;
    let prevCount = 0;
    let visibled = false;
    let watching = false;

    annotationManager.addEventListener(
      'annotationsDrawn',
      () => {
        count++;
        if (watching) return;
        watching = true;

        const checkVisible = () => {
          if (visibled) return;

          setTimeout(() => {
            if (count > prevCount) {
              prevCount = count;
              checkVisible();
            } else {
              const documentContent =
                this.viewerInstance.UI.iframeWindow.document.querySelector(
                  '.content'
                );

              documentContent?.setAttribute('style', 'visibility: visible');
              visibled = true;
            }
          }, 2000);
        };

        checkVisible();
      }

It seems to be working for me.
If there are any big problems, it would be great if you’d let me know.

Best Regards.

1 Like

I see that you’re changing the CSS styles, and I think it should be fine.

2 Likes