Skip to content
New issue

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

功能请求:当某个页码数超过PDF总页数时警告用户 #35

Closed
qwinsi opened this issue Jun 13, 2024 · 3 comments
Closed

功能请求:当某个页码数超过PDF总页数时警告用户 #35

qwinsi opened this issue Jun 13, 2024 · 3 comments

Comments

@qwinsi
Copy link

qwinsi commented Jun 13, 2024

背景

今天在用软件的时候遇到了个问题

Screenshot

输出的目录从"4.3 Plotting Ohm's Law"这一节开始就卡在第122页不增长了,往下都是清一色的第122页

但在预览界面上页码还是正常的

Screenshot 2024-06-13 092628

问题原因

我拉源码 Debug 到这个 _add_bookmark 函数才发现问题:原来我犯傻了,其实我的PDF文件总共就只有122页!

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) 做了兜底了。

期望行为

虽然是我作为用户输入了不正常的页码有错在先,但还是希望如果某个页码数超过了 PDF 实际的总页数,能做点什么让用户察觉到,比如说下面的措施之一

  • 当用户在左侧文本区输入了过大的页码数时,在预览区下方显示 "Invalid" 之类的提示性文字。
  • 当用户执行写入时,弹窗警告。

个人认为这种使用场景还是不罕见的,比如用户页码数多摁了个0,把 123 打成了 1230,再或者像我这次的情况,以为下载了全书,实际上是只包含前三章的预览版……

@chroming
Copy link
Owner

chroming commented Jun 14, 2024

确实值得加上~

@qwinsi
Copy link
Author

qwinsi commented Jul 12, 2024

发现这个功能从 v0.3.0-beta24 开始也实现了,再次感谢作者!

@qwinsi qwinsi closed this as completed Jul 12, 2024
@chroming
Copy link
Owner

感谢反馈~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants