I'm trying to write a script in Powershell to automatically print the contents of a text file. However, my tab characters are removed when printing making the final output hard to read.
I've provided an MWE to illustrate the issue.
Contents of MWE.txt (encoded in ANSI; a →
represents a tab character):
FOO→1,23→4,56
My powershell script:
$fname = "C:\MWE.txt"
Get-Content $fname | Out-Printer -name "Microsoft XPS Document Writer"
I'm using the XPS writer to avoid wasting paper, but in the end this will be changed to a real printer. The output on real paper is identical, I've ruled that out too.
Problem is that the in the print output, the tab characters are just erased, yielding:
FOO1,234,56
However, If I instead change the Out-Printer
to Out-String
, the console displays the file contents correctly. What on earth am I doing wrong? The file displays correctly with tabs in both notepad and notepad++, and I've tried UTF-8 encoding as well.
Edit 2018-07-12 10:20
Content structure of the file I'm trying to print, which is automatically generated by a system and put on a web server for which I have no access. For clarity, I've used →
to denote the tab character and ·
to denote a space:
MWE·-·TestFile·:·
0)→Time
1)→Temperature·1
2)→Humidity
3)→Pressure·A-B
4)→Pressure·A-C
5)→Pressure·D-C
0)···················→1)→2)→3)→4)→5)→
2018-07-04 12:00:00→22,03→5,34→18,93→23,10→10,10
2018-07-04 13:00:00→21,99→5,22→18,75→23,56→10,00
2018-07-04 14:00:00→21,99→5,17→18,55→23,54→10,15
2018-07-04 15:00:00→22,03→5,25→18,73→23,41→8,33