?
Solved

Why i get this error ?

Posted on 2014-01-16
10
Medium Priority
?
748 Views
Last Modified: 2014-01-17
Hi!

Have this report :

Gives me this error message:

Output has already been sent from the script - PDF file generation aborted.


<?php

require_once("../mpdf.php");
require_once('Connect_databse.php');

session_start();



$table3='Reportform';
$table4 = 'P_SHOW_Transactions';

ini_set("memory_limit","-1");

$mpdf=new mPDF('win-1252', 'A4', 11, 'DejaVuSansCondensed', 15, 15, 15, 15, 8, 8);
$mpdf->mirrorMargins = 0; // Use different Odd/Even headers and footers and mirror margins
$mpdf->defaultheaderfontsize = 10; /* in pts */
$mpdf->use_kwt = true;
$mpdf->keep_table_proportions = true;
$mpdf->shrink_tables_to_fit=1;
$mpdf->debug = true;
$mpdf->defaultheaderfontstyle = B; /* blank, B, I, or BI */
$mpdf->defaultheaderline = 1; /* 1 to include line below header/above footer */
$mpdf->defaultfooterfontsize = 10; /* in pts */
$mpdf->defaultfooterfontstyle = B; /* blank, B, I, or BI */
$mpdf->defaultfooterline = 1; /* 1 to include line below header/above footer */
$mpdf->SetHeader('{DATE j-m-Y}||Agreppa Report');
$mpdf->SetFooter('Side:{PAGENO}'); /* defines footer for Odd and Even Pages - placed at Outer margin */
$mpdf->SetFooter(array(
'L' => array(
'content' => 'Text to go on the left',
'font-family' => 'sans-serif',
'font-style' => 'B', /* blank, B, I, or BI */
'font-size' => '10', /* in pts */
),
'C' => array(
'content' => '- {PAGENO} -',
'font-family' => 'serif',
'font-style' => 'BI',
'font-size' => '18', /* gives default */
),
'R' => array(
'content' => 'Printed @ {DATE j-m-Y H:m}',
'font-family' => 'monospace',
'font-style' => '',
'font-size' => '10',
),
'line' => 1, /* 1 to include line below header/above footer */
), 'E' /* defines footer for Even Pages */
);





$html = '
<html>
<head>
<meta charset="utf-8" />
<style>
table.testtabell
{
    border:1px solid #cccccc;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 20px;
  margin-right: 15px;
}
.rapport2_header
{
    background-color: #efefef;
    border:1px solid #cccccc;
  color:#cccccc;
  font-size: 15px;
  font-family: Verdana;
  border-collapse: collapse;
    box-shadow: none ! important;
  padding-left:10px;
  padding-top:10px;
}
.rapport1_del8
{
   border:1px solid #cccccc;
   border-collapse: collapse;
   box-shadow: none ! important;
   padding-left:10px;
   padding-top:10px;
   font-size:12px;
   color:#0;
}

.rapport1_del9
{
   border:1px solid #cccccc;
   border-collapse: collapse;
   box-shadow: none ! important;
   padding-left:10px;
   padding-bottom:8px;
   font-size:12px;
   color:#b2b3c3;
}

.rapport1_del1
{
    background-color: #efefef;
    border:0px solid #cccccc;
  border-collapse: collapse;
    box-shadow: none ! important;
  padding-left:10px;
}
.rapport1_del2
{
   background-color: #f8f8f8;
   border-left:0px solid #cccccc;
   border-bottom:1px solid #cccccc;
   border-right:0px solid #cccccc;
   border-collapse: collapse;
   padding-left:10px;
}
.rapport_brukernavn
{
   background-color: #f8f8f8; 
   border-right:1px solid #cccccc;
   border-left:0px solid #cccccc;
   border-bottom:1px solid #cccccc;
   border-collapse: collapse;
   padding-right:10px;
   font-family: Verdana;
   font-size: 11px;
   color:#cccccc;
   text-align:right;
}
.blank_row_noborder {
  height: 20px !important;
  background-color: #FFFFFF;
}
.blank_row {
  height: 20px !important;
  background-color: #FFFFFF;
  border-bottom: 1px solid #cccccc; /* or whatever specific values you prefer */
}
.rapport1_del3
{
   background-color: #ffffff;
   font-size:12px;
    border:0px solid #cccccc;
   border-collapse: collapse;
   box-shadow: none ! important;
}
.rapport_image1
{
   background-color: #ffffff;
   border: none ! important;
   box-shadow: none ! important;
   padding-right:10px;
}
IMG.displayed {
    display: block;
    margin-left: auto;
    margin-right: auto }
