简体   繁体   English

Autodesk Forge Viewer仅呈现PDF文件的单个页面

[英]Autodesk Forge viewer renders only single page for PDF files

In our application we're using Autodesk Forge Viewer to render 3D and 2D design files. 在我们的应用程序中,我们使用Autodesk Forge Viewer渲染3D和2D设计文件。 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. 但是对于pdf文件,即使文件实际上有多页,也仅显示第一页。 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? 为了使查看器还可以呈现多页pdf文件以及其他3D / 2D文件,我还需要做什么?

I couldn't find any way to configure this in the API documentation as well nor could I find it in any sample. 我也找不到在API文档中进行配置的任何方法,也无法在任何示例中找到它。

.pdf files are translated as 2D sheets in the viewer, each page in the .pdf file should appear as individual 2D views. .pdf文件被翻译为观众二维图纸,在每一页.pdf文件应该显示为单独的二维视图。

If you just use the boilerplate code from the Instantiate a Basic Viewer you'll get multiple views like so: 如果仅使用“ 实例化基本查看器”中的样板代码,则将获得多个视图,如下所示:

多个2D视图

Since you override onDocumentLoaded , take a look at how the Autodesk360App.js implemented onDocumentLoaded method. 由于您覆盖了onDocumentLoaded ,因此请看一下Autodesk360App.js如何实现onDocumentLoaded方法。 At line 621: 在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. onDocumentLoaded方法中,调用Autodesk.Viewing.Document.getSubItemsWithProperties方法以获取所有视图。

There's also a line at lmvdbg at demonstrate how to load all the views. lmvdbg上还有一行可以演示如何加载所有视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM