Voici votre URL de partage https://sharemycode.io/c/36d2fe4 (Cliquer pour copier) (Copié)
#[Route('/invoice/{id}', name: 'invoice')]
public function invoicePDF(
AddressesRepository $addressesRepo,
ArticlesRepository $articles,
BlocCmsRepository $cms,
CarriersServicesRepository $carriersServicesRepo,
CarriersDetailsRepository $carriersDetailsRepo,
CivilityRepository $civilityRepo,
CountriesRepository $countriesRepo,
Orders $order,
OrdersDetailsRepository $ordersDetailsRepo,
PaymentsRepository $paymentsRepo,
ProductCategoriesRepository $productCategories,
ProductsRepository $products,
MenusRepository $menus,
MenuTypesRepository $menutypes,
UsersRepository $usersRepo,
Request $request
): Response {
$address = $addressesRepo->findByUsers($this->getUser()->getId());
$locale = $request->getLocale();
$orderDatas = $ordersDetailsRepo->findBy(['orders' => $order]);
$carrier = $carriersServicesRepo->findOneBy(['id' => $order->getCarrierservice()->getId()]);
$payment = $paymentsRepo->findOneBy(['id' => $order->getPayment()->getId()]);
$carrierdetail = $carriersDetailsRepo->find($order->getCarrier());
$civility = $civilityRepo->findOneById($order->getUsers()->getCivility());
$customer = $usersRepo->findOneById($order->getUsers()->getId());
$country = "";
if (!is_null($order->getUsers()->getCountries())) {
$countryResult = $countriesRepo->findOneById($order->getUsers()->getCountries());
$country = ($locale == "fr_fr") ? $countryResult->getNomFrFr() : $countryResult->getNomEnGb();
}
// $imageSrc = $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/assets/images/footer_logo.png');
$orderDate = $order->getCreatedAt();
$data = [
'civility' => $civility,
'country' => $country,
'customer' => $customer,
'imageSrc' => $this->imageToBase64($this->getParameter('kernel.project_dir') . '/public/assets/images/footer_logo.png'),
'order' => $order,
'orderDatas' => $orderDatas,
'payment' => $payment,
'carrier' => $carrier,
'orderDate' => $orderDate,
'carrierdetail' => $carrierdetail,
'address' => $address
];
// return $this->render('orders/invoice.html.twig', compact('imageSrc', 'order', 'orderDate', 'orderDatas'));
$html = $this->renderView('orders/invoice.html.twig', $data);
$dompdf = new Dompdf();
$pdfOptions = new Options();
$pdfOptions->set('defaultMediaType', 'all');
$pdfOptions->set('isFontSubsettingEnabled', true);
$pdfOptions->set("isPhpEnabled", true);
$dompdf->setOptions($pdfOptions);
$dompdf->set_paper('A4', 'landscape');
$canvas = $dompdf->get_canvas();
$canvas->page_text(0, 0, "{PAGE_NUM} / {PAGE_COUNT}", null, 10, array(0, 0, 0));
$dompdf->loadHtml($html);
$dompdf->render();
// file_put_contents('Fichier.pdf', $dompdf->output());
// ob_end_clean();
return new Response(
$dompdf->output(["Attachment" => false]),
Response::HTTP_OK,
['Content-Type' => 'application/pdf']
);
}
private function imageToBase64($pathfile)
{
$path = $pathfile;
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
return $base64;
}
}
Informations
Cet extrait a été créé le 30 sept. 2024 à 11:49:35
Cet extrait expire le 30 oct. 2024 à 11:49:35
Langage : php
Link
Voici votre URL de partage : https://sharemycode.io/c/36d2fe4 Copié