</style>

</head>

<body>
';


$brukerID = $_GET["brukerID"];
$kundeid = $_GET["kundeid"];


$sql = "SELECT * FROM {$table3} WHERE UserID={$brukerID} and Organisation={$kundeid}";
$resultraptmp = sqlsrv_query($conn,$sql); 

// Hent parametere som er valgt for utvalget til rapporten
while($row3 = sqlsrv_fetch_array($resultraptmp)){

      $datofra = $row3['Datefrom'];
      $datotil = $row3['Dateto'];
      $kontr = $row3['Controllername'];
      $brukere = $row3['Username'];
      $svarsp = $row3['Answer'];
      $vilkenrapport = $row3['Report'];
      $organisasjon = $row3['OrganisationName'];
      $antsider = $row3['Pages'];
      $rec_count = $row3['Numberrecords'];
      $antrader = $row3['NumRows'];
      $datobrukes = 1;
      $side = $row3['Page'];

} 


$dagensdato = date("Y-m-d");



$html .= '<table width="100%" border="0" align="center" class="testtabell">'; 
$html .= '<tr>';
$html .= '<td class="rapport1_infodel" width="30%" align="right">Organisasjon: </td>';
$html .= '<td class="rapport1_infodel" width="70%" align="left" id="teste" name="teste">ORGNAVN</td>'; 
$html .= '</tr>';
$html .= '<tr>';   
$html .= '<td class="rapport1_infodel" width="30%" align="right">Dato: </td>';
$html .= '<td class="rapport1_infodel" width="70%" align="left">. $dagensdato . </td>'; 
$html .= '</tr>';
$html .= '</table>';


if ($vilkenrapport=="Enkel rapport"){    
$html .= '<table width="100%" align="left" class="testtabell">'; 
$html .= '<tr>';
$html .= '<th class="rapport2_header" height="40px" align="left">Kontroller</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Lokasjon</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Dato</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Object</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Spørsmål</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Svar</th>';
      
$html .= '</tr>';  
}  
     

$sql = "SELECT Name,ControlName,LocationID,Location,ControlID,Organisation,Question,Note,CreatedDate,Answer,UserID,IsScale,Object,TransactionID,Organisationname FROM {$table4}";


$sql = $sql." Where CreatedDate between '{$datofra}' AND '{$datotil}'";


$substr = "Alle kontrollere";
if (strpos($kontr, $substr) === false) {
  $sql = $sql." and ControlName='{$kontr}'";
}

$substr = "Alle brukere";
if (strpos($brukere, $substr) === false) {

  
  // Hent UserID    
   $tsql_callSP = "{call GET_UserID( ?, ?)}";
   $params = array( 
                 array($brukere, SQLSRV_PARAM_IN),
                 array($brID, SQLSRV_PARAM_INOUT)
               );

/* Execute the query. */
   $stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
   if( $stmt3 === false )
   {
       echo "Error in executing statement 1.\n";
       die( print_r( sqlsrv_errors(), true));
   }
   else
   {sqlsrv_free_stmt( $stmt3);}


  $sql = $sql." and UserID='{$brID}'";
}

if ($svarsp=="Ja"){
  $sql = $sql." and Answer='Ja'";
}

if ($svarsp=="Nei"){
  $sql = $sql." and Answer='Nei'";
}

if ($svarsp=="Avvik"){
  $sql = $sql." and Answer='Avvik'";
}

if ($svarsp=="Scale"){
  $sql = $sql." and Answer<>'Ja' and Answer<>'Nei' and Answer<>'Avvik' ";
}
  
$sql = $sql." and Organisationname='{$organisasjon}'";

$sql = $sql." ORDER BY ControlID,CreatedDate";

$retval = sqlsrv_query($conn,$sql); 

if( $retval === false )
{
       echo "Error in executing statement 12.\n";
       die( print_r( sqlsrv_errors(), true));
}

$TMP_KID=0;
$forstekontroller = 1;
$TMP_LOK=0;
$farge1="#ffffff";
$farge2="#d9eefa";
$valgfarge="#ccc";
$byttfarge = 1;
$antrader=1;
$antraderMAX= 20;



