Post not yet marked as solved
Hi,
In Windows and Linux, it's possible to ask a printer to print content programmatically in Black & White. This may be referred to as "Monochrome", "Grayscale", "B&W", depending on the device driver.
For feature parity with other operating systems, I'd like to do the same -- programmatically -- in macOS using Objective-C or Swift. Is this possible? If not, what's the best, formal way to request this useful OS feature to Apple so that it may be added in a future release?
More context about this request:
https://github.com/openjdk/jdk/pull/18195
Post not yet marked as solved
UIPrintInteractionController crashed when I use it to print a html content.
Fatal Exception: NSInternalInconsistencyException
UITableView dataSource returned a nil cell for row at index path: <NSIndexPath: 0x938e90f84baaa518> {length = 2, path = 1 - 0}. Table view: <UITableView: 0x107991000; frame = (0 0; 375 419); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x2846b0000>; backgroundColor = <UIDynamicSystemColor: 0x281d2e400; name = systemGroupedBackgroundColor>; layer = <CALayer: 0x2848aa480>; contentOffset: {0, -56}; contentSize: {375, 357.0830078125}; adjustedContentInset: {56, 0, 0, 0}; dataSource: <UIPrintOptionsTableViewController: 0x107973800>>, dataSource: <UIPrintOptionsTableViewController: 0x107973800>
here is the code
private let webView = WKWebView()
private let printController = UIPrintInteractionController.shared
func showPrintView(encodedHtml: String) {
printController.delegate = self
let decodedHtmlString = base64Decode(encodedHtml)
webView.loadHTMLString(decodedHtmlString, baseURL: nil)
loadPrint()
}
private func loadPrint() {
let printInfo = UIPrintInfo(dictionary: nil)
printInfo.orientation = .landscape
printController.printInfo = printInfo
printController.printFormatter = webView.viewPrintFormatter()
Timer.scheduledTimer(withTimeInterval: 0.6, repeats: false) { _ in
self.printController.present(animated: true) { _, _, error in
guard let error = error else { return }
self.error = error
}
}
}
private func base64Decode(_ text: String) -> String {
if let restoreData = Data(base64Encoded: text) {
if let restoreString = String(data: restoreData, encoding: .utf8) {
return restoreString
}
}
return ""
}
I'm sure did nothing with UIPrintOptionsTableViewController so I have no idea how did this crash happened and how to fix it. Can someone help me?
Post not yet marked as solved
After updating to the lates OS many of the standard page sizes have disappeared from the HP Officejet Pro 7740 setting such as the full bleed 8.5 x 11 and full bleed 11 x 17... is this up to to correct or HP?
Post not yet marked as solved
After updating to Mac OS Sonoma, we have encountered compatibility issues with our iPad-designed application, specifically with the AirPrint functionality, when it is run on MacOS. The AirPrint feature stopped working properly through UIPrintInteractionController.shared.
We have noticed that when we compile the application using Catalyst, the AirPrint functionality is restored and works as expected. However, this solution is not viable for us due to the restrictions associated with the frameworks we are utilizing.
We are seeking alternative solutions, and any help or guidance would be highly appreciated to resolve this issue and ensure a seamless and uninterrupted user experience in our application.
STEPS TO REPRODUCE
Create an app for ipad with just a button and this code
var str = "TEST"
let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = .general
printInfo.jobName = "Report"
printInfo.orientation = .portrait
let printController = UIPrintInteractionController.shared
printController.printInfo = printInfo
printController.showsNumberOfCopies = false
printController.showsPageRange = false
printController.showsNumberOfCopies = false
let formatter = UIMarkupTextPrintFormatter(markupText: str)
formatter.contentInsets = UIEdgeInsets(top: 72, left: 72, bottom: 72, right: 72)
printController.printFormatter = formatter
printController.present(animated: true, completionHandler: nil)
2.Run it on a MacOS with Sonoma, there is no error on console or anything but it don't work.
-If you run it with Catalyst it just works when adding the Printing permission of App Sandbox in Signing & Capabilities.
Post not yet marked as solved
For printing from worker thread to a UIPrinter(whose url i have saved ) i am doing this and able to print :
func PrintPdfDocument (pDocument:Data)
{
// Create a print interaction controller
let printController = UIPrintInteractionController.shared
// Set the printing options
let printInfo = UIPrintInfo(dictionary:nil)
printInfo.jobName = "Print Job "
printController.printInfo = printInfo
printController.showsPageRange = true
// Set the PDF document to be printed
printController.printingItems = pDocument
printController.print(to: defaulttprinter, completionHandler: { (controller, completed, error) in
if completed {
print("Printing successful!")
} else {
if let error = error {
print("Printing failed with error: \(error.localizedDescription)")
} else {
print("Printing was canceled.")
}
}
})
}
When i call PrintPdfDocument (pDocument:Data) function , more than once with diffrent data shown below :
DispatchQueue.global().async {
PrintPdfDocument (pDocument:data1)
}
DispatchQueue.global().async {
PrintPdfDocument (pDocument:data2)
}
DispatchQueue.global().async {
PrintPdfDocument (pDocument:data3)
}
Printer is printing only one document(data1) .
For other call is not executing printController.print (to....) function inside PrintPdfDocument.
Post not yet marked as solved
I'm working with cupsfilter command to convert files from PDF to PS.
We had been previously working with cupsfilter on Linux, but we had to migrate to macOS and some of the command line arguments are not compatible.
In particular, we can't control autorotation and scaling on macOS. They seem to be "on" by default, but there are some cases where we need to turn them "off" so page doesn't rotate or scale to fit automatically.
On Linux, those options are controlled with -o nopdfAutorotate and -o nofit-to-page.
Any ideas how to control rotation and scaling on macOS?
Thank you very much in advance.
I want to use CUPS in iOS for printing and it is mentioned at many places that we can use cups for printing in ios .But when i import library cups/cups.h ,xcode is giving error "cups/cups.h not found".
code i am using in a objective c file :
import &lt;cups/cups.h&gt;
cups_dest_t *dest;
int num_options;
cups_option_t *options;
int job_id;
/* Print a single file */
job_id = cupsPrintFile(dest-&gt;name, "/usr/share/cups/data/testprint.ps",
"Test Print", num_options, options);
Do i need to intall some driver or any library to make it work ? or is it the case that CUPS is not available for iOS?
Post not yet marked as solved
We have an app that exports PDFs with a custom page size, using PSDKit. In iOS16 the PDF export would have the correct page size dimensions, but now iOS17 exports everything to a Letter (8.5x11) size, regardless of what the PDF size specs are defined in the code:
let pageWidth: CGFloat = 86.0 / 25.4 * 72
let pageHeight: CGFloat = 54.0 / 25.4 * 72
let pageSize = CGRect(x: 0, y: 0, width: pageWidth, height: pageHeight)
Any thoughts as to how to fix this?
Post not yet marked as solved
Fatal Exception: NSInvalidArgumentException
<UIPrintPanelNavigationController: 0x144010a00> is pushing the same view controller instance (<UIPrinterBrowserViewController: 0x142854400>) more than once which is not supported and is most likely an error in the application : com.myapp.myapp
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0xec870 __exceptionPreprocess
1 libobjc.A.dylib 0x2bc00 objc_exception_throw
2 UIKitCore 0xcb284 -[UINavigationController pushViewController:transition:forceImmediate:]
3 UIKitCore 0xca398 -[UINavigationController pushViewController:animated:]
4 PrintKitUI 0x45024 -[UIPrintPanelNavigationController pushViewController:animated:]
5 UIKitCore 0x129b78 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:]
6 UIKitCore 0x129680 -[_UIViewControllerTransitionContext _runAlongsideCompletions]
7 UIKitCore 0x128d10 -[_UIViewControllerTransitionContext completeTransition:]
8 UIKitCore 0x7a3d48 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke_5
9 UIKitCore 0x84a38 __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__
10 UIKitCore 0x841d0 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:]
11 UIKitCore 0x83848 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
12 UIKitCore 0x65aa4 -[UIViewAnimationState animationDidStop:finished:]
13 UIKitCore 0x65bb8 -[UIViewAnimationState animationDidStop:finished:]
14 QuartzCore 0x72098 run_animation_callbacks(void*)
15 libdispatch.dylib 0x4300 _dispatch_client_callout
16 libdispatch.dylib 0x12998 _dispatch_main_queue_drain
17 libdispatch.dylib 0x125b0 _dispatch_main_queue_callback_4CF
18 CoreFoundation 0x3720c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
19 CoreFoundation 0x33f18 __CFRunLoopRun
20 CoreFoundation 0x33668 CFRunLoopRunSpecific
21 GraphicsServices 0x35ec GSEventRunModal
22 UIKitCore 0x22c2b4 -[UIApplication _run]
23 UIKitCore 0x22b8f0 UIApplicationMain
24 MyApp 0x4a940 main + 14 (main.m:14)
25 ??? 0x1ac55adcc (Missing)
I found this crash in Firebase crashlytics.
This is device info
Model:iPad Air (5th generation)
Version:17.1.1
Orientation:Landscape
Please help me to findout the root cause of the crash and possible solution.
I have tried to reprduce the crash but didn't reproduce.
Post not yet marked as solved
I use the following code to print PDF:
let printInfo = UIPrintInfo.printInfo()
printInfo.outputType = UIPrintInfo.OutputType.general
printInfo.jobName = "My Print Job"
printInfo.orientation = .portrait
let printController = UIPrintInteractionController.shared
printController.printInfo = printInfo
printController.printingItem = pdfData
printController.delegate = self
printController.present(animated: true, completionHandler: nil)
Everything works fine, but according to the Xcode Organizer, some users experience sporadic crashes after initiating printing. It appears that these crashes may be related to updates in the UI within UIPrintInteractionController. The majority of these crashes occur on iOS 16, with a few also affecting iOS 17. I am unable to reproduce the issue.
Stack trace for iOS 16.6.1:
Fatal Exception: NSInternalInconsistencyException
Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (0), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out). Collection view: <UICollectionView: 0x14d9a1a00; frame = (0 0; 235 944); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x281fe9fb0>; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x28164e660>; contentOffset: {0, 0}; contentSize: {235, 88}; adjustedContentInset: {0, 0, 0, 0}; layout: <UIPrintPreviewFlowLayout: 0x14b7c1320>; dataSource: <UIPrintPreviewViewController: 0x14d811200>>
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x9cb4 __exceptionPreprocess
1 libobjc.A.dylib 0x183d0 objc_exception_throw
2 Foundation 0x4e154c _userInfoForFileAndLine
3 UIKitCore 0x7024f4 -[UICollectionView _Bug_Detected_In_Client_Of_UICollectionView_Invalid_Number_Of_Items_In_Section:]
4 UIKitCore 0x30d5a8 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:collectionViewAnimator:]
5 UIKitCore 0x26bd5c -[UICollectionView _updateRowsAtIndexPaths:updateAction:updates:]
6 UIKitCore 0x26d0e0 -[UICollectionView reloadItemsAtIndexPaths:]
7 PrintKitUI 0x2677c __55-[UIPrintPreviewViewController updatePrintPreviewInfo:]_block_invoke_3
8 UIKitCore 0x30494 +[UIView(Animation) performWithoutAnimation:]
9 PrintKitUI 0x266c8 __55-[UIPrintPreviewViewController updatePrintPreviewInfo:]_block_invoke
10 PrintKitUI 0x57b30 -[UIPrintPreviewPageFetcher resetAllPages:]
11 PrintKitUI 0x26460 -[UIPrintPreviewViewController updatePrintPreviewInfo:]
12 PrintKitUI 0x47b84 -[UIPrintPanelViewController updatePrintPreviewInfo]
13 PrintKitUI 0x45d5c -[UIPrintPanelViewController observeValueForKeyPath:ofObject:change:context:]
14 Foundation 0x3c0d0 NSKeyValueNotifyObserver
15 Foundation 0x52618 NSKeyValueDidChange
16 Foundation 0x3f518 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:]
17 Foundation 0x3f248 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:]
18 Foundation 0x3e1f8 _NSSetLongLongValueAndNotify
19 PrintKitUI 0x52e00 -[UIPrintInColorOption observeValueForKeyPath:ofObject:change:context:]
20 Foundation 0x3c0d0 NSKeyValueNotifyObserver
21 Foundation 0x52618 NSKeyValueDidChange
22 Foundation 0x3f518 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:]
23 Foundation 0x3f248 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:]
24 Foundation 0x3e7dc _NSSetObjectValueAndNotify
25 PrintKitUI 0x496f0 __51-[UIPrintPanelViewController lookupLastUsedPrinter]_block_invoke_2
26 libdispatch.dylib 0x2320 _dispatch_call_block_and_release
27 libdispatch.dylib 0x3eac _dispatch_client_callout
...
Stack trace for iOS 17.0.3:
Fatal Exception: NSInternalInconsistencyException
UITableView dataSource returned a nil cell for row at index path: <NSIndexPath: 0x96b9dd5bd6ad637d> {length = 2, path = 0 - 0}. Table view: <UITableView: 0x108846400; frame = (0 0; 430 542); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x281fa8ae0>; backgroundColor = <UIDynamicSystemColor: 0x280481bc0; name = systemGroupedBackgroundColor>; layer = <CALayer: 0x2817cbea0>; contentOffset: {0, -56}; contentSize: {430, 332.99999618530273}; adjustedContentInset: {56, 0, 0, 0}; dataSource: <UIPrintOptionsTableViewController: 0x108819600>>, dataSource: <UIPrintOptionsTableViewController: 0x108819600>
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0xed5e0 __exceptionPreprocess
1 libobjc.A.dylib 0x2bc00 objc_exception_throw
2 Foundation 0x6bc398 _userInfoForFileAndLine
3 UIKitCore 0x289d74 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:]
4 UIKitCore 0x289a70 -[UITableView _updateVisibleCellsForRanges:createIfNecessary:]
5 UIKitCore 0x287fbc -[UITableView _updateVisibleCellsNow:]
6 UIKitCore 0xfc45dc -[UITableView _updateAnimationDidStopWithOldVisibleViews:finished:context:]
7 UIKitCore 0x850bc __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__
8 UIKitCore 0x84854 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:]
9 UIKitCore 0x83ecc -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
10 UIKitCore 0x66498 -[UIViewAnimationState animationDidStop:finished:]
11 QuartzCore 0x7276c run_animation_callbacks(void*)
12 libdispatch.dylib 0x4300 _dispatch_client_callout
...
Full exception stacktrace iOS 16
Full exception stacktrace iOS 17
Is anyone experiencing similar issues?
Thanks!
Post not yet marked as solved
We have a software product that sends prints to a printer driver with the driver settings pre-saved to a file and applied at the time of printing. For reasons outside the scope of this question in some specific cases we need to open a pop up window for the OEM driver for the settings to be accepted by the OEM driver. In these cases the user has to click "Print" a second time, not ideal.
Our dev team is having a difficult time automatically clicking that second Print button so the user doesn't have to. The goal is the window would pop up for a fraction of a second and the file is sent off right away with only one click by the user.
I have personally tried playing around with AppleScript to accomplish this but have not been able to do so.
The application itself is written with QT and here is the info regarding the button in question from Accessibility Inspector:
Does anyone have any knowledge how to auto press this button?
Post not yet marked as solved
I'm using UIPrintInteractionController to display the standard printing window to print a PDF file, passed as NSData using 'setPrintingItem'. Everything was working fine until iOS 16. Now when I call 'presentAnimated', the printing window briefly appears before immediately closing again. In the Xcode debug window I see layout constraint errors - see text below.
I don't think I can affect the layout constraints of the print controller?
2022-09-13 16:57:43.220970+0100 myiOSApp[11359:185527] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x6000022e23a0 h=--& v=--& UIView:0x7fa0e588e5a0.minX == 0.5 (active, names: '|':UIView:0x7fa0e588bbe0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x6000022e3160 h=--& v=--& UIView:0x7fa0e588bbe0.minX == 0 (active, names: '|':UIPrintPreviewPageCell:0x7fa0e588e060 )>",
"<NSLayoutConstraint:0x6000022e0f00 UIView:0x7fa0e588e5a0.leading == UIPrintPreviewPageCell:0x7fa0e588e060.leading (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000022e0f00 UIView:0x7fa0e588e5a0.leading == UIPrintPreviewPageCell:0x7fa0e588e060.leading (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2022-09-13 16:57:43.221720+0100 myiOSApp[11359:185527] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x6000022e23a0 h=--& v=--& UIView:0x7fa0e588e5a0.minX == 0.5 (active, names: '|':UIView:0x7fa0e588bbe0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x6000022e2fd0 h=--& v=--& UIView:0x7fa0e588e5a0.width == 124.438 (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x6000022e3160 h=--& v=--& UIView:0x7fa0e588bbe0.minX == 0 (active, names: '|':UIPrintPreviewPageCell:0x7fa0e588e060 )>",
"<NSLayoutConstraint:0x6000022e0fa0 UIView:0x7fa0e588e5a0.trailing == UIPrintPreviewPageCell:0x7fa0e588e060.trailing (active)>",
"<NSLayoutConstraint:0x6000022e32a0 'UIView-Encapsulated-Layout-Width' UIPrintPreviewPageCell:0x7fa0e588e060.width == 125 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000022e0fa0 UIView:0x7fa0e588e5a0.trailing == UIPrintPreviewPageCell:0x7fa0e588e060.trailing (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2022-09-13 16:57:43.232533+0100 myiOSApp[11359:185527] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x6000022e05a0 h=--& v=--& UIView:0x7fa0e5895a60.minX == 0.5 (active, names: '|':UIView:0x7fa0e5891520 )>",
"<NSAutoresizingMaskLayoutConstraint:0x6000022e1630 h=--& v=--& UIView:0x7fa0e5891520.minX == 0 (active, names: '|':UIPrintPreviewPageCell:0x7fa0e58902c0 )>",
"<NSLayoutConstraint:0x6000022e0500 UIView:0x7fa0e5895a60.leading == UIPrintPreviewPageCell:0x7fa0e58902c0.leading (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000022e0500 UIView:0x7fa0e5895a60.leading == UIPrintPreviewPageCell:0x7fa0e58902c0.leading (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2022-09-13 16:57:43.233227+0100 myiOSApp[11359:185527] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x6000022e05a0 h=--& v=--& UIView:0x7fa0e5895a60.minX == 0.5 (active, names: '|':UIView:0x7fa0e5891520 )>",
"<NSAutoresizingMaskLayoutConstraint:0x6000022e0410 h=--& v=--& UIView:0x7fa0e5895a60.width == 124.438 (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x6000022e1630 h=--& v=--& UIView:0x7fa0e5891520.minX == 0 (active, names: '|':UIPrintPreviewPageCell:0x7fa0e58902c0 )>",
"<NSLayoutConstraint:0x6000022e0690 UIView:0x7fa0e5895a60.trailing == UIPrintPreviewPageCell:0x7fa0e58902c0.trailing (active)>",
"<NSLayoutConstraint:0x6000022e14f0 'UIView-Encapsulated-Layout-Width' UIPrintPreviewPageCell:0x7fa0e58902c0.width == 125 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000022e0690 UIView:0x7fa0e5895a60.trailing == UIPrintPreviewPageCell:0x7fa0e58902c0.trailing (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
Post not yet marked as solved
Previously in MacOS13 and below versions, we used get the printer name from the running applications by this below code:-
let apps = NSWorkspace.shared.runningApplications
for app in apps{
if(app.bundleIdentifier == "com.apple.print.PrinterProxy"){
let spoolerName = app.bundleURL?.deletingPathExtension().lastPathComponent
print("spooler name is : \(spoolerName ?? "")")
//spooler name is : HP LaserJet Pro M428f-M429f
}
}
In MacOS 14, the same approach is not able get the printer name as the implementation is modified to PrintCenter. So, can someone please suggest me the way to the fetch selected printer details from the printCenter.
let apps = NSWorkspace.shared.runningApplications
for app in apps{
if(app.bundleIdentifier == "com.apple.printcenter"){
let spoolerName = app.bundleURL?.deletingPathExtension().lastPathComponent
print("spooler name is : \(spoolerName ?? "")")
//spooler name is : Print Centre
}
}
Post not yet marked as solved
Environment→ ・Device: iPad 9th generation ・OS:iPadOS17.1、iPadOS16.6 ・Printer model:EPSON PX-S730
What I want→ I want to determine whether the printer and iPad are connected to the same Wi-Fi network.
Current issues→ When I run the below code on an iOS17 iPad, contactPrinter() becomes true even though you are not connected to the same network as the printer.
Problem Description→
I want to pass the URL of the printer that I have set in advance and print directly from the device to the printer.
So in iOS 16 when i execute the below code, without connecting to the same network as printer, return value of the "contactPrinter" method is FALSE.
once i update to iOS 17 and ran the same code with the same conditions(iPad and printer not connected to same network), return value becomes TRUE.
[I'm using "contactPrinter" method because after update to iOS 17 i was able to successfully launch a print job even if your device isn't connected to the same network as your printer.But in iOS 16 it return as an Error.]
Is this a bug in iOS 17? Or is the method used incorrectly?
Test code:
let printer = UIPrinter(url: URL(string: "printer url")!)
printer.contactPrinter { (available) -> Void in
if (available) { // iOS17.1:true, iOS16.6:false
print("connected to printer")
printController.print(to: printer, completionHandler: printCompletionHandler)
} else {
print("not connected to printer")
}
}
Post not yet marked as solved
I am having problems printing a pdf file in an iPad app when running iPadOS15 or later.
With previous iPadOS versions, the choosePaper delegate method is called just once, and is called with a paperList of several valid entries (30 in the case of my printer).
Since iPadOS 15, the call is made numerous times.
Firstly, it is called a few time with 0 entries in the paperList.
Then it is called with the correct number (30 in my case) of entries.
But then it is called several more times, with just 1 (and incorrect) entry in the paperList.
Has anyone else come across this?
Post not yet marked as solved
Recently I was responsible for a project to print PDF reports.
The challenge I'm facing is that the tablets used by clients are shared, and they frequently change the print settings on these tablets. However, my app needs to ensure that it always prints in single-sided format (as the reports from another department require the company logo to be printed).
I've checked the code and found that I can use UIPrintInfo(dictionary: nil) to set it to single-sided printing. However, no matter how I set it, the printer still defaults to double-sided printing. Is there a way to ensure that when my app is using AirPrint, the print settings won't be affected by the global settings on the iPad?
Here is the code:
https://gist.github.com/oilking143/a1ea3cce9f73905046e20db0c37a847d
I appreciate any guidance on this matter. Thank you!
Post not yet marked as solved
Hey, fellow iOS developers! I'm working on an app for iOS 17 and need to implement single-side printing using the AirPrint API. I've done some research, but I'm still facing a few challenges. Can anyone provide guidance or share some sample code to achieve this?
I've already imported the UIKit and MobileCoreServices frameworks and have set up the basic AirPrint functionality. Now, I'm looking specifically for instructions and code to enable single-sided printing.
URL - https://www.controlf5.in/
Test code
`**import UIKit
import MobileCoreServices
// Set up AirPrint functionality
func printDocument() {
let printController = UIPrintInteractionController.shared
let printInfo = UIPrintInfo(dictionary: nil)
printInfo.outputType = .general
printController.printInfo = printInfo
let formatter = UIMarkupTextPrintFormatter(markupText: "Your printable content goes here")
formatter.perPageContentInsets = UIEdgeInsets(top: 36, left: 36, bottom: 36, right: 36)
printController.printFormatter = formatter
printController.present(animated: true) { (controller, success, error) in
if success {
print("Printing completed successfully")
} else if let error = error {
print("Printing failed with error: \(error.localizedDescription)")
}
}
}**`
Post not yet marked as solved
Environment→
・Device: iPad 9th generation
・OS:**iOS17.0.3
・Printer model:EPSON PX-S730
What I want→
I would like to return an error when I submit a printing job, if the printer is not properly connected to the same WIFI as iPad(iOS17).
Current issues→
When I run the below code in iOS17, I was able to successfully submit a print job to printer and, printer returns completed(true) as the result. In iOS16 print job return as an error to the same below code.
Problem Description→
In iOS 16.6.1 when you know the correct printer access URL and submit a print job without connecting to the same WIFI as the printer, job return as an error.(return to the error code segment in the below code)
But after I updated the app to iOS 17.0.3 and run the same job, it's not returning as an error.(it returns to the completed block in the below code segment and completed Boolean value is true. )
When you check the "Print Summary" window in iPad, the status of the print job is Waiting.
So I would like to handle this process in the same way like iOS16 in iOS17. I would like to Print Job to return as a error when printer and iPad not connected to same WIFI(error like "cannot connect to the printer")
Test code:
let printInfo = UIPrintInfo(dictionary: nil)
printInfo.jobName = "Print Job"
printController.printInfo = printInfo
let pdfURL = Bundle.main.url(forResource: "sample", withExtension: "pdf")!
printController.printingItem = pdfURL
let printer = UIPrinter(url: printerUrl)
printController.print(to: printer, completionHandler: { [self] printController, completed, error in
if(error != nil){
print("error")
}else if completed{
print("completed")
}else{
print("cancel")
}
})
Does anyone knows if it's a bug in iOS17 or am I missing something?
Post not yet marked as solved
Environment→
・Device: iPad 9th generation
・OS: iOS17.0.3
・Printer model: EPSON PX-S730
What I want→
I would like to programmatically use the AirPrint API to directly print from my application to a selected printer specifying the printing as single-side
Current issues →
After updating the iOS from 16.6.1 to 17 version, when printing programmatically using the AirPrint API, even setting the print options as single-side, it end up printing on double- side.
Issue description→
When I run the code below on iOS16.6.1, it prints on single-side,** but after updating to iOS17.0.3, It’s always printing on double-sides.**
Also, the Apple Developer Documentation says that the print method disables duplex printing and it's describe in below URL:
https://developer.apple.com/documentation/uikit/uiprintinteractioncontroller/1618174-print
Test code:
let printInfo = UIPrintInfo(dictionary: nil)
printInfo.jobName = "Print Job"
printController.printInfo = printInfo
let pdfURL = Bundle.main.url(forResource: "sample", withExtension: "pdf")!
printController.printingItem = pdfURL
let printer = UIPrinter(url: printerUrl)
printController.print(to: printer, completionHandler: { [self] printController, completed, error in
if(error != nil){
print("error")
}else if completed{
print("completed")
}else{
print("cancel")
}
})
Does anyone knows if it's a bug in iOS17 or am I missing something?
Starting iOS 16 seeing some crashes related to pdf printing in the crash reporter. It looks like the issue is not so frequent. Also, I'm unable to reproduce the crash. Looks like the app crashes when the print preview dialog is opening. According to crash reports, there are some crashes on different iOS 16 versions: 16.0.0, 16.0.2, and 16.0.3.
Printing code:
let printInfo = UIPrintInfo.printInfo()
printInfo.jobName = "Printing Job Name"
self.printViewController = UIPrintInteractionController.shared
self.printViewController?.printInfo = printInfo
self.printViewController?.printingItem = pdfURL
self.printViewController?.present(from: barButtonItem, animated: true) { (controller, completed, error) in
self.printViewController = nil
}
Stack trace:
compare_key + 4 (CGPDFObject.c:134)
bsearch + 68 (bsearch.c:70)
CGPDFDictionaryGetUnresolvedObject + 68 (CGPDFDictionary.c:153)
CGPDFDictionaryGetObject + 44 (CGPDFDictionary.c:172)
CGPDFDictionaryGetDictionary + 44 (CGPDFDictionary.c:284)
get_pages_dictionary + 68 (pdf-reader.c:410)
pdf_reader_get_number_of_pages + 76 (pdf-reader.c:557)
-[UIPrintPreviewPageFetcher fetchNumberOfItems] + 76 (UIPrintPreviewPageFetcher.m:115)
-[UIPrintPreviewViewController collectionView:numberOfItemsInSection:] + 32 (UIPrintPreviewViewController.m:482)
-[UICollectionViewData _updateItemCounts] + 220 (UICollectionViewData.mm:335)
-[UICollectionViewData isIndexPathValid:validateItemCounts:] + 52 (UICollectionViewData.mm:348)
-[UICollectionViewData validatedGlobalIndexForItemAtIndexPath:] + 36 (UICollectionViewData.mm:778)
-[UICollectionView _cellForItemAtIndexPath:] + 108 (UICollectionView.m:7112)
-[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:collectionViewAnimator:] + 1384 (UICollectionView.m:9357)
-[UICollectionView _updateRowsAtIndexPaths:updateAction:updates:] + 396 (UICollectionView.m:9104)
-[UICollectionView reloadItemsAtIndexPaths:] + 52 (UICollectionView.m:9124)
-[UIPrintPreviewViewController reloadVisibleItems:] + 256 (UIPrintPreviewViewController.m:568)
__63-[UIPrintPreviewViewController updatePdfURL:options:completed:]_block_invoke_2 + 44 (UIPrintPreviewViewController.m:305)
__NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 24 (NSOperation.m:1545)
-[NSBlockOperation main] + 104 (NSOperation.m:1564)
__NSOPERATION_IS_INVOKING_MAIN__ + 16 (NSOperation.m:2189)
-[NSOperation start] + 708 (NSOperation.m:2206)
There is full stack trace I got from the Organizer
Thanks!