Я работаю с библиотекой fpdf, чтобы создать несколько отчетов о продажах для моей системы.У меня не было проблем с этой библиотекой до сих пор, когда я создал первый отчет.
То, что происходит, заключается в том, что мне приходится создавать отчет в конце каждого дня с информацией обо всех продажах.Эта информация сохраняется в базе данных, поэтому для создания PDF-документа мне нужно сначала выполнить несколько запросов, чтобы получить данные.Я делаю это без проблем.Проблемы начинаются, когда созданный документ PDF имеет много страниц.Дизайн документа нарушается, когда информация должна продолжаться на следующей странице.
Здесь, на этом изображении, вы можете видеть то, что я пытаюсь сказать:
Как видите, когда происходит разрыв страницы, информация не переходит в начало новой страницы и не сохраняет прежний дизайн.Вместо этого информация сбрасывается на разных страницах неверным способом.
Это мой PHP-код для создания PDF:
require('../fpdf17/fpdf.php');
include ("PrintTickets2.php");
Connection::open_db();
function generateRandomString($length) {
return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
}
$status = "Processed";
$poststatus = "Finished";
$id = intval($_GET['id']);
$AllIngredients = "";
$Result = PrintTickets2::CheckOrderToPrint(Connection::GetConnection(), $id);
$date_timeOrder= $Result[8];
if($Result)
{
$orderNum = $Result[0];
$Result2 = PrintTickets2::GlobalGetGeneral(Connection::GetConnection(), 1);
$restaurent = $Result2[2];
$adresse = $Result2[4];
$adresse = str_replace("<br>", "", $Result2[4]);
$celphone = $Result2[5];
$email = $Result2[6];
$coin = $Result2[3];
$IDRest = "YG84784FOSJD-00";
$Result3 = PrintTickets2::GetCustomerOrders(Connection::GetConnection(), $Result[1]);
$name = $Result3[1] ." ". $Result3[2];
$telefone = $Result3[8];
$emailCos = $Result3[9];
$ID_Client = $Result3[0];
$Result4 = PrintTickets2::CheckPreOrderToPrint(Connection::GetConnection(), $Result[1]);
$type_orders = $Result4[5];
if ($type_orders == "TAKE_OVER")
{
$type_orders = "TAKE OVER";
}
else if ($type_orders == "DELIVERY")
{
$type_orders = "DELIVERY";
}
$ResultPayment = PrintTickets2::GetPaymentInformations(Connection::GetConnection(), $id);
$paymentMethod = $ResultPayment[6];
$paymentName = "";
if ($paymentMethod == "Cash")
{
$paymentName = "Cash";
}
else
{
$paymentName = $paymentMethod;
}
$order_date_and_time = "";
$address786876786 = [];
if ($type_orders == "TAKE_OVER")
{
$Result15 = PrintTickets2::GetAllTakeOverDetailsByID(Connection::GetConnection(), $id);
$originalDate = $Result15[0][2];
$newDate = date("d.m.Y", strtotime($originalDate));
$order_date_and_time = "Date/Time: ". $newDate ."/". $Result15[0][3];
}
else if ($type_orders == "DELIVERY")
{
$Result16 = PrintTickets2::GetAllDeliveryDetailsByID(Connection::GetConnection(), $id);
$originalDate2 = $Result16[0][3];
$newDate2 = date("d.m.Y", strtotime($originalDate2));
$address786876786 = explode(" ", $Result16[0][2]);
$order_date_and_time = "Date/Hour: ". $newDate2 ."/". $Result16[0][4] ."\n"."Address: ".utf8_decode($address786876786[0]) ."PLZ. " . $address786876786[1] . " Ort. " . $address786876786[2];
}
$pdf = new FPDF($orientation='P', $unit='mm', 'A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',12); //Arial, (Bold), tam. 20
$pdf->SetTextColor(255, 255, 255);
$pdf->setX(30);
$pdf->Image("logo_company.JPEG",52,0,50,10);
$pdf->setY(11);
$pdf->setX(30);
$pdf->Multicell(90,5,".:: ".$restaurent." ::.", 1,"C", 1);
$pdf->SetFont('Arial','B',10);
$pdf->setX(30);
$pdf->Multicell(90,5,"Tel. " .$celphone."\n"."E-Mail: ".$email, 1,"C", 1);
$pdf->SetFont('Arial','B',10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setX(10);
$pdf->Multicell(126,5,"Date/Hour: " . date('d.m.Y H:i:s')."\n"."Customer: ".utf8_decode($name)."\n"."Order ID: ".$orderNum."\n"."Order Type: ".$type_orders."\n".$order_date_and_time."\n"."Payment Type: ".utf8_decode($paymentName), 0,"C", 0);
$pdf->setX(10);
$pdf->SetFillColor(202, 0, 0);
$pdf->Multicell(126,1," ",0,"C", 1);
//--------------------------------------------HEADER-----------------------------------------------------
$pdf->SetFont('Arial','B',10);
$pdf->SetTextColor(0, 0, 0);
$y = $pdf->GetY();
$pdf->SetY($y);
$pdf->SetFont('Arial','B',10);
$y = $pdf->GetY();
$pdf->MultiCell(15,5,"QNT.",0,'L',0);
$pdf->SetXY(25,$y);
$y = $pdf->GetY();
$pdf->MultiCell(81,5,"PRODUCT",0,'L',0);
$pdf->SetXY(106,$y);
$y = $pdf->GetY();
$pdf->MultiCell(30,5,"PRICE",0,'L',0);
//---------------------------------------------HEADER--------------------------------------
$pdf->SetFont('Arial','B',10);
$pdf->SetTextColor(0, 0, 0);
//----------------------------------------------------------------------------------------
$dish_details = "";
$Result6 = PrintTickets2::CheckOrderDetailsToPrint(Connection::GetConnection(), $Result[0]);
$DISHES_NUM = count($Result6);
$subtotalPrice = $Result[2];
$totalRabatt = $Result[3];
$total = $Result[5]; //$Result[2];
for ($i=0; $i < count($Result6); $i++)
{
$price = 0;
$Result5 = PrintTickets2::CheckOrderDishesToPrint(Connection::GetConnection(), $Result6[$i][2]);
//print_r($Result5);
if ($type_orders == "LIEFERN")
{
$Result10 = PrintTickets2::GetAllMenuDetailsByID(Connection::GetConnection(), $Result5[0][0], $Result6[$i][4]);
for ($j=0; $j < $Result6[$i][3]; $j++)
{
$price = ($price + $Result10[0][4]);
}
}
else if ($type_orders == "ABHOLEN")
{
$Result10 = PrintTickets2::GetAllMenuDetailsByID(Connection::GetConnection(), $Result5[0][0], $Result6[$i][4]);
for ($j=0; $j < $Result6[$i][3]; $j++)
{
$price = ($price + $Result10[0][3]);
}
}
$y = $pdf->GetY();
$pdf->SetY($y+2);
$pdf->SetFont('Arial','B',10);
$y = $pdf->GetY();
$pdf->MultiCell(15,4,$Result6[$i][3],0,'L',0);
$pdf->SetXY(25,$y);
$y = $pdf->GetY();
$pdf->MultiCell(81,4,utf8_decode($Result5[0][6]). " " .utf8_decode($Result5[0][2]). " (".$Result6[$i][4] .") Valor de Y: " .$y,0,'L',0);
$pdf->SetXY(106,$y);
$y = $pdf->GetY();
$pdf->MultiCell(30,4,number_format($price, 2, ".", "") . " ".$coin,0,'L',0);
//FREE ITEMS-------------------------------------------------------------------------------
$Result110 = PrintTickets2::GetAllIngredientsDishInOrder(Connection::GetConnection(), $Result[0]);
if ($Result110)
{
for ($r=0; $r < count($Result110); $r++)
{
if (intval($Result110[$r][6]) == intval($Result5[0][0]) && intval($Result110[$r][8]) == intval($Result6[$i][6]) && $Result6[$i][5] == $Result110[$r][7])
{
$AllIngredients = $AllIngredients.", ".utf8_decode($Result110[$r][5]);
}
else
{
}
}
$AllIngredients = trim($AllIngredients, ", ");
$y = $pdf->GetY();
$pdf->SetY($y);
$pdf->SetFont('Arial','B',8);
$y = $pdf->GetY();
$pdf->MultiCell(15,4,"",0,'L',0);
$pdf->SetXY(25,$y);
$y = $pdf->GetY();
$pdf->MultiCell(81,4,$AllIngredients,0,'L',0);
$pdf->SetXY(106,$y);
$y = $pdf->GetY();
$pdf->MultiCell(30,4,"",0,'L',0);
}
$AllIngredients = "";
//EXTRA ITEMS--------------------------------------------------------------------------------------
$Result11 = PrintTickets2::GetAllExtraToPrintOrders(Connection::GetConnection(), $Result[0], $Result6[$i][2], $Result6[$i][6]);
if ($Result11)
{
for ($k=0; $k < count($Result11); $k++)
{
$y = $pdf->GetY();
$pdf->SetY($y);
$pdf->SetFont('Arial','B',8);
$y = $pdf->GetY();
$pdf->MultiCell(15,4,"",0,'L',0);
$pdf->SetXY(25,$y);
$y = $pdf->GetY();
$pdf->MultiCell(81,4,$Result11[$k][4] . "x (XXOUT43) " . utf8_decode($Result11[$k][6]),0,'L',0);
$pdf->SetXY(106,$y);
$y = $pdf->GetY();
$pdf->MultiCell(30,4,$Result11[$k][5]. " ".$coin,0,'L',0);
}
}
} //for result6
//-------------------------------------------------------
$pdf->setX(10);
$pdf->SetFillColor(202, 0, 0);
$pdf->Multicell(126,1," ",0,"C", 1);
//---------------------------------------------------------subtotal
$y = $pdf->GetY();
$pdf->SetY($y+3);
$pdf->SetFont('Arial','B',10);
$y = $pdf->GetY();
$pdf->MultiCell(15,5,"",0,'L',0);
$pdf->SetXY(25,$y);
$y = $pdf->GetY();
$pdf->MultiCell(81,5,"Subtotal",0,'L',0);
$pdf->SetXY(106,$y);
$y = $pdf->GetY();
$pdf->MultiCell(30,5,$subtotalPrice." ".$coin,0,'L',0);
//------------------------------------------------------------discount
$y = $pdf->GetY();
$pdf->SetY($y);
$pdf->SetFont('Arial','B',10);
$y = $pdf->GetY();
$pdf->MultiCell(15,5,"",0,'L',0);
$pdf->SetXY(25,$y);
$y = $pdf->GetY();
$pdf->MultiCell(81,5,"Discount",0,'L',0);
$pdf->SetXY(106,$y);
$y = $pdf->GetY();
$pdf->MultiCell(30,5,$totalRabatt." ".$coin,0,'L',0);
//--------------------------------------------------------------total
$y = $pdf->GetY();
$pdf->SetY($y);
$pdf->SetFont('Arial','B',10);
$y = $pdf->GetY();
$pdf->MultiCell(15,5,"",0,'L',0);
$pdf->SetXY(25,$y);
$y = $pdf->GetY();
$pdf->MultiCell(81,5,"Total to Pay",0,'L',0);
$pdf->SetXY(106,$y);
$y = $pdf->GetY();
$pdf->MultiCell(30,5,$total." ".$coin,0,'L',0);
$url_pdf = "documents/SalesDetails".date('d-m-y').".pdf";
$pdf->output($url_pdf,"F");
}
else
{
echo "No information available.";
}
Connection::close_db();
Есть ли способ решить эту проблему в этой библиотеке?