在 Forge Viewer 上查看原生 PDF 和 DWF,无需翻译 [英] Native PDF and DWF viewing on Forge Viewer without translation

查看:26
本文介绍了在 Forge Viewer 上查看原生 PDF 和 DWF,无需翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在没有 SVF 转换的情况下以本机方式显示 DWF 文件和 PDF 文件.我在这里关注这个博客:

I'm trying to show DWF files and PDF files natively without SVF translation. I'm following this blog here:

https://forge.autodesk.com/blog/dwf-and-pdf-support-forge-viewer

从一个 PDF 示例开始,这是我正在使用的代码(Petr Broz 在其中一篇 stackoverflow 帖子中建议)

Starting with a PDF example, this is the code I'm using (suggested by Petr Broz in one of the stackoverflow posts)

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <link rel="stylesheet" href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.css">
        <style>
            body,
            html {
                margin: 0;
                padding: 0;
                height: 100vh;
            }

            #preview {
                position: absolute;
                width: 100%;
                height: 100%;
            }
        </style>
        <title>Autodesk Forge: PDF Demo</title>
    </head>

    <body>
        <div id="preview"></div>
        <script src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.js"></script>
        <script>
            Autodesk.Viewing.Initializer({ accessToken: '' }, async function () {
                const viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('preview'));
                viewer.start();
                await viewer.loadExtension('Autodesk.PDF');
                viewer.loadModel('https://developer.api.autodesk.com/oss/v2/signedresources/44b4af63-bd11-4a0f-8231-b1cbd14da3d9?region=US');
            });
        </script>
    </body>

    </html>

这一行:

viewer.loadModel('https://developer.api.autodesk.com/oss/v2/signedresources/44b4af63-bd11-4a0f-8231-b1cbd14da3d9?region=US');
                });

显示位于 oss 存储桶中的 pdf 文件的签名 url.这是将文件传递给此方法的正确方法吗?因为我收到以下错误:

shows a signed url of a pdf file that resides in an oss bucket. Is this the correct way to pass the file to this method? because I'm getting the following errors:

错误 1错误 2

你能提出一个解决方案吗?

Could you please suggest a solution?

推荐答案

查看器要求 URL 以特定的文件扩展名结尾,以便它知道要使用哪个加载程序.如您所见,签名网址不包含该信息.

The viewer requires the URL to end with a specific file extension so that it knows which loader to use. And as you can see, signed URLs don't include that info.

您可以通过在签名 URL 末尾将文件扩展名作为附加查询参数传递来解决此问题,例如,如下所示:

You can work around that by passing the file extension as an additional query parameter at the end of of your signed URL, for example, like this:

https://developer.api.autodesk.com/oss/v2/signedresources/44b4af63-bd11-4a0f-8231-b1cbd14da3d9?region=US&format=.pdf

这篇关于在 Forge Viewer 上查看原生 PDF 和 DWF,无需翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