renderForSigning($version, $signatureDate, $signingSubject, $counterpartyName)['bytes']; } public function renderForSigning(CourierQuoteVersion $version, ?string $signatureDate = null, ?string $signingSubject = null, ?string $counterpartyName = null): array { $data = $this->confirmation->data($version, $signingSubject, $counterpartyName); $signatureDate = Carbon::parse($signatureDate ?: now())->format('Y年n月j日'); $html = view('business.pdf.courier-quote', [ 'version' => $version, 'change' => $version->change, 'values' => $data['values'], 'formulas' => $data['formulas'], 'partyA' => $data['party_a'], 'partyB' => $data['party_b'], 'expiryDate' => $data['expiry_date'], 'temporaryNote' => $data['temporary_note'] ?? null, 'billingRules' => $data['billing_rules'], 'faceFee' => $data['face_fee'], 'bubbleCoefficient' => $data['bubble_coefficient'], 'signatureDate' => $signatureDate, 'generatedAt' => now(), 'fontPath' => str_replace('\\', '/', resource_path('fonts/DroidSansFallback.ttf')), ])->render(); $pdf = app('dompdf.wrapper'); $pdf->setPaper('a4', 'landscape'); $pdf->loadHTML($html, 'UTF-8'); $result = PdfSigningPositions::render($pdf, 'data-counterparty-signature', 'b'); $bytes = $result['bytes']; if (! is_string($bytes) || ! str_starts_with($bytes, '%PDF-')) { throw new RuntimeException('报价 PDF 生成失败。'); } if (count($result['signing_positions']) !== 1) { throw new RuntimeException('未能定位报价确认单乙方正文签章区,未生成待签文件。'); } return $result; } }