Skip to main content

Quick Start for Go

Go

Go offers libraries for programmatic PDF creation and for browser automation, but they often require additional dependencies or complex integration. PDFBolt's PDF generation API provides an efficient solution for generating PDFs from HTML, URLs, and dynamic templates that works seamlessly with Go.

1. Get Your API Key

  • After signing up, locate your API Key in the Admin Dashboard under the API Keys section.
  • This key is essential for authorizing your requests to the PDFBolt API. Remember to keep it secure.

2. Make Your First Request

Get started with these examples to send requests to the PDFBolt API and generate PDFs instantly.

Choose your preferred endpoint and source combination.

➡️ Endpoints:

The Direct endpoint provides immediate PDF generation and returns the raw PDF file in the response.


➡️ Sources:

Convert any webpage into a PDF:

package main

import (
"bytes"
"fmt"
"io"
"net/http"
"os"
)

func main() {
jsonBody := `{
"url": "https://example.com",
"format": "A4",
"printBackground": true
}`

req, _ := http.NewRequest("POST", "https://api.pdfbolt.com/v1/direct", bytes.NewBufferString(jsonBody))
req.Header.Add("API-KEY", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
req.Header.Add("Content-Type", "application/json")

resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
fmt.Printf("HTTP %d\n", resp.StatusCode)
body, _ := io.ReadAll(resp.Body)
fmt.Printf("Error Message: %s\n", string(body))
return
}

file, _ := os.Create("webpage.pdf")
defer file.Close()

io.Copy(file, resp.Body)
fmt.Println("PDF generated successfully")
}

3. What's next?

Explore how PDFBolt can streamline your Go applications. Start with the API Endpoints and dive into the Conversion Parameters to customize your integration for your specific requirements.