We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
今天在用软件的时候遇到了个问题
输出的目录从"4.3 Plotting Ohm's Law"这一节开始就卡在第122页不增长了,往下都是清一色的第122页
但在预览界面上页码还是正常的
我拉源码 Debug 到这个 _add_bookmark 函数才发现问题:原来我犯傻了,其实我的PDF文件总共就只有122页!
_add_bookmark
def _add_bookmark(pdf, index_dict): if not index_dict: return None m = max(index_dict.keys()) parent_dict = {} # {parent index:IndirectObject} max_page_num = len(pdf.writer.pages) - 1 for i in range(m+1): value = index_dict[i] inobject = pdf.add_bookmark(value.get('title', ''), min(value.get('real_num', 1) - 1, max_page_num), parent_dict.get(value.get('parent'))) parent_dict[i] = inobject
从代码上来看,输出目录一直卡在第122页是因为这个函数里 min(value.get('real_num', 1) - 1, max_page_num) 做了兜底了。
min(value.get('real_num', 1) - 1, max_page_num)
虽然是我作为用户输入了不正常的页码有错在先,但还是希望如果某个页码数超过了 PDF 实际的总页数,能做点什么让用户察觉到,比如说下面的措施之一
个人认为这种使用场景还是不罕见的,比如用户页码数多摁了个0,把 123 打成了 1230,再或者像我这次的情况,以为下载了全书,实际上是只包含前三章的预览版……
The text was updated successfully, but these errors were encountered:
确实值得加上~
Sorry, something went wrong.
Check pdf real page number before write to pdf #35
5797113
发现这个功能从 v0.3.0-beta24 开始也实现了,再次感谢作者!
感谢反馈~
No branches or pull requests
背景
今天在用软件的时候遇到了个问题
输出的目录从"4.3 Plotting Ohm's Law"这一节开始就卡在第122页不增长了,往下都是清一色的第122页
但在预览界面上页码还是正常的
问题原因
我拉源码 Debug 到这个
_add_bookmark
函数才发现问题:原来我犯傻了,其实我的PDF文件总共就只有122页!从代码上来看,输出目录一直卡在第122页是因为这个函数里
min(value.get('real_num', 1) - 1, max_page_num)
做了兜底了。期望行为
虽然是我作为用户输入了不正常的页码有错在先,但还是希望如果某个页码数超过了 PDF 实际的总页数,能做点什么让用户察觉到,比如说下面的措施之一
个人认为这种使用场景还是不罕见的,比如用户页码数多摁了个0,把 123 打成了 1230,再或者像我这次的情况,以为下载了全书,实际上是只包含前三章的预览版……
The text was updated successfully, but these errors were encountered: