From 2342a9940541723290156423ae370f6eb56119aa Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Fri, 3 Apr 2026 15:24:36 +0000 Subject: [PATCH] Save experiment in postgred integration --- .gitignore | 1 + postgrid/cmd/send-pdf/main.go | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 postgrid/cmd/send-pdf/main.go diff --git a/.gitignore b/.gitignore index bae0fbff..71323113 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ flogo.log nidus-sync nidus-sync.log node_modules/ +postgrid/cmd/send-pdf/send-pdf result stadia/cmd/bulk-geocode/bulk-geocode stadia/cmd/reverse-geocode/reverse-geocode diff --git a/postgrid/cmd/send-pdf/main.go b/postgrid/cmd/send-pdf/main.go new file mode 100644 index 00000000..c056c4f3 --- /dev/null +++ b/postgrid/cmd/send-pdf/main.go @@ -0,0 +1,45 @@ +// Command pdf is a chromedp example demonstrating how to capture a pdf of a +// page. +package main + +import ( + "context" + "fmt" + "log" + "os" + + "github.com/chromedp/cdproto/page" + "github.com/chromedp/chromedp" +) + +func main() { + // create context + ctx, cancel := chromedp.NewContext(context.Background()) + defer cancel() + + // capture pdf + var buf []byte + if err := chromedp.Run(ctx, printToPDF(`https://www.google.com/`, &buf)); err != nil { + log.Fatal(err) + } + + if err := os.WriteFile("sample.pdf", buf, 0o644); err != nil { + log.Fatal(err) + } + fmt.Println("wrote sample.pdf") +} + +// print a specific pdf page. +func printToPDF(urlstr string, res *[]byte) chromedp.Tasks { + return chromedp.Tasks{ + chromedp.Navigate(urlstr), + chromedp.ActionFunc(func(ctx context.Context) error { + buf, _, err := page.PrintToPDF().WithPrintBackground(false).Do(ctx) + if err != nil { + return err + } + *res = buf + return nil + }), + } +}