fix: replace fake Go/PHP SDK examples with plain HTTP examples
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
- Go: replaced non-existent docfast-go SDK with net/http example - PHP: replaced non-existent DocFast\Client SDK with file_get_contents example - Removed fake Laravel facade example, added note instead - Updated code labels to 'generate-pdf.go' and 'generate-pdf.php' - Added test to prevent regression
This commit is contained in:
parent
c82e00f18b
commit
4f6659c8c9
2 changed files with 53 additions and 52 deletions
|
|
@ -327,29 +327,26 @@ response.<span class="fn">raise_for_status</span>()
|
|||
<!-- PHP -->
|
||||
<section id="php" class="example-section">
|
||||
<h2>PHP Integration</h2>
|
||||
<p><strong>SDK coming soon.</strong> In the meantime, use the HTTP example below — it works with any HTTP client.</p>
|
||||
<p><strong>SDK coming soon.</strong> In the meantime, use the HTTP example below — it works with any HTTP client. Laravel: Use this in any controller or Artisan command.</p>
|
||||
<div class="code-block">
|
||||
<span class="code-label">PHP — Using the SDK</span>
|
||||
<pre><code><span class="kw">use</span> DocFast\Client;
|
||||
<span class="kw">use</span> DocFast\PdfOptions;
|
||||
<span class="code-label">PHP — generate-pdf.php</span>
|
||||
<pre><code><span class="kw"><?php</span>
|
||||
$html = <span class="str">'<h1>Hello</h1><p>Generated with DocFast</p>'</span>;
|
||||
|
||||
$client = <span class="kw">new</span> Client(<span class="str">'df_pro_your_api_key'</span>);
|
||||
$options = [
|
||||
<span class="str">'http'</span> => [
|
||||
<span class="str">'method'</span> => <span class="str">'POST'</span>,
|
||||
<span class="str">'header'</span> => <span class="fn">implode</span>(<span class="str">"\r\n"</span>, [
|
||||
<span class="str">'Authorization: Bearer '</span> . <span class="fn">getenv</span>(<span class="str">'DOCFAST_API_KEY'</span>),
|
||||
<span class="str">'Content-Type: application/json'</span>,
|
||||
]),
|
||||
<span class="str">'content'</span> => <span class="fn">json_encode</span>([<span class="str">'html'</span> => $html]),
|
||||
],
|
||||
];
|
||||
|
||||
$options = <span class="kw">new</span> PdfOptions();
|
||||
$options->format = <span class="str">'A4'</span>;
|
||||
$options->margin = [<span class="str">'top'</span> => <span class="str">'20mm'</span>, <span class="str">'bottom'</span> => <span class="str">'20mm'</span>];
|
||||
|
||||
$pdf = $client->html(<span class="str">'<h1>Hello</h1><p>Generated with DocFast</p>'</span>, <span class="kw">null</span>, $options);
|
||||
file_put_contents(<span class="str">'output.pdf'</span>, $pdf);</code></pre>
|
||||
</div>
|
||||
<div class="code-block">
|
||||
<span class="code-label">Laravel — Using the Facade</span>
|
||||
<pre><code><span class="kw">use</span> DocFast\Laravel\Facades\DocFast;
|
||||
|
||||
<span class="cmt">// In your controller</span>
|
||||
$pdf = DocFast::html(view(<span class="str">'invoice'</span>)->render());
|
||||
<span class="kw">return</span> response($pdf)
|
||||
->header(<span class="str">'Content-Type'</span>, <span class="str">'application/pdf'</span>);</code></pre>
|
||||
$pdf = <span class="fn">file_get_contents</span>(<span class="str">'https://docfast.dev/v1/convert/html'</span>, <span class="kw">false</span>, <span class="fn">stream_context_create</span>($options));
|
||||
<span class="fn">file_put_contents</span>(<span class="str">'output.pdf'</span>, $pdf);
|
||||
<span class="kw">echo</span> <span class="str">"✓ Saved output.pdf\n"</span>;</code></pre>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue