October 10, 2006

Printable Mazes

Here is a free PDF maze generator that can create mazes of various sizes and complexity, including pretty diabolical mazes that include 3-d crossings...

Maze Options

This form drives some of the options on the maze generator:

width in points
height in points
cell size
curvy straight
crossings not

Programming in PostScript

When I was a student at Cornell I was a postscript fanatic. PostScript is a complete programming language that happens to be used by many printers, and I found it amusing to write postscript files that rendered differently every time you printed them. One of my favorite creations was a small postscript file that would generate a random labyrinth each time it was printed; it won the Obfuscated PostScript Contest in 1993. Unfortunately, postscript printers are not that common today - instead, everybody uses PDF to prepare files for printing. Although PDF is related to postscript, PDF is not a complete programming language, so for a while I have wanted to write a maze generator for the web that would just generate PDF mazes using a cgi script in some other language.

The Source

The result is here: a little cgi/commandline program written in about 150 lines of python which takes advantage of the ReportLab pdf generation library to produce its output.

If you improve the program, please let me know. Enjoy!

Posted by David at October 10, 2006 11:11 AM

Very cool. My 5-year old is on a maze kick. He'll love these. Thanks!

Posted by: Robert W. Anderson at October 12, 2006 11:24 AM

Roger mentioned over email, "If I make a maze 60x60 I get smoke :(".

Basically that's because the maze code puts a 36-point margin around the edge of the paper by default, and throws an exception when a maze ends up being all-margin. Since I figure this blog is read by fellow nerds (like Roger), I didn't bother formatting error messages in my 150-line CGI script: you get to see the stack trace raw.

So how to make really small mazes? You can add "&m=0" to the request URL to make the margin zero points if you like.

Posted by: David at October 17, 2006 01:57 PM

this is totally awesome

you should find a way to make a maze with the center as your goal

Posted by: jesse at January 16, 2007 05:55 AM

Cool - you should include a little attribution URL in your output so I can find it again after printing out a bunch of mazes for the kids (and give yourself a little credit).

Posted by: Patrick Surry at April 23, 2007 01:31 PM

The "make my maze" bwtton generates an error now. Used to work for me.

Posted by: Tom at October 17, 2007 12:56 AM


Posted by: David at October 30, 2007 05:05 AM

Thanks for your program,too easy! I was anticipating HOURS of sitting in front of this computer!

Posted by: Ning at March 10, 2008 07:56 PM

I am curious about your mazes.
I was searching to learn how to make a maze generator myself. I ran across your site.
I have Bible students that I am sure, would love to do these! Maybe I could add a beginning picture and end picture, if allowed.
Another time I will come back and read more. It's late. I would like to put a couple or so of these on my family site, but need to check out your copyright rules, before doing any of these things. Thank you, Carolyn

Posted by: Carolyn at September 12, 2008 01:46 AM

Thanks, David, for this wonderful maze maker. I enjoy easy-to-use process programs. I am making mazes for church kids.

Posted by: Gayle at October 28, 2008 06:13 PM

Ahh I love mazes and so does my son, thanks for this!

Tip: Read this page http://www.inkguides.com/postscript-programming.asp if you are interested in creating your own postscript programs.

Posted by: Stuart at January 2, 2009 08:26 AM

My 5 yr old son loves these mazes, and I often print out a few on my lunch hour for him. Now everyday as I say goodbye going to work, he says "Don't forget the mazes", and rattles off the types & sizes he wants that day. Thanks much!

Posted by: Ken at April 20, 2009 03:46 PM

The make my maze button does not work now. Internal server error.

Posted by: Jenny at October 29, 2009 12:11 AM

Sorry about that - it was broken by a pair.com upgrade.

It's fixed now!

Feel free to email me at the address on the home page if there's a problem.

Posted by: David at October 30, 2009 08:07 PM

These are wonderful and I love to visit the site and generate a maze or two. I am trying them out for my son who is five.
thanks for sharing

Posted by: Diane at December 16, 2010 04:40 PM

Thank you for sharing the source code. I really like the mazes. Can you please post the rewrite rules and .php that allow the pl script to be displayed as a .pdf? I am missing that magic to be able to generate mazes on my web server(non-public).

Posted by: Mitchell at May 3, 2011 03:12 PM

Thank you again. I just wanted to let you know that i got your cgi working. The issue that i was having is getting cgi working with apache on windows. I added three lines to the httpd.conf file. I added a directory section for the directory that i placed the cgi into with these two commands "Options +ExecCGI" and "AddHandler cgi-script .py". Then i added "ScriptInterpreterSource registry" and "PassEnv PYTHONPATH" and "SetEnv PYTHONUNBUFFERED 1". The information was from http://www.imladris.com/Scripts/PythonForWindows.html.
I would still like to be able to point to a "pdf" file instead of a .py file, however i now have everything working.
Thank you.

Posted by: Mitchell at May 4, 2011 08:54 AM

Thank you very much. I was able to finally get everything working as it appears to be working on your site. The last piece that i was missing was the rewrite rules. I used these:
"RewriteEngine on
RewriteRule ^(.*)\.pdf$ $1.py [T=application/x-httpd-cgi]" inside of a directory section where the python script is stored.

Posted by: Mitchell at May 4, 2011 02:53 PM

