PrintBase
  • Product
  • Pricing
  • Docs
  • Resources
PrintBase/Guides/Print from your language or framework

Print a PDF from Go

Read a PDF in Go and post it as base64. Use content_url if the object store link is public. No CGO PDF library is required to transport the file.

For Go services that already produce PDFs

Overview

Generating a PDF in Go (or writing one from another service) is separate from printing it. Once you have []byte starting with %PDF-, base64 it and set content_type pdf. Sending those bytes as raw fails validation.

An S3 or similar presigned URL can be content_url if the agent can GET it before it expires. A URL that only works inside your VPC will fail with DOWNLOAD_FAILED.

Check the status code. 201 with a JSON id is success to queue. 4xx is a body you should log, without logging the PDF.

Create the job with POST /v1/print-jobs, an Authorization: Bearer header, printer_code, content_type pdf or raw, and exactly one of content or content_url. The free plan is 100 jobs a month on one computer.

Integration steps

  1. 01

    Create an API key on the server

    Use an API key (pb_live_…) in the process environment. Authorization is Bearer. Do not ship the key to browsers or mobile apps.

  2. 02

    Install the agent beside the printer

    Windows, macOS, or Linux. GET /v1/printers and keep the numeric code.

  3. 03

    POST /v1/print-jobs

    content_type is pdf or raw. Send exactly one of content (standard base64) or content_url.

  4. 04

    Reuse the idempotency key on retry

    A new key means a second physical print. HTTP 409 means the same key was reused with a different body.

  5. 05

    Read the job before you tell the user

    GET /v1/print-jobs/{id}. Paid plans can also receive print_job.completed and print_job.failed webhooks.

Go

// Go PDF
body, _ := json.Marshal(map[string]any{
    "printer_code": printerCode,
    "content_type": "pdf",
    "content": base64.StdEncoding.EncodeToString(pdfBytes),,
    "copies": 1,
})
req, _ := http.NewRequest(http.MethodPost, "https://api.printbase.cloud/v1/print-jobs", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("PRINTBASE_API_KEY"))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", idempotencyKey)
res, err := http.DefaultClient.Do(req)
if err != nil { log.Fatal(err) }
defer res.Body.Close()
// 201 {"id":"job_abc","status":"queued"}

Details for this setup

Do not log the body

The PDF is customer data. Log the job id and the status code only. The agent prints only what you send; it does not fetch the document from the platform for you.

Presign long enough

The agent downloads after the job is dispatched. A URL that expires in one second is DOWNLOAD_FAILED.

Questions

Which PDF library?

Whichever produces bytes. The print call does not import it.

pdfcpu or jung-kurt?

Fine for generation. Not involved in the HTTP call. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.

Can Go print on Windows without an agent?

Only with Windows APIs on that machine. This page is the remote case.

Copies? in this setup

The copies field. The PDF itself should be one document. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.

Related guides

  • Print raw ZPL from Go

    Go's net/http posts ZPL with no extra module. Base64 from encoding/base64. The agent prints the Zebra queue.

  • Print a PDF from Node.js to a printer in another place

    From Node.js, base64 a PDF and POST it to the print-jobs API. The printer is attached to a computer running the agent, not to your server.

  • Print a PDF from Python

    Use the Python standard library to POST a base64 PDF. No extra print package is required. The agent prints it on the computer you chose.

  • Print a PDF from Flask

    Flask can post a PDF with urllib in the request that generates it. Keep the API key in the environment. There is no Flask extension to install.

Free plan: 100 jobs a month on one computer, no card.

Create a free accountRead the API docs
PrintBase

PrintBase connects your applications to physical printers anywhere - securely, reliably, and in real time.

Product
Receipt PrintingLabel PrintingDashboardDevicesWebhooks
Resources
DocsBlogStatusAPI ReferenceDownloadPrintBase vs PrintNodePrintNode PricingFAQ
Guides
All guidesIntegrationsPrintersCode samplesComparisonsUse casesTroubleshooting
Company
ContactSecurityPrivacy

© 2026 Aveniq Technologies OÜ. All rights reserved. PrintBase is a service of Aveniq Technologies OÜ.

PrivacyTermsRefunds