func getHtml() -> String {
// Create a HTML document to be printed
// Save data to file
let fileName = "noteImage.jpeg"
let pathToInvoiceHTMLTemplate = Bundle.main.path(forResource: "note", ofType: "html")
let tmpDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory())
let fileURL = tmpDirectoryURL.appendingPathComponent(fileName)
let mergedImages = getMergedImages()
//let pngImageData = UIImagePNGRepresentation(image)
let imageData = UIImageJPEGRepresentation(mergedImages, 1.0) // if you want to save as JPEG
try? imageData!.write(to: URL(fileURLWithPath: fileURL.path), options: [.atomic])
var htmlText = "<html><body><b>Problem Retrieving Note Template</b></body></html>"
do {
// Load the note HTML template code into a String variable.
htmlText = try String(contentsOfFile: pathToInvoiceHTMLTemplate!)
// Replace the variables in HTML.
htmlText = htmlText.replacingOccurrences(of: "__PROJECT_NAME__", with: projectName!)
htmlText = htmlText.replacingOccurrences(of: "__NOTE_NAME__", with: note!.name)
htmlText = htmlText.replacingOccurrences(of: "__NOTE_IMAGE__", with: "file:"+fileURL.path)
}
catch {
print("Unable to open and use HTML template files.")
}
return htmlText
}
func getPdf() -> NSMutableData {
// Create a PDF document from the HTML to be shared
// Format HTML
let fmt = UIMarkupTextPrintFormatter(markupText: getHtml())
// Assign print formatter to UIPrintPageRenderer
let render = UIPrintPageRenderer()
render.addPrintFormatter(fmt, startingAtPageAt: 0)
// Assign paperRect and printableRect
let page = CGRect(x: 0, y: 0, width: 595.2, height: 841.8) // A4, 72 dpi
let printable = page.insetBy(dx: 0, dy: 0)
render.setValue(NSValue(cgRect: page), forKey: "paperRect")
render.setValue(NSValue(cgRect: printable), forKey: "printableRect")
// Create PDF context and draw
let pdfData = NSMutableData()
UIGraphicsBeginPDFContextToData(pdfData, CGRect.zero, nil)
for i in 1...render.numberOfPages {
UIGraphicsBeginPDFPage();
let bounds = UIGraphicsGetPDFContextBounds()
render.drawPage(at: i - 1, in: bounds)
}
UIGraphicsEndPDFContext();
return pdfData
}
@IBAction func shareNote(_ sender: UIBarButtonItem) {
// Called in direct sharing
let firstActivityItem = "Text int the message"
let docToShare = getPdf()
let activityViewController : UIActivityViewController = UIActivityViewController(
activityItems: [firstActivityItem, docToShare], applicationActivities: nil)
// This lines is for the popover you need to show in iPad
activityViewController.popoverPresentationController?.barButtonItem = sender
// This line remove the arrow of the popover to show in iPad
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection()
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
// Anything you want to exclude
activityViewController.excludedActivityTypes = [
UIActivityType.postToWeibo,
UIActivityType.assignToContact,
UIActivityType.saveToCameraRoll,
UIActivityType.addToReadingList,
UIActivityType.postToFlickr,
UIActivityType.postToVimeo,
UIActivityType.postToTencentWeibo,
]
self.present(activityViewController, animated: true, completion: nil)
}
@IBAction func shareDocument(_ sender: UIBarButtonItem) {
// Called in the preview controller when the HTML is displayed
let firstActivityItem = "Text in the message"
let docToShare = getPdf()
let activityViewController : UIActivityViewController = UIActivityViewController(
activityItems: [firstActivityItem, docToShare], applicationActivities: nil)
// This lines is for the popover you need to show in iPad
activityViewController.popoverPresentationController?.barButtonItem = sender
// This line remove the arrow of the popover to show in iPad
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection()
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
// Anything you want to exclude
activityViewController.excludedActivityTypes = [
UIActivityType.postToWeibo,
UIActivityType.assignToContact,
UIActivityType.saveToCameraRoll,
UIActivityType.addToReadingList,
UIActivityType.postToFlickr,
UIActivityType.postToVimeo,
UIActivityType.postToTencentWeibo,
]
self.present(activityViewController, animated: true, completion: nil)
}
当我运行此代码时,它会抛出以下错误。
答案 0 :(得分:0)
您错过了第4个值:
insert into students (subject_id, subject_name, level_of_entry, exam_board)
values ('aldjk', 'sdad', 'adasd','<<ForthValue>>');
答案 1 :(得分:0)
IN Insert INTO
INSERT中的列数等于传递给它的值的数量,您可能缺少subject_id
的传递值
insert into students (subject_id, subject_name, level_of_entry, exam_board)
values (1,'aldjk', 'sdad', 'adasd');
--------^
答案 2 :(得分:0)
请提供您的第四栏的价值:
如果“subject_id”是您的表的主键并且它将是自动增量,那么您可以将其留空或在查询中忽略此字段。所以请使用下面提到的查询:
insert into students (`subject_id`, `subject_name`, `level_of_entry`, `exam_board`)
values ('', 'aldjk', 'sdad', 'adasd');
OR
insert into students (`subject_name`, `level_of_entry`, `exam_board`)
values ('aldjk', 'sdad', 'adasd');
了解更多click here