gpt4 book ai didi

javascript - pdfium 是否将其 api 公开给 javascript?我想获取当前页数,但是该怎么做呢?

转载 作者:行者123 更新时间:2023-11-29 14:49:18 34 4
gpt4 key购买 nike

众所周知,pdfium 现在是 chrome 的一部分,这是一个很好的 pdf 渲染器,但我遇到了一些问题。

代码如下,默认页数为12,由#page=12赋值,当打开该页时,可以跳转或导航到其他页,但如何使用javascript获取页码?有没有我可以用来获取页码的 js api?

<head>
<style type="text/css">
.pdf {
width: 100%;
height: 99%;
}
</style>
</head>

<div>
okok
</div>

<iframe class="pdf" src="http://127.0.0.1/test.pdf#page=12" frameborder="0"></iframe>

最佳答案

我也在寻找 JS API。在 http://src.chromium.org/viewvc/chrome/trunk/src/pdf/instance.cc

如果有人需要,有以下方法:

object accessibility()
bool documentLoadComplete()
number getHeight()
number getHorizontalScrollbarThickness()
string getPageLocationNormalized()
number getVerticalScrollbarThickness()
number getWidth()
double getZoomLevel()
void goToPage(int arg)
void grayscale(bool arg)
void loadPreviewPage(string arg0, int arg1)
void onload(function arg)
void onPluginSizeChanged(function arg)
void onScroll(function arg)
number pageXOffset()
number pageYOffset()
void printPreviewPageCount(int arg)
void reload()
void removePrintButton()
void resetPrintPreviewUrl(string arg)
void sendKeyEvent(number arg)
void setPageNumbers(string arg)
void setPageXOffset(number arg)
void setPageYOffset(number arg)
void setZoomLevel(double arg)
void fitToHeight()
void fitToWidth()
void zoomIn()
void zoomOut()
void print()

获取当前页面的例子就是这样

<html>
<head>
<script type='text/javascript'>

window.addEventListener('load', function(){

var embed = document.getElementsByName('plugin')[0];
// this method should return the page location (not the page number, i suppose that made some calculation on the portion of PDF that is showed in the embed window)
alert(embed.getPageLocationNormalized());
// we can use other api methods
embed.removePrintButton();

}, false);
</script>
</head>
<body marginwidth='0' marginheight='0' style='background-color: rgb(38,38,38)' width='100%' height='100%'>
<embed width='100%' height='100%' name='plugin' src='path_to_pdf_file' type='application/pdf' />
</body>
</html>

关于javascript - pdfium 是否将其 api 公开给 javascript?我想获取当前页数,但是该怎么做呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28391198/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com