The Good: I'm building a FlowDocument in my app and sending it to a Star Micronics TSP100 thermal receipt printer, and I can print bar codes as well by sending ESC codes to the printer directly.
The Bad: It's automatically cutting the paper after the FlowDocument, before the bar codes have had a chance to print.
The Question: Is there a better way to print the FlowDocument so it doesn't tell the printer it's done printing? Or to have the some part of that trigger an event handler so I can squeeze my bar code commands in before it tells the printer it's done?
Here's where I am now:
The flow document is called, creatively enough, "doc".
FlowDocument doc
Then of course, I add a whole bunch of stuff to the FlowDocument. Then I grab the printer and print the FlowDocument:
string printerName = "Star TSP100 Cutter (TSP143)";
LocalPrintServer local = new LocalPrintServer();
PrintQueue rcptpq = local.GetPrintQueue(printerName);
Xps.XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(rcptpq);
IDocumentPaginatorSource dps = doc;
If that all worked without errors (error handling not copied--this is what I'm stepping through), I write out the receipt:
// print MOST of the receipt
xpsdw.Write(dps.DocumentPaginator);
The printer cuts here automatically. I don't want it to. I want it to cut after the bar code.
// print the bar code
RawPrinterHelper.SendStringToPrinter(printerName,"\x1b\x62\x2\x2\x30" + "MyUPC123\n");
// Cut the paper
RawPrinterHelper.SendStringToPrinter(printerName,"\x1b\x64\x02");
(RawPrinterHelper is from the Star Micronics SDK sample, and what it does is pretty self explanatory, at least with my comments to describe the specific codes being used.)
I've tried some settings in TSP100's Configuration tool regarding "Page end detection", but so far all I've succeeded in doing is turning off all cutting, or turning off the explicit "cut the paper" command at the end. I can't just turn off the first cut.