tags:

views:

146

answers:

4

Hi

I want to place sudoku puzzles(9X9 size) on A4 paper, 4 on front side of the page and 4 on back side of the page.I am in need to generate 12 pages booklet with 96 sudoku puzzles each 8 sudoku puzzles.Does any body guide me how to do this either using perl or C#.I do not know which website or manual to go through for information.

Any help is greatly appreciated

A: 

Here is an article about printing using C#.

Andrew Keith
+3  A: 

For C#, take a look at iTextSharp. It's open source. Here's a tutorial on sourceforge, but if you search you can find higher quality tutorials like this one:

Creating Simple PDF Files With iTextSharp

Jay Riggs
+2  A: 

There are quite a few modules on CPAN for creating PDF objects / files.

PDF::API2 comes up favourite most times but there are others. See this SO question: What is the best Perl module to use for creating a .pdf from scratch?

There is a nice beginners tutorial: Using PDF::API2 - The Code

You may also been interested in fact that CPAN does seem to have quite a few Sudoku modules. Games::Sudoku::Component stands out because it does generate Sudoku puzzles.

/I3az/

draegtun
A: 

I would have used a Perl script to generate LaTeX scripts. But that's me.

Edit:

Well, this is what I love about Stackoverflow: lots of interesting and fun problems to solve. My wife is kind of a Sudoku junkie, so I thought printing a couple of booklets to keep her happy wouldn't hurt.

Note: A sample result PDF file is available at Scribd.

First, I went to CTAN (in case you don't know, this is CPAN's big brother.) I found a module for LaTeX called (what else?) sudoku. I read the documentation and deemed it good enough.

Secondly, I wanted it in booklet format. This time, the module I found on CTAN was too obscure and difficult to use, so I kept searching and found an article named LaTeX: creating a5 booklets written by Sven Hartenstein. The first line on this article says "this is how I produce A5 booklets printed on A4 paper (which is then folded once) with LaTeX ..."

Last, I searched CPAN for a good Sudoku generator. There are lots of solvers, but I just wanted to print a puzzle, so I settled with Games::Sudoku::Component and I wrote a little Perl script for generate the TeX file, called sudoku.pl:

#!/usr/bin/perl
use strict;
use warnings;
use Games::Sudoku::Component;

my $sudoku = Games::Sudoku::Component->new(size => 9);
print '
\documentclass[a5paper,headsepline,titlepage,10pt,normalheadings,DIVcalc]{scrbook}
\usepackage{sudoku}
\begin{document}
\title{Sudoku}
\author{L. Herrera}
\maketitle
\renewcommand*\sudokuformat[1]{\Large\sffamily#1}
\setlength\sudokusize{6cm}
\setlength\sudokuthickline{1pt}
';

print "\\chapter*{Easy puzzles}\n";
foreach (1 .. 16) {
    print "\\section*{Puzzle $_}\n";
    $sudoku->generate(blanks => 50);
    my $puzzle = $sudoku->as_string(
        separator => '|',
        linebreak => "|.\n|",
    );
    $puzzle =~ s/0/ /gs;
    print "\\begin{sudoku}\n|", $puzzle, "|.\n";
    print "\\end{sudoku}\n\n\n";
}
print "\\end{document}\n";

Then, I copied verbatim the script created by Sven and named it booklet.sh:

#!/bin/sh
#
# This script takes an A5 latex file as input and produces an A4
# document (both ps and pdf) for printing an A5 booklet 
#
# Usage: 
# booklet [filename without extension]

latex $1
latex $1

# make an a5 ps from dvi:
dvips -t a5 -o $1.ps $1.dvi

# sort pages
psbook $1.ps tmp1.ps

# put two pages on one a4 sheet
psnup -Pa5 -pa4 -2 tmp1.ps tmp2.ps

# change a5 to a4 in ps file
sed 's/^%%DocumentPaperSizes: A5/%%DocumentPaperSizes: a4/g' < tmp2.ps > $1_booklet.ps

# produce pdf files, pdflatex ist used (twice) to get bookmarks
pdflatex $1.tex
pdflatex $1.tex
ps2pdf -sPAPERSIZE=a4 $1_booklet.ps

# delete tmp files
rm tmp1.ps tmp2.ps

Now, I regenerate a small booklet ready for print just by executing

perl sudoku.pl > puzzle1.tex && ./booklet.sh puzzle1
Leonardo Herrera