Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Yes, really. Print it with a hardware printer 🖨 to create a hard copy.

Send the necessary commands/data to your printer such that the following text is printed on a piece of paper:

Hello, World!

You may use any local- or network-connected printer that is available to you.

If your printer allows, you should use 8pt or greater text in black ink on white paper.

The text should appear on its own line. It may be left or right positioned as you wish.

Digital photographic/video/GIF evidence of submissions will be helpful.

If your hardware cannot do paper, but allows other exotic hardcopy production such as 3D printing, CNC machining, or printing at the atomic level, then I will happy to accept such interesting submissions.


To clarify, the question asks "Send the necessary commands/data to your printer". This means that there should be no further user input. Opening a print dialog is not sufficient. Existing answers that do this as of 10:48am PST 31st Dec 2016 will be grandfathered (but not upvoted by me).

share|improve this question
22  
Please supply address to which we can send submissions for verification. – steenbergh yesterday
    
@steenbergh Yep - good point - Digital photographic/video/GIF evidence of submissions should be good enough. – Digital Trauma yesterday
1  
It's worth noting that many older printers use custom command sets. Most of these print ASCII characters literally, so if you have access to one of the printers in question (or can just claim that you do), sending Hello, World! to the printer port should be enough. – ais523 yesterday
    
I could swear that I tried print("Hello, World!") in the Firefox console once and it opened the print dialogue (useless because I wasn't connected to a printer in any way), but now it just returns the string... – ETHproductions 21 hours ago
    
are xditview, distiller, cups-pdf and other printer simulators considered cheating? – Jasen 18 hours ago

15 Answers 15

PowerShell, 18 bytes

'Hello, World!'|lp

Try it online!

enter image description here

share|improve this answer
6  
Not sure the point of the TIO link. +1 anyway. – Digital Trauma 22 hours ago
7  
+1 for try it online – Pavel 22 hours ago
1  
@DigitalTrauma I thought it was funny; and it generates the post for me. You can also look at the debug output just to see that it's trying (and failing) to spool the job. :-p – briantist 22 hours ago
13  
@DigitalTrauma If you put your address in the input field, TIO will mail you the result. – Dennis 22 hours ago
14  
+1 for wasting Dennis' sheets of paper – Luis Mendo 22 hours ago

Bash, 21 19 bytes

lp<<<Hello,\ World!

actual printout

And there it is.

2 bytes saved thanks to Dennis!

share|improve this answer
    
+1 Valid as a script. Works fine on my Mac. If you want to run it directly at the command-line you'll need to change the double-quotes to single-quotes. – Digital Trauma yesterday

Python 2.7, 421 bytes

import zlib,base64,os;os.system("s=$'%s';lp<<<\"$s\""%zlib.decompress(base64.decodestring("eNqVkk1qxDAMha/yupNgwNfoDboReDPdhQRmrcNXP3bixA3tGEMesj/r5wXoq+YysUemI0BWlYgV\npTyAEDKEQSDucxLxJaj6gUVKE8BFsH2TIOM5iMyrcTIL3YnMqCH4X0TLONTwF3H04Z0XuRPeR3Wi\nxDOi1EZY7gUTWFa8s+z5kTgcnK3sBtbZQRtCt5LPDlrliKouDh5DYz07KB6COuETUL/YRthGxHqZ\nbjyWBAU8EFk6z350Yt97Dol65hxUow9i3zr8YGxFS61nB4szPqvDnS7CU/nFwYLIYczn97JsD3xt\nr+X5wT/ARNN3\n")))

Seems a bit too long? Perhaps it's a bit overcomplicated.... :P

A lot of hello world

In all seriousness, here is a shorter one:

import os;os.system("lp<<<'Hello, World!'")

Not very interesting, though.

share
locked by Dennis 6 hours ago

This post has been locked while disputes about its content are being resolved. For more info visit meta.

2  
+1 for the nice "font" :) – Walfrat 12 hours ago
    

QBIC, 11 bytes

`LPRINT `_h

Almost forgot I built a 'Hello, World!' command into QBIC...

`          Starts a code literal. This used to be "$", finally changed it.
 LPRINT `  Feeds everything from ` to the next ` directly to QBasic. 
           In this case, "LPRINT" and a space
_h         Yields "Hello, World!"

Tested and found working identical to my QBasic answer: enter image description here

share|improve this answer
    
um.. so what's that link? Is it a language invented by you? – eis yesterday
    