Hello, all I can get is blank white PDF file.
I have windows python, and reportlab installed.
Doing this: pymaze.py -w500 -h500 > test.pdf
but I only get square white pdf page :(
Thanks for help.

Posted by: Jan Daniel at June 9, 2011 05:28 AM

I added a '-p' option for specifying the page size as a string. Sizes defined in reportlab.lib.pagesizes (e.g. a4 and letter) are supported.

You don't mention the license under which you're publishing your code. Is it ok to stick my fork on GitHub?


Posted by: Antti Kaihola at October 13, 2011 03:49 AM

thanks! I'm making an keep-the-little-kids-quiet wedding program for a friend of mine, and your mazes are lovely - I'm going to put a maze or two in with a link for parents to be able to make more...

Posted by: kelly at May 11, 2013 09:37 PM

i want it plz how can i have it ?

Posted by: keem at September 30, 2013 03:53 PM

Bummer! We've been using and enjoying this for ages but it seems to be broken now.

Thanks for all the fun David!


Posted by: Dean at May 8, 2014 10:47 PM


Your site at davidbau.com no longer will create a maze. Curses!

i have enjoyed it for a long, long time. I have often given your mazes away as gifts to friends to complete.

Can it be fixed?


Posted by: Bob at May 12, 2014 08:32 PM

Sorry about the breakage!

It works again now!

Posted by: David at May 12, 2014 09:43 PM


I finally returned to check if you had time to fix mazestoprint.

Thank you, I look forward to many more mazes to share with others.


Posted by: Bob at May 16, 2014 06:15 PM


Make that: printable_mazes.html

Your program is by far the best!


Posted by: David at May 16, 2014 06:20 PM

Hello David,

I've been looking for a good maze generator which I need for a design project and your is just perfect, because I am able to easily import the pdf-files into design software like illustrator, so I can manipulate the vectors of the maze. Just perfect for my workflow, thank you very much!

Now I would like to use your code on my private server for bigger output files. In fact I want to use it inside of XAMPP.
Could you please tell me how to set up the maze generation environment right?

I've never worked with cgi scripts before, so I don't know where to place it, so it can be called from the form-elements to write the PDF.


Posted by: Alex at August 8, 2014 11:01 PM


I downloaded your Obfuscated PostScript Contest code(Dynamically Generated maze). It runs great on an older mac(10.4.11) and preview. I'd like to try and get it to work with a CNC router or laser cutter. I think laser cutting by adding a fill command would be straight forward and fairly easy.

Is there an unobfuscated version available with comments?

Is there a parameter that sets the length of the dead end paths?


Posted by: John at October 24, 2016 02:25 PM

Hallo David.
Culd I use your script from http://davidbau.com/archives/2006/10/10/printable_mazes.html to generate maze for commercial purpose? If I manage to sell some i will tel you way how I monetize it and you will be able to monetize it allso. Can I use it for free to commercial purpose?

Jakub Miłek

Posted by: Jakub at September 13, 2017 12:36 PM

Fantastic Maze generator, David!
I am a Dutch teacher and make worksheet to use in my classroom. Does your generator also genetate the solution somewhere?

Posted by: Jack at December 2, 2018 04:33 PM

Hallo David.

Could I create mazes for commercial purpose? Can I use it for free to commercial purpose?

Posted by: Steve at October 5, 2019 08:28 AM


Can I use this mazes for commercial purpose? How much costs it?

Can your application show the solutions?

Posted by: NÚstor MaciÓ at December 12, 2019 04:49 AM

Fantastic Maze generator, David!
Can I use this mazes for commercial purpose? How much costs it? thanks

Posted by: Abdelali BENNAR at May 11, 2020 05:30 PM

Hi David,
What about using your maze generator for commercial use, in a book I make for KDP sales? I really want to be 100% careful about that. Thanks. Michael Rush

Posted by: Michael Rush at October 5, 2020 07:53 PM

Hi David,
I have recently discovered your overlapping 3d maze generator and I am very intrigued. I create activity books and have used the typical flat maze generator software as part of the content. I was wondering if you have any terms for allowing use of mazes generated by your unique program in mixed content books for sale. Thank you very much! Tom

Posted by: Tom Shaw at October 21, 2020 10:12 PM

Hello, David. My kids love your mazes! Thank you.
I am as well designer and illustrator, and working on books for kids. I'd like to include some mazes there too. Are there any terms for commercial use of your mazes? Thank you. Kind Regards, Helena

Posted by: Helena at January 5, 2021 12:34 AM

I would just like to ask the same question a number of others have asked - are there any restrictions to using the mazes on a commercial basis.

Posted by: Darrel Hype at January 5, 2021 05:51 PM

what is the commercial use criteria?

Posted by: Dion Hodge at February 19, 2021 05:25 PM

has anyone ever told you you're a-maze-ing? cos that's what you are

Posted by: at May 4, 2021 01:55 PM

Do you allow for Commercial use?

Posted by: shannan at June 14, 2021 09:36 AM

Guys, does anyone try it in amazon KDP books, are there any risks?

Posted by: Ayoub at August 9, 2021 02:19 PM

Beautiful. But..........answer key???

Posted by: Shakur at September 25, 2021 01:40 PM

Yes, amazing pieces but there is a way to print the solution?

Posted by: Silvian at November 1, 2021 02:07 PM

This generator is amazing! I see that several people asked about using the mazes created by your generator for KDP books but I didn't see a response or answer to this question. Is commercial use allowed?


Posted by: Debra at December 27, 2021 06:03 PM

Again, are these allowed for commercial distribution? There appears to be no reply to this question.

Posted by: Angela at January 13, 2022 11:49 AM

These are great! Is it possible to generate the solutions? Thank you.

Posted by: Everlie at June 21, 2023 10:18 PM
Post a comment

Remember personal info?