Showing PDF files in the Viewer

October 4, 2018

Viewer

This is how my code used to load 2D models:

geometryItems = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), {
    'type': 'geometry',
    'role': '2d'
}, true);

if (geometryItems.length > 0) {
    var path = doc.getViewablePath(geometryItems[0]);
    var options = {};
    viewer.loadModel(path, options);
}

However, this throws an error that the relevant resources could not be found when trying to load a PDF document.

Now there is a new function to load your models which will also take care of loading PDF files, called loadDocumentNode()

Here is the updated code that works :)

if (geometryItems.length > 0) {
    viewer.loadDocumentNode(doc, geometryItems[0]);
}

 

Posts by author

Adam Nagy joined Autodesk back in 2005 and has been providing programming support, consulting, training and evangelism to external developers.