Redaction applied programmatically is not working in Angular Webviewer

Product: Web-Viewer

Product Version: 8.10.0

Please give a brief summary of your issue:
Redaction applied programmatically just shows a rectangle box with no color visibility, no text visibility. When we mouse over on the box color is appearing and text font and alignments are not as given in the code.

Please describe your issue and provide steps to reproduce it:

I am just copying the code mentioned here PDFTron Systems Inc. | Documentation
into my application. But after loading the page it is just showing just a rectangle box with no color visibility, no text visibility as shown below.

image

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

Hello nari.naresh2022,

This guide might be a bit outdated, can you provide your sample project for us to debug?

Best regards,
Tyler Gordon
Web Development Support Engineer
PDFTron

Hello tgordon,

Thank you for the reply. Please find the repo below that I am seeing the problem.

narinaresh2022/pdftronPOC (github.com)

Hello nari.naresh2022

Happy new year!
I have checked your code. From what I see, the problem may fron

annotationManager.addEventListener('annotationChanged', (annotations, action) => {
        if (annotations.length > 0 && action === 'delete') {
          annotations.forEach((annot) => {
            let annotForSave = {
              height: annot.Height,
              width: annot.Width,
              x : annot.X,
              y: annot.Y,
              pageNumber : annot.PageNumber,
              overlayText : annot.OverlayText,
              fontSize: annot.FontSize,
              textColor : annot.TextColor,
              // fillColor:{'R':annot.Ij.R,'G':annot.Ij.G,'B':annot.Ij.B,'A':annot.Ij.A}
            }
            console.log('annotJson', annot);
            console.log('annotForSave', annotForSave);
          });
        }
      })

After I have commented out the fillColor it works well. I also find that you are using the webviewer 8.0.0 from the project package. If it is okie, could you please update the version into the latest one??

Best Regards
Jack

Hi @jhou ,

Thank you for your reply and wish you a Happy New Year too.

The code snippet what you have shown is not for binding the redaction to the UI. Instead its a dummy object I created for saving.

Please refer the below code that I am using to bind redaction to UI and please advise if any changes are required.

Hey nari.naresh2022

The code you shared with me on my side works fine. You could check the video I have recorded. https://pdftron.s3.amazonaws.com/custom/test/jack/Screen+Recording+2023-01-05+at+3.11.00+PM.mov
Could you update the webviewer library to see if there is still a problem?
Here is the code I am using:

import { Component, ViewChild, OnInit, Output, EventEmitter, ElementRef, AfterViewInit } from '@angular/core';
import { Subject } from 'rxjs';
import WebViewer, { Core, WebViewerInstance } from '@pdftron/webviewer';
import { Inject }  from '@angular/core';
import { DOCUMENT } from '@angular/common'; 

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit, AfterViewInit {
  @ViewChild('viewer') viewer: ElementRef;
  wvInstance: WebViewerInstance;
  @Output() coreControlsEvent:EventEmitter<string> = new EventEmitter(); 

  private documentLoaded$: Subject<void>;

  constructor(@Inject(DOCUMENT) document: Document) {
    this.documentLoaded$ = new Subject<void>();
  }

  ngAfterViewInit(): void {

    WebViewer({
      path: '../lib',
      initialDoc: '../files/V3S Aggrement.pdf'
      ,enableRedaction: true
      ,fullAPI:true
      
    }, this.viewer.nativeElement).then(instance => {
      this.wvInstance = instance;

      this.coreControlsEvent.emit(instance.UI.LayoutMode.Single);

      const { documentViewer, annotationManager, Annotations  } = instance.Core;

      instance.UI.setHeaderItems(header => {
        header.push({
          type: 'actionButton',
          img: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z"/></svg>',
          onClick: () => {
            debugger;
            // save the annotations
            annotationManager.exportAnnotations({ links: false, widgets: false }).then(xfdfString => {
              console.log('xfdfString',xfdfString);
            })
          }
        });
      })


      instance.UI.openElements(['notesPanel']);

      documentViewer.addEventListener('documentLoaded', () => {

     
      var math = instance.Core.Math;
      const redactAnnot1 = new Annotations.RedactionAnnotation({
          PageNumber: 1,
          Rect: new math.Rect(100, 100, 300, 200),// Rect are in the form x1,y1,x2,y2,
          FillColor: new Annotations.Color(197, 68, 206),
          OverlayText: "Test",
          TextColor: new Annotations.Color(228, 66, 52),
          TextAlign : "Center"
      });

      redactAnnot1.Color = new Annotations.Color(197, 68, 206);
      redactAnnot1.StrokeColor = new Annotations.Color(197, 68, 206);
      redactAnnot1.Font = "44pt";

      const redactAnnotations = [redactAnnot1];
      annotationManager.addAnnotations(redactAnnotations);
      annotationManager.drawAnnotationsFromList(redactAnnotations);
			documentViewer.getAnnotationManager().applyRedactions();
       
     

      this.documentLoaded$.next();        
      });

      // Bind Annotations fron DB
      documentViewer.setDocumentXFDFRetriever(async () => {
        // load the annotation data
        const response = await fetch('https://localhost:44313/api/Annotation');
        const xfdfString = await response.text();
        return xfdfString;
      });
       
      //Save redaction to DB
      annotationManager.addEventListener('annotationChanged', (annotations, action) => {
        if (annotations.length > 0 && action === 'delete') {
          annotations.forEach((annot) => {
            let annotForSave = {
              height: annot.Height,
              width: annot.Width,
              x : annot.X,
              y: annot.Y,
              pageNumber : annot.PageNumber,
              overlayText : annot.OverlayText,
              fontSize: annot.FontSize,
              textColor : annot.TextColor,
              // fillColor:{'R':annot.Ij.R,'G':annot.Ij.G,'B':annot.Ij.B,'A':annot.Ij.A}
            }
            console.log('annotJson', annot);
            console.log('annotForSave', annotForSave);
          });
        }
      }) 
     })

    
     
  }

  

  ngOnInit() {
  }

  getDocumentLoadedObservable() {
    return this.documentLoaded$.asObservable();
  }
}