禁用HTML PDF查看器对象

时间:2016-12-28 16:59:28

标签: html css angularjs pdf

我在我的页面中嵌入了一个PDF viwer,并希望禁用该对象,使其无法与之交互(无滚动,无放大/缩小)。我的html对象如下所示:

<div id="pdf">
        <object width="650" height="500" type="application/pdf" data="./forms/my.pdf?#zoom=45&scrollbar=0&toolbar=0&navpanes=0" id="pdf_content">
            <p>PDF could not be loaded.</p>
        </object>
    </div>

甚至可以禁用该对象吗?

1 个答案:

答案 0 :(得分:1)

如果您的PDF在页面加载时按预期呈现,并且您只是想阻止鼠标交互,那么您可以使用CSS来隐藏一个不可见的元素:

#pdf {
  position: relative;
}

#pdf::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  z-index: 1;
  background: rgba(0, 0, 0, .3);
}

根据您的要求,可以开启/关闭此方法(使用jQuery):

&#13;
&#13;
$('#toggle').on('click', function() {

  if ($('#pdf').hasClass('enable')) {

    $('#pdf').removeClass('enable').on('mousedown scroll', function() { return false; });
    $(this).text('Enable PDF Interaction');

  } else {

    $('#pdf').addClass('enable').off();
    $(this).text('Disable PDF Interaction');

  }
});
&#13;
#pdf {
  position: relative;
  /* sizes for example since PDF won't load: */
  width: 650px;
  height: 500px;
}
#pdf::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  z-index: 1;
  background: rgba(0, 0, 0, .3);
}
#pdf.enable::before {
  content: none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button id="toggle">Disable PDF Interaction</button>

<div id="pdf" class="enable">
  <object width="650" height="500" type="application/pdf" data="https://upload.wikimedia.org/wikipedia/en/d/dc/Convergent_Synthesis_Example.pdf" id="pdf_content">
    <p>PDF could not be loaded.</p>
  </object>
</div>
&#13;
&#13;
&#13;