public function sharePdf1($id) { // Fetch the quotation data based on the provided ID $quotation = Quotation::with('productDetails')->findOrFail($id); $productDetail =ProductDetail::where('invoice_id',$id)->with('product')->get(); // Generate the PDF for the quotation $pdf = $this->generatePdf($quotation); // dd($pdf); // Create the social share instance $socialShare = Share::page( route('quotation.show', ['id' => $quotation->id]), 'Share Quotation PDF' )->description('Check out this Quotation PDF'); // Pass the quotation, PDF, and social share buttons to the view return view('quotation.share', compact('quotation', 'pdf', 'socialShare','productDetail')); } // private function generatePdf($quotation) // { // // Load the invoice view and pass the invoice data // $productDetail =ProductDetail::where('invoice_id',$quotation->id)->with('product')->get(); // $html = view('invoice.pdf', compact('quotation','productDetail'))->render(); // // Configure Dompdf options // $options = new Options(); // $options->setIsRemoteEnabled(true); // // Instantiate Dompdf with the configured options // $dompdf = new Dompdf($options); // // Load the HTML content into Dompdf // $dompdf->loadHtml($html); // // (Optional) Set paper size and orientation // $dompdf->setPaper('A4', 'portrait'); // // Render the PDF content // $dompdf->render(); // // Return the generated PDF content // return $dompdf->output(); // } public function sharePdf2($id) { // Fetch the quotation data based on the provided ID $quotation = Quotation::with('productDetails')->findOrFail($id); $productDetail =ProductDetail::where('invoice_id',$quotation->id)->with('product')->get(); // Generate the PDF for the quotation $pdf = $this->generatePdf($quotation); // Pass the quotation and PDF to the view return view('quotation.share', compact('quotation', 'pdf','productDetail')); } public function sharePdf3($id) { // Fetch the quotation data based on the provided ID $quotation = Quotation::with('productDetails')->findOrFail($id); $productDetail = ProductDetail::where('invoice_id', $id)->with('product')->get(); // Generate the PDF for the quotation $pdfContent = $this->generatePdf($quotation); // Generate a unique file name for the PDF $fileName = 'quotation_' . $quotation->id . '.pdf'; // Define the directory path for storing the PDF file $directory = storage_path('app/public/temp/'); // Create the directory if it doesn't exist if (!is_dir($directory)) { mkdir($directory, 0755, true); } // Save the PDF file in the directory $path = $directory . $fileName; file_put_contents($path, $pdfContent); // Create the social share instance $socialShare = Share::page(asset('storage/temp/' . $fileName), 'Share Quotation PDF') ->setParameters(['text' => 'Check out this Quotation PDF']); // Pass the quotation, PDF, and social share buttons to the view return view('quotation.share', compact('quotation', 'socialShare', 'fileName', 'productDetail')); } public function sharePdf_important($id) { // Retrieve the necessary data for the PDF $quotation = Quotation::with('productDetails')->find($id); $productDetail =ProductDetail::where('invoice_id',$id)->with('product')->get(); // Generate the PDF file $pdfFilePath = $this->generatePdf($quotation,$productDetail); // Create the social share buttons $socialShare = new Share(); // Generate the social share buttons $socialShare->page(asset($pdfFilePath), 'Share Quotation PDF') ->whatsapp() ->facebook() ->linkedin() ->pinterest() ->twitter(); // Return the view with the social share buttons // return view('quotation.share', compact('socialShare')); // $socialShare = new Share(); // $socialShare->page( // asset($pdfFilePath), // 'Share Quotation PDF' // )->facebook()->whatsapp()->linkedin()->pinterest()->twitter(); return view('quotation.share', compact('socialShare','quotation','productDetail')); } public function generatePdf_important($quotation,$productDetail) { // Load the invoice view and pass the invoice data $html = view('invoice.pdf', compact('quotation','productDetail'))->render(); // Configure Dompdf options $options = new Options(); $options->setIsRemoteEnabled(true); // Instantiate Dompdf with the configured options $dompdf = new Dompdf($options); // Load the HTML content into Dompdf $dompdf->loadHtml($html); // (Optional) Set paper size and orientation $dompdf->setPaper('A4', 'portrait'); // Render the PDF content $dompdf->render(); // Save the generated PDF to a storage location $filePath = storage_path('app/public/temp/quotation_' . $quotation->id . '.pdf'); file_put_contents($filePath, $dompdf->output()); return $filePath; } public function sharePdf($id) { // Generate the PDF file $pdfFilePath = $this->generatePdf($id); // Get the file's content $pdfContent = Storage::disk('public')->get($pdfFilePath); // Set the appropriate headers for the PDF file $headers = [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="quotation.pdf"', ]; // Return the PDF file as a response return response($pdfContent, 200, $headers); } public function generatePdf($id) { // Retrieve the necessary data for the PDF $quotation = Quotation::findOrFail($id); $productDetails = ProductDetail::where('invoice_id', $id)->get(); // Generate the PDF using Dompdf or another library $pdf = new Dompdf(); $pdf->loadView('invoice.pdf', compact('quotation', 'productDetails')); $pdf->render(); // Save the generated PDF to a storage location $filePath = 'temp/quotation_' . $id . '.pdf'; Storage::disk('public')->put($filePath, $pdf->output()); return $filePath; }