@eis Yes, I made QBIC. The link is a Google Drive folder with all the code in it - I suck at GitHub... It's an interpreter atop of QBasic (QBIC stands for Quick Basic's Interpreter for Codegolf) and it runs in DosBox. Check out the Showcase-thread for some examples (or just open my profile's answers-page, 75% is in QBIC). WIP, so syntax and tokens occasionally get shifted. – steenbergh yesterday

HTML + Javascript, 37 bytes

Hello, World!<script>print()</script>

Tested in Safari:

enter image description here

share|improve this answer
4  
This appears just to open the print dialog box and not actually send the job to the printer without further manual intervention – Digital Trauma 18 hours ago
    
Minor nitpick, the W in world should be capitalized. – Pavel 15 hours ago
2  
@DigitalTrauma JS cannot do that – Mr. Alien 12 hours ago
    
Also, you can shave 9 bytes off by omitting </script>. – Erik the Outgolfer 8 hours ago
    
Are you sure, @EriktheOutgolfer? Firefox and Chrome evaluates the script code only when the closing tag is met. – manatwork 6 hours ago

Batch, 22 bytes

echo Hello, World!>prn

This redirects the output of the echo command to the device file PRN, meaning that it's sent directly to the default printer (usually LPT1).

I neither have a DOS machine nor a printer, so I'm afraid I can't test this right now, but I'm fairly certain I've done this back in the day. It doesn't work on Windows XP or later.

share|improve this answer

QBasic, 21 bytes

LPRINT"Hello, World!"

LPRINT sends text directly to the printer. Unfortunately untested, DosBox doesn't natively support NET USE, so I can't reroute LPT1: to NovaPDF.

The problems I have...

UPDATE: Tested it in QB64. Resulting PDF opened in Microsoft Edge. Looks like this: enter image description here

share|improve this answer

MATLAB, 40 bytes

Printing text is not something you'd normally do in Matlab, but it can be done.

text(0,0,'Hello, World!');axis off;print

text adds text description to data points in a figure. If a figure is not yet open, it will be created. The first two arguments are the coordinates of the bottom left corner of a figure.

axis off is used to get rid of the frame and axes, so that the text appears on its own line.

print prints the current figure to the default printer if no input arguments are given.

I printed this (successfully according to the dialog box) on my default printer at the office. I can retrieve it there and prove it but you'll have to wait two weeks. After changing the default to a pdf-printer, this is the output:

enter image description here

share|improve this answer

ZX Spectrum BASIC, 16 bytes

LPRINT "Hello, World!"

LPRINT is a 1-byte keyword in ZX Spectrum BASIC, having codepoint 224.

share|improve this answer
1  
can you show a photo of the hardcopy. – Jasen 18 hours ago
2  
@Jasen In theory I still have the kit around, but it would be a bit of a palaver to dig it out and hook it up to an old enough TV. Sorry about that. – Neil 13 hours ago
    
you could probably type that command "blind". – Jasen 13 hours ago

hello + lp, 9 bytes

hello|lp

hello is from the Debian package hello

share|improve this answer
5  
hello prints a lowercase w, as is the custom on most programming sites. (I'm not quite sure how the uppercase W became standard on PPCG.) – ais523 16 hours ago
5  
@ais523 I think uppercase W is standard here precisely to avoid built ins like this. – Pavel 15 hours ago
1  
If the capitalization is wrong, I'm afraid this is invalid. – Dennis 6 hours ago

GFA-Basic, 22 bytes

Only tested on an Atari ST emulator with the parallel port redirected to a file. It should work on the Windows version of GFA-Basic (which is free), but this is untested.

LPRINT "Hello, World!"

Note: This turns out to be identical to the QBasic syntax.

share|improve this answer

HTML (33)

Hello, World!<svg onload=print()>

(Prompts a print window in the browser, doesn't print directly)

share|improve this answer
    
Is there a reason the tag has to be <svg> specifically, or would any tag work? (Many tags have shorter names.) – ais523 14 hours ago
2  
afaik, only svg, img (with a valid src), iframe and body have an onload event triggered when the page is loaded. img without src triggers an onerror event. all in all, the shortest we've found is svg onload=... – xem 10 hours ago
    
The challenge asks for upper case W (not that it changes your byte count). – Martin Ender 9 hours ago
    
fixed, ty...... – xem 8 hours ago

Mathematica, 29 bytes

NotebookPrint@"Hello, World!"

enter image description here

share|improve this answer

JavaScript, 38 bytes

document.write('Hello, World!');print()

Thanks manatwork for shaving off 14 bytes!

share|improve this answer
2  
No need to explicitly specify window: document.write('Hello, World!');print(). Or even shorter: print(document.write('Hello, World!')). – manatwork 11 hours ago
1  
with ES6 you can even do: document.write`Hello, world!` (more info here: xem.github.io/articles/#webspeech) – xem 10 hours ago

Racket 35 bytes

(system("echo 'Hello World!'\|lp"))
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.