mythri Posted March 28, 2014 Share Posted March 28, 2014 Hello , I am trying to export my data to pdf, but some junk data is getting displayed when i hit print pdf button. Here is the output i am getting %PDF-1.7 % 7 0 obj << /Type /Page /Parent 1 0 R /LastModified (D:20140328100129+05'30') /Resources 2 0 R /MediaBox [0.000000 0.000000 595.276000 841.890000] /CropBox [0.000000 0.000000 595.276000 841.890000] /BleedBox [0.000000 0.000000 595.276000 841.890000] /TrimBox [0.000000 0.000000 595.276000 841.890000] /ArtBox [0.000000 0.000000 595.276000 841.890000] /Contents 8 0 R /Rotate 0 /Group << /Type /Group /S /Transparency /CS /DeviceRGB >> /Annots [ 6 0 R ] /PZ 1 >> endobj 8 0 obj <> stream xřr0yLf@ч%%09$ ة+c2`v$_ڵ0>6Tܜpsg^bss9`@M8m'~&) XF ^>52߿ 6H2/@(&rl buAQlbD<.S.m}2 3ƒtrǹS~Re(F#6ir쇈zax8KS%S=s(/rA_OcC !7)ogw\8&RchUvO>QPuZrgE҅S5U,eIwZ(_5Eu-k.xwp ̽7`N=k '|hhiܑ=n]%{&llCiyWV0w|4;7ȩվ2!ʵL`u3vkf*x{kv5xfWGhv5tfj]}[4s3_/7=4/ lK> endobj 3 0 obj <> endobj 4 0 obj <> endobj 5 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 3 0 R /F2 4 0 R /F3 5 0 R >> /XObject << >> >> endobj 6 0 I don't know why i am getting this and how to resolve this. My php code is <?php include('includes/SQL_CommonFunctions.inc'); //include('includes/session.inc'); if(isset($_POST['ShowPR'])) { include('includes/session.inc'); $Title=_('PhilHealth Monthly Premium Listing'); include('includes/header.inc'); include('includes/prlFunctions.php'); $sql = "SELECT employeeid,basicpay,othincome,absent,late,otpay,grosspay,loandeduction,sss,hdmf,philhealth,tax,netpay FROM prlpayrolltrans WHERE prlpayrolltrans.payrollid='" .$_POST['PayrollID']. "'"; $PayResult = DB_query($sql,$db); if(DB_num_rows($PayResult)>0) { echo '<table class="selection">'; echo "<tr> <th>" . _('Emp ID') . "</th> <th>" . _('Full Name') . "</th> <th>" . _('Basic') . "</th> <th>" . _('Other Income') . "</th> <th>" . _('Overtime') . "</th> <th>" . _('Gross') . "</th> <th>" . _('SSS ') . "</th> </tr>"; $k=0; //row colour counter while ($myrow=DB_fetch_array($PayResult)) { $EmpID =$myrow['employeeid']; $FullName=GetName($EmpID, $db); $Basic =$myrow['basicpay']; $OthInc = $myrow['othincome']; $OT =$myrow['otpay']; $Gross =$myrow['grosspay']; $SSS =$myrow['sss']; $HDMF =$myrow['hdmf']; $PhilHealth = $myrow['philhealth']; $Loan =$myrow['loandeduction']; $Tax = $myrow['tax']; $Net =$myrow['netpay']; $GTBasic +=$myrow['basicpay']; $GTOthInc += $myrow['othincome']; $GTOT +=$myrow['otpay']; $GTGross +=$myrow['grosspay']; $GTSSS +=$myrow['sss']; $GTHDMF +=$myrow['hdmf']; $GTPhilHealth += $myrow['philhealth']; $GTLoan +=$myrow['loandeduction']; $GTTax += $myrow['tax']; $GTNet +=$myrow['netpay']; if ($k==1){ echo "<tr class='EvenTableRows'>"; $k=0; } else { echo "<tr class='OddTableRows'>"; $k++; } echo '<td>' . $EmpID . '</td>'; echo '<td>' . $FullName . '</td>'; echo '<td>' . $GTBasic . '</td>'; echo '<td>' . $GTOthInc . '</td>'; echo '<td>' . $GTOT . '</td>'; echo '<td>' . $GTGross . '</td>'; echo '<td>' . $SSS . '</td>'; echo '<td><a href="'. $RootPath . '/prlCreatePayroll.php?PayrollID=' . $PayrollID . '">' . _('Select') . '</a></td>'; echo '<a href="' . $RootPath . '/StockStatus.php?StockID=' . $StockID . '">' . _('Show Stock Status') . '</a><br />'; echo '</tr>'; } } echo 'Use PrintPDF instead'; echo "<BR><A HREF='" .$RootPath ."/index.php?" ."'>" . _('Back to the menu') . '</A>'; include('includes/footer.inc'); exit; } If (isset($_POST['PrintPDF']) AND isset($_POST['PayrollID'])) { include('includes/session.inc'); include('includes/PDFStarter.php'); include('includes/prlFunctions.php'); $pdf->addinfo('Title', _('Payroll Register') ); $pdf->addinfo('Subject', _('Payroll Register') ); $FontSize = 10; $PageNumber = 0; $line_height = 12; $PayDesc = GetPayrollRow($_POST['PayrollID'], $db,1); $FromPeriod = GetPayrollRow($_POST['PayrollID'], $db,3); $ToPeriod = GetPayrollRow($_POST['PayrollID'], $db,4); $EmpID =''; $Basic = 0; $OthInc = 0; $Lates = 0; $Absent = 0; $OT = 0; $Gross = 0; $SSS = 0; $HDMF =''; $PhilHealt = 0; $Loan = 0; $Tax = 0; $Net = 0; include('includes/PDFPayRegisterPageHeader.inc'); $k=0; //row colour counter $sql = "SELECT employeeid,basicpay,othincome,absent,late,otpay,grosspay,loandeduction,sss,hdmf,philhealth,tax,netpay FROM prlpayrolltrans WHERE prlpayrolltrans.payrollid='" .$_POST['PayrollID']. "'"; $PayResult = DB_query($sql,$db); if(DB_num_rows($PayResult)>0) { while ($myrow=DB_fetch_array($PayResult)) { $EmpID =$myrow['employeeid']; $FullName=GetName($EmpID, $db); $Basic =$myrow['basicpay']; $OthInc = $myrow['othincome']; $OT =$myrow['otpay']; $Gross =$myrow['grosspay']; $SSS =$myrow['sss']; $HDMF =$myrow['hdmf']; $PhilHealth = $myrow['philhealth']; $Loan =$myrow['loandeduction']; $Tax = $myrow['tax']; $Net =$myrow['netpay']; $GTBasic +=$myrow['basicpay']; $GTOthInc += $myrow['othincome']; $GTOT +=$myrow['otpay']; $GTGross +=$myrow['grosspay']; $GTSSS +=$myrow['sss']; $GTHDMF +=$myrow['hdmf']; $GTPhilHealth += $myrow['philhealth']; $GTLoan +=$myrow['loandeduction']; $GTTax += $myrow['tax']; $GTNet +=$myrow['netpay']; //$YPos -= (2 * $line_height); //double spacing //$FontSize = 8; //$pdf->selectFont('./fonts/Helvetica.afm'); $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,50,$FontSize,$EmpID); $LeftOvers = $pdf->addTextWrap(100,$YPos,120,$FontSize,$FullName,'left'); $LeftOvers = $pdf->addTextWrap(221,$YPos,50,$FontSize,number_format($Basic,2),'right'); $LeftOvers = $pdf->addTextWrap(272,$YPos,50,$FontSize,number_format($OthInc,2),'right'); $LeftOvers = $pdf->addTextWrap(313,$YPos,50,$FontSize,number_format($Lates,2),'right'); $LeftOvers = $pdf->addTextWrap(354,$YPos,50,$FontSize,number_format($Absent,2),'right'); $LeftOvers = $pdf->addTextWrap(395,$YPos,50,$FontSize,number_format($OT,2),'right'); $LeftOvers = $pdf->addTextWrap(446,$YPos,50,$FontSize,number_format($Gross,2),'right'); $LeftOvers = $pdf->addTextWrap(487,$YPos,50,$FontSize,number_format($SSS,2),'right'); $LeftOvers = $pdf->addTextWrap(528,$YPos,50,$FontSize,number_format($HDMF,2),'right'); $LeftOvers = $pdf->addTextWrap(569,$YPos,50,$FontSize,number_format($PhilHealth,2),'right'); $LeftOvers = $pdf->addTextWrap(610,$YPos,50,$FontSize,number_format($Loan,2),'right'); $LeftOvers = $pdf->addTextWrap(671,$YPos,50,$FontSize,number_format($Tax,2),'right'); $LeftOvers = $pdf->addTextWrap(722,$YPos,50,$FontSize,number_format($Net,2),'right'); $YPos -= $line_height; if ($YPos < ($Bottom_Margin)){ include('includes/PDFPayRegisterPageHeader.inc'); } } }//end of loop $LeftOvers = $pdf->line($Page_Width-$Right_Margin, $YPos,$Left_Margin, $YPos); $YPos -= (2 * $line_height); $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,150,$FontSize,'Grand Total'); $LeftOvers = $pdf->addTextWrap(221,$YPos,50,$FontSize,number_format($GTBasic,2),'right'); $LeftOvers = $pdf->addTextWrap(221,$YPos,50,$FontSize,number_format($GTBasic,2),'right'); $LeftOvers = $pdf->addTextWrap(272,$YPos,50,$FontSize,number_format($GTOthInc,2),'right'); $LeftOvers = $pdf->addTextWrap(313,$YPos,50,$FontSize,number_format($GTLates,2),'right'); $LeftOvers = $pdf->addTextWrap(354,$YPos,50,$FontSize,number_format($GTAbsent,2),'right'); $LeftOvers = $pdf->addTextWrap(395,$YPos,50,$FontSize,number_format($GTOT,2),'right'); $LeftOvers = $pdf->addTextWrap(446,$YPos,50,$FontSize,number_format($GTGross,2),'right'); $LeftOvers = $pdf->addTextWrap(487,$YPos,50,$FontSize,number_format($GTSSS,2),'right'); $LeftOvers = $pdf->addTextWrap(528,$YPos,50,$FontSize,number_format($GTHDMF,2),'right'); $LeftOvers = $pdf->addTextWrap(569,$YPos,50,$FontSize,number_format($GTPhilHealth,2),'right'); $LeftOvers = $pdf->addTextWrap(610,$YPos,50,$FontSize,number_format($GTLoan,2),'right'); $LeftOvers = $pdf->addTextWrap(671,$YPos,50,$FontSize,number_format($GTTax,2),'right'); $LeftOvers = $pdf->addTextWrap(722,$YPos,50,$FontSize,number_format($GTNet,2),'right'); $LeftOvers = $pdf->line($Page_Width-$Right_Margin, $YPos,$Left_Margin, $YPos); $pdfcode = $pdf->output(); $len = strlen($pdfcode); if ($len<=20){ $Title = _('Payroll Register Error'); include('includes/header.inc'); echo '<p>'; prnMsg( _('There were no entries to print out for the selections specified') ); echo '<BR><A HREF="'. $RootPath.'/index.php?' . '">'. _('Back to the menu'). '</A>'; include('includes/footer.inc'); exit; } else { header('Content-type: application/pdf'); header('Content-Length: ' . $len); header('Content-Disposition: inline; filename=PayrollRegister.pdf'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); $pdf->Stream(); } exit; } else { /*The option to print PDF was not hit */ include('includes/session.inc'); $Title=_('Payroll Register'); include('includes/header.inc'); echo "<form method='post' action='" . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . "'>"; echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; echo '<table class="selection"><TR><TD>' . _('Select Payroll:') . '</TD><TD><SELECT Name="PayrollID">'; $sql = 'SELECT payrollid, payrolldesc FROM prlpayrollperiod'; $result = DB_query($sql, $db); DB_data_seek($result, 0); while ($myrow = DB_fetch_array($result)) { if ($myrow['payrollid'] == $_POST['PayrollID']) { echo '<OPTION SELECTED VALUE='; } else { echo '<OPTION VALUE='; } echo $myrow['payrollid'] . '>' . $myrow['payrolldesc']; } //end while loop echo '</SELECT></TD></TR>'; echo "</TABLE><INPUT TYPE='Submit' NAME='ShowPR' VALUE='" . _('Show Payroll Register') . "'>"; echo "<INPUT TYPE='Submit' NAME='PrintPDF' VALUE='" . _('PrintPDF') . "'>"; include('includes/footer.inc');; } /*end of else not PrintPDF */ ?> Please somebody help me in resolving this. Thanks Quote Link to comment Share on other sites More sharing options...
requinix Posted March 28, 2014 Share Posted March 28, 2014 Looks right to me. Add a header("Content-Type: application/pdf");before you output the PDF. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 28, 2014 Share Posted March 28, 2014 I think the real problem is you echoed stuff prior to sending the pdf, so the output is scrambled like it is. You must not send anything to the client other than the completed pdf file Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.