FB 即阅文:我可以在即阅文中显示 PDF 文件吗?

FB Instant Articles: Can i display a PDF file inside an instant article?

我是 facebook instant articles 的新手。 我有一个依赖PDF文件来表示政治研究的网站,该网站上的每篇文章(页面)都包含一个PDF文件。 有没有办法在即时文章中显示 PDF 文件?

即阅文不支持 PDF 格式。您可以看到所有支持的格式 here 但是 您应该仍然能够将 pdf 显示为 op-interactive(嵌入)。请参阅此处的文档: https://developers.facebook.com/docs/instant-articles/reference/embeds

它基本上只是一个 iframe,您可以向其中添加内联 js 脚本或指向使用类似 pdf.js 的托管页面。

这里有一些假设 pdf.js:

的例子

嵌入式操作交互(未经测试,从他们的 github 文档中获取):

<figure class="op-interactive">
    <iframe>
        <script>
            var url = './helloworld.pdf';
            PDFJS.workerSrc = 'http://yourdomain.com/build/pdf.worker.js';
            PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf) {
                pdf.getPage(1).then(function getPageHelloWorld(page) {
                    var scale = 1.5;
                    var viewport = page.getViewport(scale);
                    var canvas = document.getElementById('the-canvas');
                    var context = canvas.getContext('2d');
                    canvas.height = viewport.height;
                    canvas.width = viewport.width;
                    var renderContext = {
                        canvasContext: context,
                        viewport: viewport
                    };
                    page.render(renderContext);
                });
            });
        </script>
    </iframe>
</figure>

URL 基于 op-interactive:

<figure class="op-interactive">
  <iframe src="https://yourdomain.com/pdfembed.html" width="600" height="600"></iframe>
</figure>

目前确实没有其他方法可以做到。