Solved

Why i get this error ?

Posted on 2014-01-16
10
638 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
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 27

Expert Comment

by:yodercm
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 34

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 34

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 27

Expert Comment

by:yodercm
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 109

Accepted Solution

by:
Ray Paseur earned 500 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 34

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 109

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 109

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Insert Button on a table 16 38
Ahax pagination 9 33
send email part1 9 28
Wordpress - Adding an if/else Conditional Argument in a Post Template 4 8
This article discusses how to create an extensible mechanism for linked drop downs.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

838 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