while($row3 = sqlsrv_fetch_array($retval)){
   
   $kontrollernavn = $row3['ControlName'];
   $lokasjonnr = $row3['LocationID'];
   $K_ID = $row3['ControlID'];
   $kunde_ID = $row3['Organisation'];
   $lokasjonnavn = $row3['Location']; 
   $sporsmal = $row3['Question'];
   $kommentar = $row3['Note'];
   //$transdato = $row3['CreatedDate'];
   $svar = $row3['Answer']; 
   $usID = $row3['UserID'];  
   $scaleant = $row3['IsScale'];
   $bilderef="";     // Midligtidig satt til blank
   $brukernavn= $row3['Name'];
   $objnavn=$row3['Object'];


if ($vilkenrapport=="Enkel rapport"){  
    
    
$html .= '<tr>';
                                                     
if ($byttfarge==1){
   $valgfarge=$farge2;
   $byttfarge=2;
}
else
{ 
   $byttfarge=1;
   $valgfarge=$farge1;
}   

$html .= '<td class="rapport1_del8" bgcolor=' . $valgfarge . ' align="left">' . $kontrollernavn . '</td>'; 
$html .= '<td class="rapport1_del8" bgcolor=' . $valgfarge . ' align="left">' . $lokasjonnavn .'</td>';
$html .= '<td class="rapport1_del8"  bgcolor=' . $valgfarge . ' align="left">'. $lokasjonnavn .'</td>';
$html .= '<td class="rapport1_del8" bgcolor=' . $valgfarge . ' align="left">' . $objnavn .'</td>';
$html .= '<td class="rapport1_del8"  bgcolor=' . $valgfarge . ' align="left">'. $sporsmal .'</td>'; 
      
if($svar=="Ja"){ 
   $html .= '<td colspan="2" class="rapport1_del9"  bgcolor=' . $valgfarge . ' align="left">' . $svar . '<img class="bildeviser" src="../../../images/jasvar.png" alt="Smiley face"></td>';
}

if($svar=="Nei"){ 
   $html .= '<td class="rapport1_del9"  bgcolor=' . $valgfarge . ' align="left">' . $svar . '<img class="bildeviser" src="../../../images/neisvar.png" alt="Smiley face"></td>';
}

 if($svar<>"Ja" and $svar<>"Nei"){
   $html .= '<td class="rapport1_del9"  bgcolor=' . $valgfarge . ' align="left">' . $svar . '<img class="bildeviser" src="../../../images/scale.png" alt="Smiley face"></td>';
}


}    
     
if ($vilkenrapport=="Standard rapport"){   
   
   if ($forstekontroller==1)
    {
       $forstekontroller=0;
     $TMP_KID = $K_ID;
     $TMP_LOK = $lokasjonnr;
     
        $html .='<table width="100%" align="center" class="testtabell"  style="page-break-inside:avoid">'; 
    $html .='<tr>';
    $html .='<td class="rapport1_del1" height="40px" colspan="4">' . $kontrollernavn .'</td>';
    $html .='</tr>';
    $html .='<tr>';
      $html .='<td class="rapport1_del2" colspan="3" height="40px">' . $lokasjonnavn . '</td>';
        $html .='<td class="rapport_brukernavn" >' . $brukernavn .'</td>';      
      $html .='</tr>';

    }
  

  
   if ((($TMP_KID<>$K_ID) or ($TMP_LOK<>$lokasjonnr)) and $forstekontroller==2)
   {
      if ($TMP_KID<>$K_ID) {$TMP_KID = $K_ID;}
    if ($TMP_LOK<>$lokasjonnr) {$TMP_LOK = $lokasjonnr;}
        $html .='</table>';
        $html .='<table width="100%" align="center" class="testtabell" style="page-break-inside:avoid">'; 
    $html .='<tr>';
    $html .='<td class="rapport1_del1" colspan="4" height="40px">' . $kontrollernavn . '</td>';
    $html .='</tr>';
    $html .='<tr>';
      $html .='<td class="rapport1_del2" colspan="3" height="40px">' . $lokasjonnavn .'</td>';
    $html .='<td class="rapport_brukernavn">' . $brukernavn .'</td>';
      $html .='</tr>';   
  
   }
   
    $html .='<tr class="blank_row_noborder">';
    $html .='<td colspan="4"></td>';
    $html .='</tr>';  
  
  $html .='<tr>';  
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="30%"> Sporsmål: </td>';
  $html .='<td class="rapport1_del3" valign="top" width="70%">' . $sporsmal . '</td>';
  $html .='</tr>';  
  $html .='<tr>';
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="30%"> Dato: </td>'; 
  $html .='<td  class="rapport1_del3" valign="top" width="70%">' . $lokasjonnavn .'</td>';
  $html .='<td class="rapport1_del3" valign="top"></td>';
  $html .='</tr>';
  
  $html .='<tr>'; 
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="30%"> Svar:</td>'; 
     
      if (($svar=="Ja") or ($svar=="Nei"))
    { 
         $html .='<td  class="rapport1_del3" valign="top" width="70%">' . $svar .'</td>';
    
    }
    else {
    
       $html .='<td  class="rapport1_del3" valign="top" width="70%">' . $svar . ' av ' . $scaleant .'</td>';
     }
  $html .='<td class="rapport1_del3" valign="top"></td>'; 
  $html .='</tr>';
  
  $html .='<tr>'; 
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="30%"> Kommentar:</td>'; 
  $html .='<td  class="rapport1_del3" valign="top" width="70%">' . $kommentar .'</td>';
  $html .='<td class="rapport1_del3" valign="top"></td>';
  $html .='</tr>'; 
  
  $html .='<tr class="blank_row">';
  $html .='<td colspan="4"></td>';
  $html .='</tr>';  
  
  $sql = "SELECT * FROM {$table6} WHERE TransactionID={$TransactionID}";
  $rettmp2 = sqlsrv_query($conn,$sql); 
  $teller=0;

  $html .='<tr>';  

  while($row3 = sqlsrv_fetch_array($rettmp2)){
       
       $bilde1 = "data:image/jpg;base64,"; 
       $bilde2 = $row3['TransImage'];
       $bilde3 = $bilde1 . $bilde2;
      
       $html .= '<td class="rapport_image1" colspan="4" valign="top"><img src=' . $bilde3 .' hight="190" align="left"> </td>';
    } 
    
    $html .='</tr>';  



  $forstekontroller=2;
}}

