# Controlled printing for iOS in FileMaker

**URL:** <https://the.fmsoup.org/t/controlled-printing-for-ios-in-filemaker/4099>\
**Category:** MBS Plugins\
**Tags:** ios, print, printing, sdk\
**Created:** [April 16, 2024, 10:56am UTC](https://the.fmsoup.org/t/controlled-printing-for-ios-in-filemaker/4099 "2024-04-16T10:56:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MonkeybreadSoftware](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/monkeybreadsoftware/32/361_2.png) [@MonkeybreadSoftware](https://the.fmsoup.org/u/MonkeybreadSoftware)\
**Post date:** [April 16, 2024, 10:56am UTC](https://the.fmsoup.org/t/controlled-printing-for-ios-in-filemaker/4099/1 "2024-04-16T10:56:57Z")

</div>

![](https://www.mbsplugins.de/image/iOSPickPrinter.png)

If you use FileMaker iOS SDK, we can provide a few new print commands for iOS in the [MBS FileMaker Plugin](https://www.monkeybreadsoftware.com/filemaker/) in version 14.2. The new [PDFKit.SelectPrinter](https://www.mbsplugins.eu/PDFKitSelectPrinter.shtml) function allows you to pick a printer. And the [PDFKit.Print](https://www.mbsplugins.eu/PDFKitPrint.shtml) function got extended to print PDF documents as well as images. You can configure printing with [PDFKit.SetPrintSetting](https://www.mbsplugins.eu/PDFKitSetPrintSetting.shtml) function.

Let's start with selecting a printer:

```auto
If [Length ( PDFKit Print::PrinterURL ) > 0]
	Set Variable [$r ; Value: MBS( "PDFKit.SetPrintSetting"; "PrinterURL"; PDFKit Print::PrinterURL )]
End If
# show the dialog
Set Variable [$userDidSelect ; Value: MBS( "PDFKit.SelectPrinter" )]
If [MBS("IsError")]
	Show Custom Dialog ["Failed to show printer selecto…" ; $r]
Else If [$userDidSelect]
	# and check what we got
	Set Variable [$printerURL ; Value: MBS( "PDFKit.GetPrintSetting"; "PrinterURL" )]
End If

```

This shows the printer picker dialog on iOS and we can pick a printer. If you had selected a printer before, the plugin would remember it. But if you had one stored in a field in the database, you may pre-select that one. After the user picked something, we store the prints in a variable/field.

To print, we need something to print. That may be a container with an image or PDF document. Or you have a file on disk which could be an image or PDF file again. If you have a PDF document in memory through [PDFKit.NewPDFDocument](https://www.mbsplugins.eu/PDFKitNewPDFDocument.shtml), [PDFKit.OpenContainer](https://www.mbsplugins.eu/PDFKitOpenContainer.shtml), [PDFKit.OpenPath](https://www.mbsplugins.eu/PDFKitOpenPath.shtml) or [PDFKit.OpenURL](https://www.mbsplugins.eu/PDFKitOpenURL.shtml), you can also pass the reference number. This way you could assemble a PDF in memory and print it directly without storing it in a temporary file or a container field.

```auto
# Print
Set Variable [$r ; Value: MBS("PDFKit.Print"; PDFKit Print::PrintItem)]
If [MBS("IsError")]
	Set Field [PDFKit Print::Result PDFKit Print::Result ; $r $r]
	Show Custom Dialog ["Failed to open file" ; $r]
Else
	Set Field [PDFKit Print::Result PDFKit Print::Result ; $r $r]
End If

```

The printing can happen with or without dialog. If you skip the dialog using [PDFKit.SetPrintSetting](https://www.mbsplugins.eu/PDFKitSetPrintSetting.shtml) and the ShowsPrintPanel option being zero, you need to tell the plugin where to print to. For that, please pass the printer URL to the [PDFKit.SetPrintSetting](https://www.mbsplugins.eu/PDFKitSetPrintSetting.shtml)function for PrinterURL option.

The following script prints something from the container directly to the printer named LaserDrucker:

```auto
Set Variable [$r ; Value: MBS( "PDFKit.SetPrintSetting"; "ShowsPrintPanel"; 0 )]
Set Variable [$r ; Value: MBS( "PDFKit.SetPrintSetting"; "PrinterURL"; "ipp://Laserdrucker.local.:631/ipp/print" )]
Set Variable [$r ; Value: MBS( "PDFKit.SetPrintSetting"; "OutputType"; "Grayscale" )]
Set Variable [$r ; Value: MBS( "PDFKit.SetPrintSetting"; "JobTitle"; "Test" )]
Set Variable [$r ; Value: MBS( "PDFKit.SetPrintSetting"; "DuplexMode"; "LongEdge" )]
# show the dialog
Set Variable [$r ; Value: MBS("PDFKit.Print"; PDFKit Print::FileContainer)]
If [MBS("IsError")]
	Set Field [PDFKit Print::Result PDFKit Print::Result ; $r $r]
	Show Custom Dialog ["Failed to open file" ; $r]
Else
	Set Field [PDFKit Print::Result PDFKit Print::Result ; $r $r]
End If

```

As you see the printer URL includes the ipp prefix, the port number. To learn the printer URL, you can use the picker dialog above.

![](https://www.mbsplugins.de/image/iOSPrint1.png) ![](https://www.mbsplugins.de/image/iOSPrint2.png)

Please try the 14.2 plugin and see if this works for you. Please don't hesitate to contact us with your questions.
