首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在PrintPanel中添加“PrintPanel”以表示PDFDocument

在PrintPanel中添加“PrintPanel”以表示PDFDocument
EN

Stack Overflow用户
提问于 2019-08-17 14:39:40
回答 1查看 206关注 0票数 0

我有一个显示PDFView的应用程序,我希望它能从视图中打印PDF文件。另外,我希望打印面板显示页面设置附件(即纸张大小、方向和比例设置,如预览版,它显示为选项下拉列表的一个面板)。

目前,我错误地打印了PDFView,而不是PDF文档本身。这只给我一页,并包括滚动条打印出来!我看不出如何init引用PDFDocument而不是PDFViewNSPrintOperation

这是我的代码,它有效,但不是我想要的。我想我必须用定义面板和信息的类似代码覆盖printDocumentprintOperation函数NSDocument

代码语言:javascript
复制
func thePrintInfo() -> NSPrintInfo {
    let thePrintInfo = NSPrintInfo()
    thePrintInfo.horizontalPagination = .automatic // Tried fit
    thePrintInfo.verticalPagination = .automatic // Tried fit
    thePrintInfo.isHorizontallyCentered = true // Tried false
    thePrintInfo.isVerticallyCentered = true // Tried false
    thePrintInfo.leftMargin = 0.0
    thePrintInfo.rightMargin = 0.0
    thePrintInfo.topMargin = 0.0
    thePrintInfo.bottomMargin = 0.0
    thePrintInfo.jobDisposition = .spool
    return thePrintInfo
}

// Need to show the 'Page Setup' Options as an Accessory
// e.g. Paper size, orientation.
@IBAction func printContent(_ sender: Any) {
    let printOperation = NSPrintOperation(view: thePDFView, printInfo: thePrintInfo())
    let printPanel = NSPrintPanel()
    printPanel.options = [
        NSPrintPanel.Options.showsCopies,
        NSPrintPanel.Options.showsPrintSelection,
        NSPrintPanel.Options.showsPageSetupAccessory,
        NSPrintPanel.Options.showsPreview
    ]
    printOperation.printPanel = printPanel
    printOperation.run()
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-18 10:16:59

基于@Willeke的评论,我想出了以下几点,似乎效果很好。(小问题是打印对话框不是工作表。)如果任何人有任何改进,请张贴一个更好的答案。

代码语言:javascript
复制
@IBAction func printContent(_ sender: Any) {
   let printOperation = thePDFView.document?.printOperation(for: thePrintInfo(), scalingMode: .pageScaleNone, autoRotate: true)
printOperation?.printPanel = thePrintPanel()
printOperation?.run()
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57537247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档