问题描述
在我们的应用程序中,我们使用
这是我用来初始化查看器的代码部分:
function doInitializeTheViewer(urn, token, element) {常量选项 = {'env': 'AutodeskProduction','accessToken':令牌};让 documentId = 'urn:' + urn;返回新的承诺((解决,拒绝)=> {Autodesk.Viewing.Initializer(选项,函数 onInitialized() {让viewerApp = new Autodesk.A360ViewingApplication(element.id);viewerApp.onDocumentLoaded = 函数(文档){解决(getViewerInstance().然后(查看者=> {state.viewer = 查看器;返回状态;}));};viewerApp.onDocumentFailedToLoad = (reason, errorCode) =>{拒绝({错误代码,原因});};viewerApp.registerViewer(viewerApp.k3D, Autodesk.Viewing.Private.GuiViewer3D);viewerApp.loadDocumentWithItemAndObject(documentId);state.viewerApp = viewerApp;});});}
而且,这就是它被调用的方式:
let element = document.getElementById('#the-viewer');fetch2LegToken().then(({accessToken}) =>doInitializeTheViewer(urnB64, accessToken, element));
我还需要在这里做什么才能让查看器同时呈现多页 pdf 文件和其他 3D/2D 文件?
我在
由于您覆盖了 onDocumentLoaded
,请查看 Autodesk360App.js 实现了 onDocumentLoaded
方法.在第 621 行:
function showDesignExplorer( modelDocument ){var viewableItems = Autodesk.Viewing.Document.getSubItemsWithProperties(modelDocument.getRootItem(), {'type':'folder','role':'viewable'}, true);var root = viewableItems[0];var geometryItems = Autodesk.Viewing.Document.getSubItemsWithProperties(root, {'type':'geometry'}, true);如果(geometryItems.length === 0)返回假;if (geometryItems.length === 1) {//检查项目是否有相机视图.返回 modelDocument.getNumViews( geometryItems[0] ) >1;}返回真;}
在您的 onDocumentLoaded
方法中,调用 Autodesk.Viewing.Document.getSubItemsWithProperties
方法以获取所有视图.
还有一行在 lmvdbg 在演示如何加载所有视图.
In our application we're using Autodesk Forge Viewer to render 3D and 2D design files. Files with other formats get rendered pretty well. But in case of the pdf
files, only the first page gets rendered even if the file actually has multiple pages.But we need to display all the pages.
Here's the part of code I'm using to initialize the viewer:
function doInitializeTheViewer(urn, token, element) {
const options = {
'env': 'AutodeskProduction',
'accessToken': token
};
let documentId = 'urn:' + urn;
return new Promise((resolve, reject) => {
Autodesk.Viewing.Initializer(options, function onInitialized() {
let viewerApp = new Autodesk.A360ViewingApplication(element.id);
viewerApp.onDocumentLoaded = function (doc) {
resolve(getViewerInstance().then(viewer => {
state.viewer = viewer;
return state;
}));
};
viewerApp.onDocumentFailedToLoad = (reason, errorCode) => {
reject({errorCode, reason});
};
viewerApp.registerViewer(viewerApp.k3D, Autodesk.Viewing.Private.GuiViewer3D);
viewerApp.loadDocumentWithItemAndObject(documentId);
state.viewerApp = viewerApp;
});
});
}
And, this is how it gets invoked:
let element = document.getElementById('#the-viewer');
fetch2LegToken().then(
({accessToken}) => doInitializeTheViewer(urnB64, accessToken, element)
);
What else do I need to do here to get the viewer also render multi-page pdf files along with other 3D/2D files?
I couldn't find any way to configure this in the API documentation as well nor could I find it in any sample.
.pdf
files are translated as 2D sheets in the viewer, each page in the .pdf
file should appear as individual 2D views.
If you just use the boilerplate code from the Instantiate a Basic Viewer you'll get multiple views like so:
Since you override onDocumentLoaded
, take a look at how the Autodesk360App.js implemented onDocumentLoaded
method. At line 621:
function showDesignExplorer( modelDocument )
{
var viewableItems = Autodesk.Viewing.Document.getSubItemsWithProperties(modelDocument.getRootItem(), {'type':'folder','role':'viewable'}, true);
var root = viewableItems[0];
var geometryItems = Autodesk.Viewing.Document.getSubItemsWithProperties(root, {'type':'geometry'}, true);
if (geometryItems.length === 0)
return false;
if (geometryItems.length === 1) {
// Check if the item has camera views.
return modelDocument.getNumViews( geometryItems[0] ) > 1;
}
return true;
}
In your onDocumentLoaded
method, call the Autodesk.Viewing.Document.getSubItemsWithProperties
method to get all the views.
There's also a line at lmvdbg at demonstrate how to load all the views.
这篇关于Autodesk Forge 查看器仅渲染 PDF 文件的单页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!