Print Report rotated by 90 degrees and/or using smaller Font

I have some Reports that are fairly wide (lots of columns), and I only have a Ticket Printer (no LTR or A4 printer), so I was wondering about possibly rotating the Print by 90 degrees so that it would be able to fit all columns in the Print, assuming it doesn’t have too many rows.

##Rotation

I found this reference to an ESC/POS command for turning 90 degree rotation on and off …

<XCT> commands would then be:

<XCT>27,86,0,48 -- turn rotation OFF
<XCT>27,86,1,48 -- rotate with 1-dot character spacing
<XCT>27,86,2,50 -- rotate with 1.5-dot character spacing

##Font Set

Another idea would be to somehow set the Font Set and/or Size to make the characters smaller. It seems many printers have at least FontA and FontB

XCT commands in this case to select one of the 2 Fonts would be:

<XCT>27,33,0 -- FontA (larger, default)
<XCT>27,33,1 -- FontB (smaller)

Another command that appears to do the same thing:

XCT commands in this case to select one of the 2 Fonts would be:

<XCT>27,77,0,48 -- FontA (larger, default)
<XCT>27,77,1,49 -- FontB (smaller)

##Initialize (Reset) Command

Just for reference, the Reset Command ESC @ is:

<XCT>27,64

##Executing ESC/POS commands when printing a Report

In any case, the question is:

How do we execute an <XCT> command when printing a Report?

Can the command go in the Report itself? @emre, do you think you might be able to add that feature somehow?

Could we Execute Print Job using a Template containing the XCT code, then subsequently fire the Print Report Action? I guess “NO” since we need a Ticket to use Execute Print Job action?

Any ideas?

It will execute XCT commands for single line templates without the need of ticket.

1 Like

What about multiple line Templates that only contains consecutive XCT commands?

<XCT>27,86,2,50
<XCT>27,77,1,49


Can we do something like this to read {SETTING:X} using Ternary Operator to execute different commands depending on the setting Value? Will it work?

<XCT>27,86,[='{SETTING:RotatePrint90}'=='OFF' ? '0,48' : '2,50']

<XCT>27,77,[='{SETTING:PrinterFont}'=='B' ? '1,49' : '0,48']

Oooh… this would be awesome if it worked… will it work @emre? :stuck_out_tongue_winking_eye:

<XCT>27,86,[='$rotate'=='OFF' ? '0,48' : '2,50']
<XCT>27,77,[='$font'=='B' ? '1,49' : '0,48']



Is that parameters an existing function??

Yes, it was introduced in .61 Beta and is in the .62 release. I have not tried it yet, but assume that is syntax based on the description, though not sure if it supports multiple comma-separated parameters:

1 Like

… double post …
… double post …

Real-world example where I would use this:

I tried it and received this error:

-----------------------------

[Exception Info 1]

