SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    FPDF/FPDI Import Page

    I have a database that is printing a medication list on to an existing PDF template. The template currently has room for 4 medications. If the user has 5-10 medications, I would like to generate a second page with the same header information and same background template PDF on the second page.

    I am also having so difficulty with spacing.

    PLEASE HELP!

    PHP Code:
    <?php
    require_once('auth.php');      //Confirm user is logged in
    require_once('config.php');    //Database connection details
    require_once('connect.php');   //Connect to database

    $sql="SELECT * FROM $tbl_members WHERE username = '" $_SESSION['SESS_LOGIN'] . "'";
    $result=mysql_query($sql);
    $rows=mysql_fetch_array($result);

    $sqlmedications="SELECT * FROM $tbl_medications WHERE username = '" $_SESSION['SESS_LOGIN'] . "'";
    $resultmedications=mysql_query($sqlmedications);

    $name $lastname $rows['lastname']. ", " .$rows['firstname'];
    $dob $rows['dob'];
    $session $rows['session'];
    $village $rows['village'];
    $allergylist $rows['allergylist'];
    $allergy $rows['allergy'];

    require_once(
    'pdf/fpdf.php');
    require_once(
    'pdf/fpdi.php');


    // initiate FPDI
    $pdf =& new FPDI();
    // add a page
    $pdf->AddPage('L''Letter');
    // set the sourcefile
    $pdf->setSourceFile('pdf/chart_template.pdf');
    // import page 1
    $tplIdx $pdf->importPage(1);
    // use the imported page and place it at point 10,10 with a width of 100 mm
    $pdf->useTemplate($tplIdx);

    // now write some text above the imported page
    $pdf->SetTextColor(0,0,255);

    $pdf->SetFont('Arial''B');
    $pdf->SetFontSize(18);

    $pdf->SetXY(1678);
    $pdf->Cell(100,5,$name,1,0,'R');

    $pdf->SetXY(78);
    $pdf->Cell(100,5,$village,1,0,'L');

    $pdf->SetFont('Arial');
    $pdf->SetFontSize(14);

    $pdf->SetXY(715);
    $pdf->Cell(100,5,$session,1,0,'L');

    $pdf->SetFontSize(12);
    $pdf->SetXY(16716);
    if (
    $allergy == "no") {
    $pdf->Cell(100,5,'No known allergies',1,0,'R'); }
    $pdf->SetXY(16716);
    $pdf->Cell(100,5,$allergylist,1,0,'R');

    $pdf->SetXY(726);
    $pdf->SetFontSize(11);
    while(
    $rowsmedications=mysql_fetch_array($resultmedications)){
        
    $pdf->SetFont('Arial''B');
        
    $pdf->Cell(115,5,$rowsmedications['med']. " (" .$rowsmedications['strength']. ")",1,0,'L');

        
    $pdf->SetFont('Arial');
        
    $pdf->SetFontSize(9);
        
    $pdf->SetX(127);
        
    $pdf->Cell(140,5,$rowsmedications['info'],1,0,'R');
            
        
    $pdf->Ln(10);
        
    $pdf->SetX(7);
        
    $pdf->MultiCell(28,3,$rowsmedications['dose'],1,'C');
        
    $pdf->SetFontSize(8);
        
    $pdf->Ln(2);

    $sum $rowsmedications['breakfast'] + $rowsmedications['lunch'] + $rowsmedications['dinner'] + $rowsmedications['bedtime'] + $rowsmedications['prn'];
    if (
    $rowsmedications['breakfast'] == 1) {$breakfast "Breakfast\r\n"; }
    if (
    $rowsmedications['lunch'] == 1) {$lunch "Lunch\r\n"; }
    if (
    $rowsmedications['dinner'] == 1) {$dinner "Dinner\r\n"; }
    if (
    $rowsmedications['bedtime'] == 1) {$bedtime "Bedtime\r\n"; }
    if (
    $rowsmedications['prn'] == 1) {$prn "As Needed\r\n"; }

    $timestogive $breakfast.$lunch.$dinner.$bedtime.$prn;
    if (
    $sum == 1) { $timestogive $timestogive."\r\n\r\n\r\n\r\n\r\n"; }
    if (
    $sum == 2) { $timestogive $timestogive."\r\n\r\n\r\n\r\n"; }
    if (
    $sum == 3) { $timestogive $timestogive."\r\n\r\n\r\n"; }
    if (
    $sum == 4) { $timestogive $timestogive."\r\n\r\n"; }
    if (
    $sum == 5) { $timestogive $timestogive."\r\n"; }

    $pdf->Write(3,$timestogive);

    $breakfast "";
    $lunch "";
    $dinner "";
    $bedtime "";
    $prn "";
    $timestogive "";

        
        
    $pdf->Ln(11.5);
        
    $pdf->SetFontSize(9);
        
    $pdf->SetX(7);
    }


    $pdf->Output('Health Form.pdf''I');

    ?>

  2. #2
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ambrosem, were you successful in doing that?. If I understood right, on the second page which you would create you want only parts of the content from the pdf that is read, is it so?.

    It seems with the -xpdf package- we could read the contents from a pdf file, but manipulating/aligning the content read to fit a pdf is something I am clueless about now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •