Hi

I am using html2pdf to convert php output to a pdf.
When I run this code without injecting any other php code it works fine.

However, prior to creating a pdf, I need to find the the current user and display variables based on that id.
I wrote code to run a query to get this result, then I save the results to variables.

Once I add that code in before the conversion, the code no longer works.

How do I resolve this issue?

This code works

    require ("WriteHTML.php");

    $pdf=new PDF_HTML();

    $pdf->AliasNbPages();
    $pdf->SetAutoPageBreak(true, 15);

    $pdf->AddPage();

    $pdf->SetFont("Arial","B",9);

    $sMsg     = "<html>
    <head>
    <body>
    <div align=center>
    <table  style='width: 900px;  color: black;  border: 1px solid DimGray;'>
    <tr>
        <td style='font-family: Arial;   font-size: 22px;   color: black;   width: 900px;' valign=top>
        TEMP CERTIFICATE OF LIABILITY INSURANCE
        </td>       
        <td align='center' style=' font-family: Arial;   font-size: 15px;   color: black;border-left:1px solid DimGray; '>
        <b>Date (MM/DD/YY)</b><br/>
        Sample Date
        </td>       
    </tr></table>

    </body>
    </html>
    ";

    $pdf->WriteHTML2("<br><br>$sMsg");

    $pdf->SetFont('Arial','B',6);
    $pdf->Output(); 

This code does not:

    $current_user = wp_get_current_user();

        if ( ! ($current_user instanceof WP_User) )
    {
          print ("<script language='JavaScript'>");
          print (" window.parent.location='http://transure.bserv.com';");
          print ("</script>");
          exit();
    }

    $sql = "SELECT 
    A.ID,  A.user_login, B.meta_value

    FROM wp_users A 
    INNER JOIN wp_usermeta B 
    ON A.ID = B.user_id
    WHERE B.user_id =  $current_user->ID 
    and B.meta_key = 'wpcf-application-date'";

    $result = mysql_query($sql);

    if (!$result) 
    {
       echo 'Could not run query: ' . mysql_error();
       exit;
    }



    $user_id = $current_user->ID;
    $single   = true;

    $key1      = "wpcf-application-date";
    $app_date = get_user_meta($user_id, $key1, $single ); 
    $sTemp1 = date('m/d/Y', $app_date);

    $key2      = "wpcf-company-addr";
    $cert = get_user_meta($user_id, $key2, $single ); 

    $key12      = "wpcf-cert-holder-address";
    $cert_addr = get_user_meta($user_id, $key12, $single ); 

        $sMsg     = "
    <div align=center>
    <table  style='width: 900px;  color: black;  border: 1px solid DimGray;'>
    <tr>
        <td style='font-family: Arial;   font-size: 22px;   color: black;   width: 700px;' valign=top>
        TEMP CERTIFICATE OF LIABILITY INSURANCE
        </td>       
        <td align='center' style=' font-family: Arial;   font-size: 15px;   color: black;border-left:1px solid DimGray; '>
        <b>Date (MM/DD/YY)</b><br/>
        $sTemp1
        </td>       
    </tr></table>

First, you need to debug and find out WHERE the script breaks. Also, I believe your $sMsg must be a full HTML format (starts with <html>, contains <body> tag, and ends with </html>).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.