0

When I print a text file (i.e. with the .txt extension) via JavaScript with the print() function, the final result is a PDF file when opening the print popup. But I need the resulting file to be the TXT file and send it to print.

Is there any way to print the original txt file by the browser?

informatik01
  • 16,038
  • 10
  • 74
  • 104
  • https://stackoverflow.com/questions/3665115/how-to-create-a-file-in-memory-for-user-to-download-but-not-through-server – Quentin Jan 24 '22 at 19:45
  • Printers cannot print plaintext files. Files containing text must first undergo a rasterization process (in which the text data is set into a specific font, amongst other things) before they can be physically printed. Sometimes this is handled by the printer driver, sometimes it’s handled by an earlier software step, and sometimes it’s a combination of steps. In this case, the browser is performing an intermediate format conversion for you in order to prepare the document for print. – jsejcksn Jan 24 '22 at 19:56

1 Answers1

0

Certainly, but you need the correct printer driver

enter image description here

enter image description here

OK it may in very very limited cases be possible, but I suspect not the way you may require, A plain text file can be easily read and displayed by most browsers it is just like xml or html simply text after all.

The browser will require some means to copy the plain-text for saving and that in theory can be saved to a file or print device which in turn can be sent to a text printer, however they are very rare since most modern printers are graphical, thus require a printer driver to convert text into vectors or PDF or postscript text or any other printers own language.

NOTE: The browser cannot/should not execute code such as

Notepad /print MyTxt.txt "Generic / Text Only"

since that would breach cross origin security.

However it is simple to do that without a browser involved using runtime command line java-script in a console / batch file or gui like Iexplorer.

K J
  • 8,045
  • 3
  • 14
  • 36