Top-level Exception
Type:        System.FormatException
Message:     Input string was not in a correct format.
Source:      mscorlib
Stack Trace: at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Convert.ToInt32(String value)
   at Samba.Services.Implementations.PrinterModule.Tools.LinePrinter.<>c.<ExecCommand>b__37_0(String x) in C:\Users\emree\Documents\Github\SambaPOSPro\Samba.Services\Implementations\PrinterModule\Tools\LinePrinter.cs:line 404
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
   at Samba.Services.Implementations.PrinterModule.Tools.LinePrinter.ExecCommand(String command) in C:\Users\emree\Documents\Github\SambaPOSPro\Samba.Services\Implementations\PrinterModule\Tools\LinePrinter.cs:line 404
   at Samba.Services.Implementations.PrinterModule.PrintJobs.SlipPrinterJob.SendToPrinter(LinePrinter linePrinter, ILineFormatter line, Printer printer) in C:\Users\emree\Documents\Github\SambaPOSPro\Samba.Services\Implementations\PrinterModule\PrintJobs\SlipPrinterJob.cs:line 76
   at Samba.Services.Implementations.PrinterModule.PrintJobs.SlipPrinterJob.DoPrint(AppState appState, String[] lines) in C:\Users\emree\Documents\Github\SambaPOSPro\Samba.Services\Implementations\PrinterModule\PrintJobs\SlipPrinterJob.cs:line 23
   at Samba.Services.Implementations.PrinterModule.PrintJobs.PrintJobCache.Print(AppState appState) in C:\Users\emree\Documents\Github\SambaPOSPro\Samba.Services\Implementations\PrinterModule\PrintJobs\PrintJobFactory.cs:line 77
   at Samba.Services.Implementations.PrinterModule.PrintJobExecutor.InternalExecutePrintJob(AppState appState, PrintJob printJob, Int32 copies, IDictionary`2 parameters) in C:\Users\emree\Documents\Github\SambaPOSPro\Samba.Services\Implementations\PrinterModule\PrintJobExecutor.cs:line 98
   at Samba.Services.Implementations.PrinterModule.PrintJobExecutor.<>c__DisplayClass20_0.<Execute>b__0() in C:\Users\emree\Documents\Github\SambaPOSPro\Samba.Services\Implementations\PrinterModule\PrintJobExecutor.cs:line 83
   at Samba.Services.Implementations.PrinterModule.AsyncPrintTask.InternalExec(Action action, ILogService logService) in C:\Users\emree\Documents\Github\SambaPOSPro\Samba.Services\Implementations\PrinterModule\AsyncPrintTask.cs:line 32

-----------------------------

I think there is something just a little “off” in the Template that causes this - I will try to figure it out …

<XCT>27,86,[='$rotate'=='ON' ? '2,50' : '0,48']
<XCT>27,77,[='$font'=='B' ? '1,49' : '0,48']

Tried without the quotes and same error:

<XCT>27,86,[=$rotate=='ON' ? '2,50' : '0,48']
<XCT>27,77,[=$font=='B' ? '1,49' : '0,48']

I have a feeling the ternary expression is not executing, probably because it is not supported.

I removed the ternary expression and just set the Template to execute the command for FontB:

<XCT>27,77,1,49

So a Print Job for the above executes, then the Report is Printed, then a Print Job for FontA executes after that.

However, the font size does not change… hmmm… I wonder why?

EDIT: set the “Print Ticket” parameter to True in Execute Print Job Action and…

IT WORKS!

Quite a difference - FontA at 42 chars on Left and FontB at 56 chars on Right …

1 Like

@QMcKay did you tried directly adding XCT commands inside report template? I don’t have a printer so I can’t test it atm but as far as I can track from the source code it keeps XCT commands after the report header. Solving it in report template might be a better idea as it will also work when it gets printed through report viewer.

OK when I think about it your idea might offer better flexibility. Can you pm me a backup so I can better track where it fails.

Hmm I was thinking you’re printing reports with Execute Print Job action. You’re using it to send printer commands. Maybe we can add command execution feature for Print Custom Report action.

1 Like

I never tried XCT in Report Template. I just assumed it would not work. It would be great if Reports supported that. I should have tried it.

Yes, I am using Exec Print Job action to simply fire XCT commands before using Print Report action, and again after to fire XCT to set the Printer back to normal.

To simplify things, if I could use Ternary Expression to derive the command, I could use a single Template/Job. Without ternary expression, I need 4 Templates/Jobs.

I assume that when the parser sees <XCT> then it does not even bother trying to evaluate expressions on the line first. Instead it just takes what follows after that and tries to execute it. Of course the expression is not purely numeric until it is evaluated. I tried different combinations of things for the expression, but always get the same error about it not being able to convert String to Int

First attempt:

<XCT>27,77,[='$font'=='B' ? '1,49' : '0,48']

Another attempt:

<XCT>27,86,[='$rotate'=='ON' ? '2' : '0'],[='$rotate'=='ON' ? '50' : '48']
<XCT>27,77,[='$font'=='B' ? '1' : '0'],[='$font'=='B' ? '49' : '48']

That said, I might be wrong. The Preview appears to evaluate the expression:

I learned something else. We might not need to set “Print Ticket” to True.

However, it is important to use hiPriority False on the Reset Job otherwise the Font is not changed for the Report …

@QMcKay I can add parameter feature, executing expressions etc… to print custom report action. When multiple actions used it may not work as SambaPOS probably reset / initialize printer settings when a new printing starts. I wish I have a printer so I could test that :slight_smile:

Hmm… check this out - this is printed to TXT… notice doubled up single quotes where the $KEY would be:

27,86,[=''OFF''=='ON' ? '2,50' : '0,48']
27,77,[=''A''=='B' ? '1,49' : '0,48']

I am at home today, so cannot test with actual printer unfortunately. Maybe I will go down to my shop to try some more testing today.

Changing Template to this:

<XCT>27,86,[=$rotate=='ON' ? '2,50' : '0,48']
<XCT>27,77,[=$font=='B' ? '1,49' : '0,48']

Preview doe not look good:

But TXT print looks good:

27,86,[='OFF'=='ON' ? '2,50' : '0,48']
27,77,[='A'=='B' ? '1,49' : '0,48']

And with different $KEY parameters …

27,86,[='ON'=='ON' ? '2,50' : '0,48']
27,77,[='B'=='B' ? '1,49' : '0,48']

I think I need to go try this with physical Printer now :wink:

1 Like

I think that would be the best!

So print custom report already have parameters feature but works differently. Instead of $key=$value list it accepts a comma separated parameter list and replaces $1, $2 etc…

So you can try adding commands into the custom report template. They’ll appear weird on preview but I think it will print nice. You can better send it to Notepad instead of print preview to test it.

If it works fine we can add an additional parameter to print custom report action to add these commands on top of custom report template so you can use single template for both displaying and printing.

1 Like