<?php

define
('xMax'595);
define('yMax'842);

define('pdfFileName''grid.pdf');

function 
init_func($xMax$yMax)
{
  
$p PDF_new();

  
PDF_begin_document($p'''');
  
PDF_begin_page_ext($p$xMax$yMax'');

  return 
$p;
}

function 
drawLines($p$xMax$yMax)
{
  
# PDF_setdash($p, 2.0, 2.0);
  
PDF_setcolor($p'stroke''rgb'0.70.70.70.7);

  for (
$i 0$i $xMax$i += 5) {
    
PDF_moveto($p$i$yMax);
    
PDF_lineto($p$i0);
  }
  for (
$j 0$j $yMax$j += 5) {
    
PDF_moveto($p$xMax$j);
    
PDF_lineto($p0$j);
  }

  
PDF_stroke($p);
}

function 
wrapUp_func($p$pdfName)
{
  
PDF_end_page_ext($p'');
  
PDF_end_document($p'');

  
$buf PDF_get_buffer($p);
  
$len strlen($buf);

  
header("Content-type: application/pdf");
  
header("Content-Length: $len");
  
header("Content-Disposition: inline; filename=".$pdfName);
  print 
$buf;

  
PDF_delete($p);
}

################################
$p init_func(xMaxyMax);
drawLines($pxMaxyMax);
wrapUp_func($ppdfFileName);

?>