Auto desk Forge Viewer PDF Snap and Zoom Issue

Viewed 94

When using forge viewer for PDF’s, is it possible to enable the Snap feature for measuring (same as when viewing models). Also, can the zoom level be changed i.e. we want to zoom in closer than the default maximum?

Both of these are possible in BIM360 so I hope it is also possible in our application, can you please advise.

Currently we are used v7 viewer. We are added the snap extension and setZoomInLimitFactor method also. But still we are unable to get snapping feature and zoom in function at PDF files.

function launchViewer(urn, viewableId) {
        var options = {
            env: 'AutodeskProduction',
            getAccessToken: getForgeToken,
            api: 'derivativeV2' + (atob(urn.replace('_', '/')).indexOf('emea') > -1 ? '_EU' : '') // Both BIM 360 US and EU regions
        };

        Autodesk.Viewing.Initializer(options, () => {
            viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer'));
            viewer.start();
            var documentId = 'urn:' + urn;
            Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
        });

        function onDocumentLoadSuccess(doc) {
            // if a viewableId was specified, load that view, otherwise the default view
            var viewables = (viewableId ? doc.getRoot().findByGuid(viewableId) : doc.getRoot().getDefaultGeometry());
            viewer.loadDocumentNode(doc, viewables).then(i => {
                viewer.loadExtension('Autodesk.VisualClusters');
                viewer.loadExtension('Autodesk.Snapping');
                viewer.loadExtension("Autodesk.Viewing.MarkupsCore");
                viewer.loadExtension("Autodesk.Viewing.MarkupsGui");
                viewer.loadExtension('Autodesk.Measure');
                viewer.loadExtension('Autodesk.DefaultTools.NavTools');
                viewer.loadExtension('Autodesk.PDF');
                viewer.loadExtension('Autodesk.DocumentBrowser');
                viewer.loadExtension('Autodesk.Viewing.ZoomWindow');
                // any additional added here
            });
            viewer.navigation.setZoomInLimitFactor(2500);
            console.log(viewer.navigation.getZoomInLimitFactor());
        }

        function onDocumentLoadFailure(viewerErrorCode) {
            console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode);
        }
    }

kindly advise if we missed anything. Thanks in advance.

1 Answers

it looks you are using the old way to translate PDF then load it to viewer. In the old way, the PDF is translated to tiled images. So snapping may not be working, and zoom has max limit due to the max resolution of tiled images.

Actually, Forge Viewer has supported to load native PDF directly, without translation. Since it is native, it is vector graphics. The snapping will work, and it can be zoomed to large/much small scale.

To play it, please download the sample project, https://github.com/Autodesk-Forge/viewer-javascript-offline.sample and replace the line to your local pdf file

  var options = {
      'env' : 'Local',
      'document' : './my_PDF_folder/mytest.pdf'
  };

This feature is from the extension Autodesk.PDF, but it will be loaded de default, you do not need to load it explicitly.

Related