$html .= '</table>';
$html .= '</body>';
$html .= '</html>';


$mpdf->SetDisplayMode('fullpage');

$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$mpdf->WriteHTML($html);

$mpdf->Output();
exit;
?>

Open in new window


What can this error be ?
0
Comment
Question by:team2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 39785624
It is most likely because you have a blank line or some other kind of output at the top of your script.

Remove the blank lines on lines 50-55
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39785632
When you generate PDFs and want to send them straight to the browser, it means that you have to send "HTTP headers" to the browser. However, you only have one chance to send "HTTP headers". Once you begin to send anything else besides HTTP headers, the server assumes you are finished with them.

That also means that if you have any other PHP warning messages, or spaces, or ANYTHING at all, it counts as content.

If you try to set the HTTP headers after you've sent content, you will get that error message.

So now you have to figure out what is being output to the browser.
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39785636
I'm guessing the content is somewhere in one of two of these files:

require_once("../mpdf.php");
require_once('Connect_databse.php');

(by the way "database"  is misspelled)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 39785673
A blank line at the top of ANY of the scripts would do this.  

That is the most common cause.
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39785698
I believe gr8gonzo is right and it's session_start() that causes the error message.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1500 total points
ID: 39785782
Sometimes you can use output buffering to work around this.  Try this change at the top of the script.

<?php
ob_start();
require_once("../mpdf.php");
require_once('Connect_databse.php');

session_start();

Open in new window

0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39785803
session_start() does not generate content (only headers), so it would not be the culprit.

Ray is correct that ob_start() can sometimes do the trick, but it doesn't really fix the problem - it just works around it, and it may leave undesired content in the stream (potentially causing the PDF to break). It's usually better to try and figure out where the undesired content is coming from.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39785978
A minor footnote on output buffering.  It usually results in better server performance.  It's expensive to connect and disconnect repeatedly for every echo, or flip into HTML.  Worth considering as a coding standard.
0
 
LVL 2

Author Closing Comment

by:team2005
ID: 39788351
Figer it out, dident use ob_start()
But this leed to my solution
I added -> ob_end_clean();

Now its working fine, thanks
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39788403
Please refresh your memory about the grading guidelines, team2005.  You're expected to explain the marked-down grade.
http://support.experts-exchange.com/customer/portal/articles/481419

Using ob_end_clean() to "fix" the problem is like putting black electrical tape over the "check engine" warning light on your dashboard.  It masks the symptom.  A wiser approach is recommended here.  If you've determined the cause of the message and determined that it's OK to mask the symptom, then you're on firm ground to use output buffering.  But I would seriously want to collect the buffers and see what is in them!  Ob_end_clean() will prevent you from seeing that.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question