Introduction Interfaces Buy Support More ActiveX Site Home

ActivePrinter --- Sample: Millimeter Paper


JavaScript Codes
Open printer. You must replace the printer name with that of your printer
var PRN=new ActiveXObject("ActivePrinter.Printer");
PRN.OpenPrinter("Adobe PDF", 1, true);
PRN.BeginPrint("mmpaper");
PRN.BeginPage();

Layout
var margin=20;
var cols=parseInt((PRN.GetPageWidth()-margin*2)/10);
var rows=parseInt((PRN.GetPageHeight()-margin*2)/10);
var x1=(PRN.GetPageWidth()-cols*10)/2;
var x2=x1+cols*10;
var y1=(PRN.GetPageHeight()-rows*10)/2;
var y2=y1+rows*10;

Draw lines every mm, horizontally and vertically
var pen=PRN.CreatePen();
pen.SetWidth(0);
pen.SetStyle("solid");
pen.SetColor("128,128,128");
var y=y1;
while(y<=y2)
    {
    pen.Line(x1, y, x2, y);
    y+=1;
    }
var x=x1;
while(x<=x2)
    {
    pen.Line(x, y1, x, y2);
    x+=1;
    }

Draw lines every 5 mm, horizontally and vertically
pen.SetColor("0,0,0");
pen.SetWidth(0.05);
y=y1;
while(y<=y2)
    {
    pen.Line(x1, y, x2, y);
    y+=5;
    }
x=x1;
while(x<=x2)
    {
    pen.Line(x, y1, x, y2);
    x+=5;
    }

Draw lines every 10 mm, horizontally and vertically
pen.SetWidth(0.1);
pen.SetColor("0,0,0");
y=y1;
while(y<=y2)
    {
    pen.Line(x1, y, x2, y);
    y+=10;
    }
x=x1;
while(x<=x2)
    {
    pen.Line(x, y1, x, y2);
    x+=10;
    }

Draw lines every 10 cm, horizontally and vertically
pen.SetWidth(0.3);
y=y1;
while(y<=y2)
    {
    pen.Line(x1, y, x2, y);
    y+=100;
    }
x=x1;
while(x<=x2)
    {
    pen.Line(x, y1, x, y2);
    x+=100;
    }

Draw frame box
pen.SetWidth(0.5);
pen.SetStyle("solid", "round", "miter");
pen.Rectangle(x1, y1, x2, y2);


Draw our tag
var text=PRN.CreateText();
text.SetFont("Arial", 3);
var tag="Printed with XUEBROTHERS ActivePrinter (http://www.xuebrothers.net/ax/activeprinter/activeprinter.htm)";
text.Draw(tag, x2, y2+10, 3);
PRN.EndPage();
PRN.EndPrint();