I'm writing an iOS application which needs to print using a Boca thermal printer. They use a proprietary language (FGL) to layout contents with commands in form of ASCII strings. I already enabled AirPrint for the Boca printer by using the AirPrint activator tool which can be downloaded for free.

My problem is that using UIPrintInteractionController, all I can do is send either already formatted text (the BOCA will then not recognize the FGL commands, printing them as if they were normal text) or NSData which needs to have a PDF header (which my data doesn't have, so I can't print this way).

Is there any way to bypass this framework and send raw ASCII data to the printer? Should I be using NSStreams and manage the print job in a low level way?

In that case, is there any way to obtain the printer's address on the network so I can establish a socket connection to it?

有帮助吗?

解决方案

It sounds as though you need either a 3rd Party library or write one yourself

But I'm not sure about the internals of networked printers function, but I were you I would ask myself:

  • Does the printer broadcast it's IP Address to the network?
  • If not what functionality does it supply to make it self discoverable to other devices?
  • Does the printer respond to a specific broadcast message from the device wanting to connect to it?
  • Does it solely rely on UDP or TCP packets?

If you can get in contact with their customer service you may be able to get hold of this information if it isn't documented on the net.

Sorry i can't give you a direct answer, but hopefully these questions help you find the answer

其他提示

Most printers have some sort of self-test function that will print some information about the printer including it's IP address. See if it mentions it in the manual online. It is usually something like holding down the feed button while turning it on. Once you have the IP address it should be fairly simple to open a connection to it and send it data.

Chances are the OP has pulled this off, but in the spirit of StackOverflow on this niche question......

If you know the IP address of the printer (you can find this out via a test print using one of the buttons on your printer), you can send FGL commands via a TCP socket on port 9100. I've used FastSocket for this on a BOCA Thermal Ticket Printer connected via ethernet.

Assuming your text file containing the FGL commands is in Tickets/test.txt in your app bundle, the code (in Swift) to achieve this is:

let client:FastSocket = FastSocket(host: PRINTER_IP_ADDRESS, andPort: "9100")
client.connect()

let ticketPath:String! = NSBundle.mainBundle().pathForResource("test", ofType: "txt", inDirectory: "Tickets")
let count:Int = client.sendFile(ticketPath)

// Do some error checking here

client.close()

The equivalent Objective-C code should be easy enough to work out.

As FastSocket does the above commands synchronously, make sure you run the above code in a background thread to prevent your UI from freezing.

You can try external accesory framework to send data to your printer. It is used to connect external peripheral devices. Probably this is what you are looking for.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top