webkit-pdf-snap
Zero-CGo (CGO_ENABLED=0), zero-TCC headless HTML/CSS/SVG → vector PDF & PNG snapshot pipeline with PDFKit inspection and Vision OCR round-trip verification — no Chrome or Playwright binary required.
What It Does
- Boots a headless
NSApplication (NSApplicationActivationPolicyProhibited) with an offscreen WKWebView.
- Renders an inline HTML+CSS+SVG card by default (offline), or a
-html file / -url.
- Exports a vector PDF (
CreatePDFWithConfigurationCompletionHandler) and inspects page/text counts via PDFKit.
- Captures a PNG snapshot (
TakeSnapshotWithConfigurationCompletionHandler) and runs VNRecognizeTextRequest OCR on the rendered pixels to verify round-trip text fidelity.
Usage
# Zero-friction offline run on built-in HTML+SVG card:
CGO_ENABLED=0 go run ./examples/webkit/webkit-pdf-snap
# Render a local HTML file or URL:
CGO_ENABLED=0 go run ./examples/webkit/webkit-pdf-snap -html card.html -pdf out.pdf -png snap.png
CGO_ENABLED=0 go run ./examples/webkit/webkit-pdf-snap -url https://example.com -width 1024 -height 768
Flags:
-url — URL to render (default: built-in HTML+SVG card)
-html — local HTML file to render
-pdf — output PDF path (default: temp dir)
-png — output PNG snapshot path (default: temp dir)
-width, -height — viewport dimensions in points (default 760 × 360)
Sample Output
Source: inline HTML+SVG card (760x360, 17.679s)
PDF: /var/folders/.../render.pdf (17505 bytes, 1 page(s), 189 text chars via PDFKit)
PNG: /var/folders/.../snapshot.png (39707 bytes, 760x360)
OCR: 7 lines recognized -> "ZERO-CGO MACOS | WebKit Headless PDF & Snapshot | Rendered offline via WKWebView, inspected with PDFKit, and verified by Vision OCR. | Vector PDF | WKPDFConfiguration | Vision OCR | Round-Trip Verified"