Chrome中通过object标签隐藏PDF侧边栏但保留工具栏的方法
解决PDF渲染隐藏侧边栏但保留工具栏的问题
不同浏览器的PDF渲染引擎支持的哈希参数存在差异,以下是针对主流浏览器的有效方案:
Chrome/Edge(PDFium引擎)
使用#pagemode=none参数,该参数会隐藏侧边栏(包括缩略图、书签等面板),同时默认保留顶部工具栏。如果需要页面宽度适配容器,可搭配view=FitH参数:<object class="document-preview" data="/path/to/the_file.pdf#pagemode=none&view=FitH" style="border: none;" width="100%" height="650" type="application/pdf" > <p>Sorry, this document could not be displayed.</p> </object>Firefox(PDF.js引擎)
使用#sidebar=hidden参数,可单独隐藏缩略图侧边栏,同时保留顶部工具栏:<object class="document-preview" data="/path/to/the_file.pdf#sidebar=hidden" style="border: none;" width="100%" height="650" type="application/pdf" > <p>Sorry, this document could not be displayed.</p> </object>
为了兼容多浏览器,可以组合两个参数,让不同引擎各自识别对应的参数:
data="/path/to/the_file.pdf#pagemode=none&sidebar=hidden"
内容的提问来源于stack exchange,提问作者Max Williams
相关产品推荐
相关产品推荐

