gpt4 book ai didi

python - 如何以编程方式创建 PDFOutline

转载 作者:太空宇宙 更新时间:2023-11-03 14:06:42 24 4
gpt4 key购买 nike

我在尝试在 PDF 文件中创建目录对象时遇到问题。我不确定我是否从 Apple 有限的文档中理解了该过程。

我使用的是 python,但欢迎使用任何语言的令人信服的示例来解释它应该如何工作。该代码创建了一个新的 PDF 文档,但预览中没有可见的大纲项目。我尝试过仅使用 myOutline 作为根对象,但这也不起作用。

pdfURL = NSURL.fileURLWithPath_(infile)
myPDF = Quartz.PDFDocument.alloc().initWithURL_(pdfURL)
if myPDF:
# Create Destination
myPage = myPDF.pageAtIndex_(1)
pagePoint = Quartz.CGPointMake(0,0)
myDestination = Quartz.PDFDestination.alloc().initWithPage_atPoint_(myPage, pagePoint)

# Create Outline
myOutline = Quartz.PDFOutline.alloc().init()
myOutline.setLabel_("Interesting")
myOutline.setDestination_(myDestination)

# Create a root Outline and add the first outline as a child
rootOutline = Quartz.PDFOutline.alloc().init()
rootOutline.insertChild_atIndex_(myOutline, 0)

# Add the root outline to the document and save
myPDF.setOutlineRoot_(rootOutline)
myPDF.writeToFile_(outfile)

编辑:实际上,大纲已保存到新文件中:我可以通过编程方式读取它,并且它作为书 checkout 现在 Acrobat 中;但是,它没有显示在预览的目录中(是的,我检查了“隐藏”)。如果我在 Acrobat 中添加另一个书签,则两者都会显示在预览中。

所以我想要么我仍然做错了什么,没有完全正确地“完成”PDFOutline 数据,并且 Acrobat 很友善;或者 PDFKit 中存在一个巨大的错误,这意味着您无法正确编写 PDFOutlines。我在 Mountain Lion 上也有同样的行为,FWIW。

最佳答案

这确实是预览版中的一个错误。如果目录仅包含一个子条目,则不会列出目录。

如果我使用上面的代码添加更多大纲,那么所有这些都会出现在预览中。如果使用其他软件删除目录中的除一个条目外的所有条目,则预览将不会显示任何

关于python - 如何以编程方式创建 PDFOutline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48841581/

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