नोट: मैं मैकोज़ के लिए स्विफ्ट 4 के साथ काम कर रहा हूं।एक स्थिर शीर्षलेख
मेरे पास NSTableView
है जो डेटा से भरा जा सकता है और कोर डेटा में सहेजा जा सकता है। मैं "डिज़ाइन" के साथ TableView मान प्रदर्शित करना चाहता हूं।
मैं इसे इस तरह एहसास हो गया:
- एक एचटीएमएल टेम्पलेट
- स्ट्रिंग के रूप एचटीएमएल कोड प्राप्त बनाया है और मेरी tableview के साथ "एचटीएमएल प्लेसहोल्डर" को महत्व देता
- संशोधित html स्ट्रिंग दिखाने की जगह वेब दृश्य के माध्यम से
अच्छा काम करता है! और यह "समाधान" स्वचालित रूप से करना होगा पृष्ठ विराम :)
यहाँ मेरी कोड
// Example with statics values
func createHTML() {
let pathToHTMLTemplate = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("basic.html")
let pathToNoticeHTMLTemplate = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("notice.html")
do {
htmlString = try String(contentsOf: pathToInvoiceHTMLTemplate)
for _ in 0 ..< 40 {
var itemHTMLContent = try String(contentsOf: pathToNoticeHTMLTemplate)
itemHTMLContent = itemHTMLContent.replacingOccurrences(of: "#NOTICE_NAME#", with: "My notice")
htmlPositionen += itemHTMLContent
}
htmlString = htmlString.replacingOccurrences(of: "#NOTICE#", with: htmlPositionen)
let totalCount = 20 //Fix value as example
htmlString = htmlString.replacingOccurrences(of: "#TOTAL_COUNT#", with: "\(totalCount)")
myWebView.mainFrame.loadHTMLString(htmlString, baseURL: nil)
} catch {}
}
का एक छोटा सा और मैं इस मुद्रित कर सकते हैं:
func webView(_ sender: WebView!, didFinishLoadFor frame: WebFrame!) {
let fileURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("test.pdf")
let printInfo = NSPrintInfo.shared
printInfo.paperSize = NSMakeSize(595.22, 841.85)
printInfo.isHorizontallyCentered = true
printInfo.isVerticallyCentered = true
printInfo.orientation = .portrait
printInfo.topMargin = 50
printInfo.rightMargin = 0
printInfo.bottomMargin = 50
printInfo.leftMargin = 0
printInfo.verticalPagination = .autoPagination
let printOp = NSPrintOperation(view: sender.mainFrame.frameView.documentView, printInfo: printInfo)
printOp.showsProgressPanel = false
printOp.showsPrintPanel = false
printOp.run()
printOp.cleanUp()
}
लेकिन वहाँ एक समस्या है: - मैं शीर्ष
पर किसी पृष्ठ को फिर से तोड़ने के बाद लाल "नोटिस-हेडर" प्राप्त करना चाहता हूं, किसी को भी कोई विचार है, मैं इसे कैसे महसूस कर सकता हूं?
अद्यतन
हो सकता है कि वेब दृश्य सकता है में मदद करता है के इस तरीकों?
func webView(_ sender: WebView!, drawFooterIn rect: NSRect) {
// DO SOMETHING
}
func webView(_ sender: WebView!, drawHeaderIn rect: NSRect) {
// DO SOMETHING
}