Site hosted by Angelfire.com: Build your free website today!




Overview.

C Tutorials.

C/C++ Code/Examples.

Postscript

Visit Crisp Design Central.

Mail Web Master






Postscript Tutorials


Here are my postscript tutorials:

Sending Data to the Printer

Printing Text

Printing Bitmap Images

Making Encapsulated Postscript



Other people's postscript tutorials:

A First Guide to Postscript



Sending Data to Printer

You may have thought that sending stuff to the printer was as simple as fprintf to the printer stream. However, this sadly is not the case. When you write to the printer stream, no errors are reported until the after the data has been sent. This means that if you are sending data too quickly for the printer, some of it will be lost. This would quickly make a mess of any image being sent. Thus we must use bios and interupts. Here is a procedure which sends characters to the printer:

void p_char(int c)

{

    union REGS r;

    do {

      r.h.ah = 2;

      r.x.dx = 0;

      int86( 0x17, &r, &r ); //call interupt 17,2. In the dx register is the lpt port (ie, 0=lpt1, 1=lpt2, 2=lpt3 etc).

                //this interupt returns in the ah register much info about the printer

    } while (!(r.h.ah & 0x80)); //this checks the status bit to see whether the printer is idle/ready to recieve data or not.

            //loops until printer is ready. You can add a time out here if you want.

    r.h.ah = 0;

    r.h.al = c; //put the char to be printed in al register

    r.x.dx = 0; //which lpt port

    int86( 0x17, &r, &r ); //call 17,0

}

From that you can easily make a p_string( char* s ) function to print strings by using a loop.

That out of the way, we can get on to actually printing!



Printing Text

Note: p_string is a procedure which sends strings to the printer. Check last section "Sending Data to a Postscript Printer" for more details.

This following code should print some text at the bottom left of a piece of A4 paper. The coordinate system is in pixels from the left bottom corner of the page. Therefore 30, 800 is about the top left of the page (remember to take into account printing margins - most printers would not be able to print to 0, 0 for example).

p_string("\r\n/Times-Roman findfont");// Get the basic font from the printer's database.

                   // the printer stores all its fonts as images.

p_string("\r\n20 scalefont"); // Scale the font image to 20 point

points p_string("\r\nsetfont"); // Make it the current font

p_string("\r\nnewpath"); //Start a new path

p_string("\r\n72 72 moveto"); // botom left corner of text

p_string("\r\n(What a waste of paper and toner!) show"); //print some text

p_string("\r\nshowpage\r\n"); //ejects the page from the printer

And voila, you should now be able to print text.