From 4f6659c8c97749167bf62372fef41ca53f1bcbb1 Mon Sep 17 00:00:00 2001 From: Hoid Date: Thu, 5 Mar 2026 14:06:27 +0100 Subject: [PATCH] fix: replace fake Go/PHP SDK examples with plain HTTP examples - 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 --- public/examples.html | 68 +++++++++++++++++++++------------------- public/src/examples.html | 37 ++++++++++------------ 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/public/examples.html b/public/examples.html index 2445c09..9f257eb 100644 --- a/public/examples.html +++ b/public/examples.html @@ -345,25 +345,32 @@ response.raise_for_status()

Go Integration

SDK coming soon. In the meantime, use the HTTP example below — it works with any HTTP client.

- Go — Using the SDK + Go — generate-pdf.go
package main
 
 import (
+    "bytes"
+    "encoding/json"
+    "io"
+    "net/http"
     "os"
-    docfast "github.com/docfast/docfast-go"
 )
 
-func main() {
-    client := docfast.New("df_pro_your_api_key")
-
-    pdf, err := client.HTML("<h1>Hello</h1><p>Generated with DocFast</p>", &docfast.PDFOptions{
-        Format: "A4",
-        Margin: &docfast.Margin{Top: "20mm", Bottom: "20mm"},
+func main() {
+    body, _ := json.Marshal(map[string]string{
+        "html": "<h1>Hello</h1><p>Generated with DocFast</p>",
     })
-    if err != nil {
-        panic(err)
-    }
-    os.WriteFile("output.pdf", pdf, 0644)
+
+    req, _ := http.NewRequest("POST", "https://docfast.dev/v1/convert/html", bytes.NewReader(body))
+    req.Header.Set("Authorization", "Bearer "+os.Getenv("DOCFAST_API_KEY"))
+    req.Header.Set("Content-Type", "application/json")
+
+    resp, err := http.DefaultClient.Do(req)
+    if err != nil { panic(err) }
+    defer resp.Body.Close()
+
+    pdf, _ := io.ReadAll(resp.Body)
+    os.WriteFile("output.pdf", pdf, 0644)
 }
@@ -371,29 +378,26 @@ response.raise_for_status()

PHP Integration

-

SDK coming soon. In the meantime, use the HTTP example below — it works with any HTTP client.

+

SDK coming soon. In the meantime, use the HTTP example below — it works with any HTTP client. Laravel: Use this in any controller or Artisan command.

- PHP — Using the SDK -
use DocFast\Client;
-use DocFast\PdfOptions;
+        PHP — generate-pdf.php
+        
<?php
+$html = '<h1>Hello</h1><p>Generated with DocFast</p>';
 
-$client = new Client('df_pro_your_api_key');
+$options = [
+    'http' => [
+        'method'  => 'POST',
+        'header'  => implode("\r\n", [
+            'Authorization: Bearer ' . getenv('DOCFAST_API_KEY'),
+            'Content-Type: application/json',
+        ]),
+        'content' => json_encode(['html' => $html]),
+    ],
+];
 
-$options = new PdfOptions();
-$options->format = 'A4';
-$options->margin = ['top' => '20mm', 'bottom' => '20mm'];
-
-$pdf = $client->html('<h1>Hello</h1><p>Generated with DocFast</p>', null, $options);
-file_put_contents('output.pdf', $pdf);
-
-
- Laravel — Using the Facade -
use DocFast\Laravel\Facades\DocFast;
-
-// In your controller
-$pdf = DocFast::html(view('invoice')->render());
-return response($pdf)
-    ->header('Content-Type', 'application/pdf');
+$pdf = file_get_contents('https://docfast.dev/v1/convert/html', false, stream_context_create($options)); +file_put_contents('output.pdf', $pdf); +echo "✓ Saved output.pdf\n";
diff --git a/public/src/examples.html b/public/src/examples.html index 28f1eac..b9a8699 100644 --- a/public/src/examples.html +++ b/public/src/examples.html @@ -327,29 +327,26 @@ response.raise_for_status()

PHP Integration

-

SDK coming soon. In the meantime, use the HTTP example below — it works with any HTTP client.

+

SDK coming soon. In the meantime, use the HTTP example below — it works with any HTTP client. Laravel: Use this in any controller or Artisan command.

- PHP — Using the SDK -
use DocFast\Client;
-use DocFast\PdfOptions;
+        PHP — generate-pdf.php
+        
<?php
+$html = '<h1>Hello</h1><p>Generated with DocFast</p>';
 
-$client = new Client('df_pro_your_api_key');
+$options = [
+    'http' => [
+        'method'  => 'POST',
+        'header'  => implode("\r\n", [
+            'Authorization: Bearer ' . getenv('DOCFAST_API_KEY'),
+            'Content-Type: application/json',
+        ]),
+        'content' => json_encode(['html' => $html]),
+    ],
+];
 
-$options = new PdfOptions();
-$options->format = 'A4';
-$options->margin = ['top' => '20mm', 'bottom' => '20mm'];
-
-$pdf = $client->html('<h1>Hello</h1><p>Generated with DocFast</p>', null, $options);
-file_put_contents('output.pdf', $pdf);
-
-
- Laravel — Using the Facade -
use DocFast\Laravel\Facades\DocFast;
-
-// In your controller
-$pdf = DocFast::html(view('invoice')->render());
-return response($pdf)
-    ->header('Content-Type', 'application/pdf');
+$pdf = file_get_contents('https://docfast.dev/v1/convert/html', false, stream_context_create($options)); +file_put_contents('output.pdf', $pdf); +echo "✓ Saved output.pdf\n";