
How to take screenshots and generate PDFs in Go
How to Take Screenshots and Generate PDFs in Go Go has no headless browser library. When Go services need to capture screenshots or generate PDFs, the usual approaches are: shell out to Chrome, run a sidecar Python process, or reach for a cgo-wrapped browser binding. All of these add operational complexity to what should be a simple output. Here's the clean approach: one HTTP POST, binary response, standard library. Screenshot from a URL package main import ( "bytes" "encoding/json" "io" "net/http" "os" ) func Screenshot ( url string ) ([] byte , error ) { payload , _ := json . Marshal ( map [ string ] interface {}{ "url" : url , "fullPage" : true , "blockBanners" : true , }) req , _ := http . NewRequest ( "POST" , "https://pagebolt.dev/api/v1/screenshot" , bytes . NewBuffer ( payload )) req . Header . Set ( "x-api-key" , os . Getenv ( "PAGEBOLT_API_KEY" )) req . Header . Set ( "Content-Type" , "application/json" ) resp , err := http . DefaultClient . Do ( req ) if err != nil { return
Continue reading on Dev.to Webdev
Opens in a new tab



