Firstly at https://www.pdftron.com/documentation/web/samples/advanced/#diff-documents the “Source Code” button does not actually show the source code of the demo. It shows something else which calls the appendTextDiffDoc API which I find confusing given that the sample is described as “shows pixel differences between the two documents”. Is appendTextDiffDoc supposed to be for pixel differences or for “text” differences. If its for pixel differences then how does it differ to appendVisualDiff?
Anyway, ignoring the “Source Code” given that it seems to be for something else, trying to work out how the real demo works is not particularly obvious to the uninitiated.
Is it possible to show a simple piece of code that shows 2 viewers being loaded and the references to the documents in those viewers being obtained? Or vice-versa, 2 documents being loaded and then shown in 2 viewers? Either way, such that the documents could then be used with appendVisualDiff for example.
Also, wondering what the syncNamespaces function does? It is done in the demo, but it’s not clear to me what it’s for. However, it looks like it could be important for what I’m trying to do which involves multiple viewers.
You said “it is used for reusing the same worker files for all the instances of WebViewer so you don’t have to reinstantiate them.”, but I don’t actively instantiate them and also you make it sound like its a performance or memory saving feature whereas the doc link you supplied makes it sound like a requirement for interoperability.
Is it for cases of sharing objects between instances. e.g. if I got a reference to a doc shown in webviewer A and want to show it directly in webviewer B (without doing anything intermediate like serialising it to a byte array)?
When loading multiple instances of WebViewer, each WebViewer loads its own namespaces into its own iframes. Since they are each loading their own, each separate window will have different instances of objects and classes that may not align with one another despite having the same script.
This causes the instanceof checks to fail when checking an object created from one instance with a loaded class from another instance.
From your code, I see you are passing Core into syncNamespaces which doesn’t take a Core argument as one of the options. From the source, it doesn’t seem to sync document types as well. This is because the Document object is used quite early and by the time you call syncNamespaces, it would be too late. I am not sure about your use case but you should be keeping each document created by a certain instance to its own respective instances. If you need to share workers, you should look to using the workerTransportPromise instead: PDFTron Systems Inc. | Documentation.
What I’ve been tasked with is to create a UI which shows the pixel differences between two documents and which can toggle between showing just the differences document and showing the two source documents as well. i.e. to toggle between a single webviewer instance and 3 webviewer instances.
What I was trying to do was to not load webviewer instances until I needed them to reduce overhead. So my plan was to load the two documents outside of a webviewer via the Core.createDocument(url). Generate the differences document, and then show that in the single webviewer instance.
Then, if the user chooses to switch to the 3 panel display, I would then create two more webviewer instances and just load the two documents in them, rather than making the webviewers load the original URLs again.
From what you’re saying, it sounds like this isn’t possible? You have to load documents in each webviewer instance independently?
I think there are tradeoffs since you have to keep documents in memory. Although the Document objects may not be compatible between each of the instances, you can still get the file data (and perhaps cache that instead) to load in other instances.