简体   繁体   中英

Native PDF and DWF viewing on Forge Viewer without translation

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

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>

This line:

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

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:

Error 1 Error 2

Could you please suggest a solution?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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