Menu

Unit Measurement for X and Y coordinates using SetXY and Write

Help
2014-12-02
2014-12-05
  • RationalRabbit

    RationalRabbit - 2014-12-02

    My projects entail creating an HTML form (with PHP) and submitting that form to a tcpdf file using a blank form as background.
    Fields are placed into an array, example below:
    $Display=array
    (
    array("field" => $Group, "X" => 176, "Y" => 30),
    array("field" => $Name, "X" => 5, "Y" => 37),
    array("field" => $SocialSecurity, "X" => 160, "Y" => 37),
    etc.
    }
    Then:
    $pdf->AddPage();

    $pdf->setSourceFile('templates/PDF_File.pdf');
    $tplIdx = $pdf->importPage(1);
    $pdf->useTemplate($tplIdx, 0, 0, 217);

    for($i = 0; $i < sizeof($Display2); ++$i)
    {
    $Xpos = $Display2[$i]["X"];
    $Ypos = $Display2[$i]["Y"];

      $pdf->SetXY($Xpos, $Ypos);
      $pdf->Write(0, $Display2[$i]["field"]);
    

    }

    $pdf->Output('File1.pdf', 'D');

    Some of these forms are quite long, and it takes some time to figure out the coordinates. I've tried writing a JavaScript routine I can temporarily add to the page to figure the coordinates using a mouse, but I can't seem to find a reasonably workable calculation to convert the mouse coordinates to TCPDF's coordinates. The only alternative I can see is to create a grid and overlay it temporarily over the background form. There must be an easier way. What are TCPDF's units measured in? I can't seem to find that information.

     
  • cpw

    cpw - 2014-12-05

    What are TCPDF's units measured in?

    The unit is set in TCPDF's constructor as the second argument, valid units are

    • pt (point)
    • mm (millimeter)
    • cm (centimeter)
    • in (inch)

    The default value (if you don't provide one) is millimeters, also see
    http://www.tcpdf.org/doc/code/classTCPDF.html#a134232ae3ad1ec186ed45046f94b7755

     

Log in to post a comment.