Mendix pdftron integration Issues

WebViewer Version: 1.0.0

Do you have an issue with a specific file(s)? N/A
Can you reproduce using one of our samples or online demos? N/A
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? N/A
Is your issue related to annotations? Yes

Please give a brief summary of your issue:
We are trying to integrate PDFTron web viewer with Mendix Application. There we are having multiple questions, can you please answer those.

  1. In Mendix App, we have PDF document as a FileDocument Entity, so how we can load this file in webviewer. Is there any best practice for that?
  2. We are using the export annotation function to get hold of annotations marked on a pdf document. Can we trigger the export annotation function from Mendix microflow? Is there any other way to get hold annotations in Mendix application?
  3. Is it possible to name the annotations in web viewer.
  4. Is it possible to restrict only one annotation in web viewer.

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

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

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi,
to answer your questions:

  1. In Mendix App, we have PDF document as a FileDocument Entity, so how we can load this file in webviewer. Is there any best practice for that?

WebViewer supports loading document from File / Blob / ArrayBuffer / URL if a document is loaded from an external source. I’m not really familiar with the FileDocument Entity in Mendix, but in any case you would need to convert that to one of the supported format before it can be loaded by WebViewer.

  1. We are using the export annotation function to get hold of annotations marked on a pdf document. Can we trigger the export annotation function from Mendix microflow? Is there any other way to get hold annotations in Mendix application?

In general, if you need to trigger an action under certain situation you will want to look for event listeners / event handlers. Depending on how Mendix implemented their event system you may be able to execute WebViewer’s annotation export logics in their event listener / event handler.

  1. Is it possible to name the annotations in web viewer.

Yes. You can set / get a name of your annotation (or any custom data) following this example.

  1. Is it possible to restrict only one annotation in web viewer.

If you want to only display one annotation based on certain criteria, you could do so by looping through all annotations and toggle the Hidden property. For example:

WebViewer(...)
  .then(instance => {
    const { documentViewer, annotationManager } = instance.Core;
    annotationManager.getAnnotationsList().forEach(annot=> {
      if (annot.Author === 'SomeSpecificAuthor') {
        annot.Hidden = false;
      } else {
        annot.Hidden = true;
      }
    })
  }

If you want to just have one annotation at any time, you can do so by removing previous annotations when you add new annotation to the document:

WebViewer(...)
  .then(instance => {
    const { documentViewer, annotationManager } = instance.Core;
    annotationManager.addEventListener('annotationChanged', (annotations, action) => {
    if (action === 'add') {
      // remove all annotations except the one we just created
      annotationManager.deleteAnnotations(annotationManager.getAnnotationsList().filter(annot => annot.Id !== annotations[0].Id))
    }
  });
}

Thank you Ychen for the response. Most of the suggestions provided worked for us.

We have one more question, Lets assume we have a Mendix entity attribute that holds xfdf XML. So on the go when value of this attribute changes, we need to draw the corresponding annotation on the loaded pdf. We can achieve annotation draw using importannotation method, but the challenge is how to trigger that function on attribute change? Could you please help us with that.

You’re welcome.
So for your last question I’m seeing 2 possibilities:

  • Within Mendix, find out what properties exactly changed in that attribute which stores the annotation
  • Search for the changed annotation in WebViewer
  • Update the annotation property

Or

  • Search for the changed annotation in WebViewer, delete it
  • Re-Import the changed annotation from the XML

In either case you would need to find the changed annotation in WebViewer to update / re-import. I think one way to do this is by look for its Id. The annotations in WebViewer has an ‘Id’ property and we have an API to get annotation by its id:
instance.Core.annotationManager.getAnnotationById()

In XML the Id is stored in the ‘name’ property.