iOS new amazing feature AIRPRINT
Airprint is a technology developed by Apple which wirelessly prints documents when connected with an iOS device.
Add this code block in your IB action and run the application.
This tutorial is made with Xcode 9 and built for iOS 11.
In this tutorial, a PDF from a url will be printed by using Airprint.
1. Create a Single View Application on Xcode and open it.
2. Create a Print button and add an action.
3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if let pdfUrl = Bundle.main.url(forResource: "sample", withExtension: "pdf", subdirectory: nil, localization: nil) { | |
do { | |
let url = URL(string: "https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf") | |
let data = try Data(contentsOf: url!) | |
let sharedContent = [data] | |
let printController = UIPrintInteractionController.shared | |
let printInfo = UIPrintInfo(dictionary:nil) | |
printInfo.outputType = UIPrintInfoOutputType.general | |
printInfo.jobName = "print Job" | |
printController.printingItems = sharedContent | |
printController.printInfo = printInfo | |
printController.present(animated: true, completionHandler: nil) | |
self.present(activityViewController, animated: true, completion: nil) | |
} | |
catch { | |
print("failed to open pdf") | |
} | |
return | |
} |
This comment has been removed by the author.
ReplyDelete