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()
SDK coming soon. In the meantime, use the HTTP example below — it works with any HTTP client.
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)
}
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.
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);
- 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";
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.
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);
- 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";