What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
To generate a PDF in Go with wkhtmltopdf, install the wkhtmltopdf executable on the same host or container as your Go program, then launch it with os/exec. Go supplies the input URL or HTML file and output PDF path as separate arguments; wkhtmltopdf performs the HTML rendering. A context, captured stderr, explicit timeout, and cleanup of failed output make the small wrapper suitable for a service.
The wkhtmltopdf downloads page identifies version 0.12.6, released June 11, 2020, as its stable series. That is a page-reported release status, not a claim that the project is recently maintained. Verify the binary and package instructions for your target operating system before deployment.
What the Go wrapper actually does
Your Go application is not a PDF renderer in this design. It starts an installed command-line process:
- Validate or create the HTML input and destination paths.
- Call
wkhtmltopdfwith discrete arguments. - Wait for the process to finish, or cancel it through a context.
- Inspect the exit error and stderr.
- Keep the PDF only after a successful exit and an output-file check.
The basic command accepts a URL or local HTML path followed by an output PDF path. Because os/exec does not invoke a shell, shell metacharacters, pipes, redirection, and shell quoting are not interpreted. Do not concatenate user input into a shell command string.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →#1 Best Overall
- INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
- LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
- COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
- ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
- HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs
Install and verify wkhtmltopdf first
Install in the runtime environment
Install a compatible package or binary in the machine, container image, or serverless runtime that executes the Go process. A binary on your development laptop is irrelevant if production runs in a different image. Put the executable on PATH, or pass its absolute path in your wrapper configuration.
The official downloads page lists operating-system, distribution, and architecture packages. It also notes that so-called static builds can still depend on system libraries, runtime font configuration, and installed fonts. Do not assume that a generic Linux build works across libc environments such as Alpine. Match the build to the base image and test it inside that image.
Check the binary and rendering prerequisites
wkhtmltopdf --version
wkhtmltopdf -H
The first command records the executable version. The second prints the help generated by the installed binary; use it to confirm that an option is available in the exact build you deploy. Check that fontconfig and the fonts required by your documents exist in the same environment. Missing fonts commonly change line wrapping, pagination, and glyphs without causing a process error.
Container and deployment checklist
- Record the operating-system and libc version.
- Install the matching wkhtmltopdf package and its dependent libraries.
- Install the fonts used by your templates, including non-Latin fonts when applicable.
- Run a representative conversion during image validation, not only
--version. - Keep the executable path configurable so a package upgrade does not require a code change.
- Do not rely on dated Amazon Linux 2 Lambda packaging notes without independently verifying them for your runtime.
A production-minded Go implementation
Minimal URL or file conversion
package pdfconv
import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
)
func RenderPDF(ctx context.Context, inputHTML, outputPDF string) error {
cmd := exec.CommandContext(ctx, "wkhtmltopdf", inputHTML, outputPDF)
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("wkhtmltopdf failed: %w (stderr: %s)", err, stderr.String())
}
if _, err := os.Stat(outputPDF); err != nil {
return fmt.Errorf("wkhtmltopdf reported success but output is unavailable: %w", err)
}
return nil
}
Call it with a URL such as https://example.com/report or with a local file path accepted by your installed build. The code passes each argument separately and captures diagnostics. The snippet is an implementation pattern; adapt path validation, logging, and error policy to your application.
Use an explicit executable path and timeout
func RenderWithTimeout(inputHTML, outputPDF, binary string) error {
ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, binary, inputHTML, outputPDF)
var stderr bytes.Buffer
cmd.Stderr = &stderr
err := cmd.Run()
if ctx.Err() != nil {
removePartial(outputPDF)
return fmt.Errorf("wkhtmltopdf timed out or was canceled: %w", ctx.Err())
}
if err != nil {
removePartial(outputPDF)
return fmt.Errorf("wkhtmltopdf failed: %w (stderr: %s)", err, stderr.String())
}
return nil
}
func removePartial(path string) {
_ = os.Remove(path)
}
Import time for this variant. CommandContext terminates the child when the context is canceled, but your service still needs a policy for partial files, queued jobs, and any descendants left by an unusual process failure. Use a per-job temporary directory and rename a completed PDF into its final location only after successful validation.
Rank #2
- CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
- INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
- LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
- PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
- ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴
Safer output handling
- Resolve input and output paths against an allowed directory rather than accepting arbitrary filesystem locations.
- Use unique temporary names to prevent two requests from writing the same PDF.
- Remove a partial output after nonzero exit, timeout, or cancellation.
- Check file size and, if required, open the result to verify it begins as a PDF before publishing it.
- Log stderr with request identifiers, but redact URLs, cookies, authorization values, or HTML that may contain secrets.
Rendering options you will commonly need
Option spelling and availability vary by build, so confirm them with the installed binary’s wkhtmltopdf -H. The project settings documentation covers the following controls:
| Need | Controls to evaluate | What to test |
|---|---|---|
| Paper and orientation | Page size, custom width/height, portrait or landscape | Page breaks, wide tables, and printer margins |
| Margins and color | Margin settings and color mode | Header overlap, clipped backgrounds, and grayscale output |
| Images | Image loading and image-related settings | Remote images, large assets, and missing resources |
| JavaScript pages | JavaScript enablement and JavaScript delay | Charts, data fetched after load, fonts, and lazy content |
| Headers and footers | Header/footer text or HTML | Page numbers, long titles, and collisions with body content |
| Output | Destination path and related output settings | Writable directories and atomic publication |
For a dynamic page, initial network completion does not prove that the application has finished rendering. Set a deliberate JavaScript delay where supported, and test readiness, fonts, images, and pagination with realistic data. Rendering can differ between operating systems and package builds; treat each target image as a separate rendering environment.
Handling errors and diagnostics
Executable not found
An error such as “executable file not found” means the binary is absent from PATH in the process environment. Install it in the runtime image, configure an absolute path, and print the configured path and wkhtmltopdf --version during deployment diagnostics.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesNonzero exit status
Preserve stderr. It may identify an invalid URL, an unreadable local file, a failed resource, an unsupported option, or a runtime library problem. Return a wrapped error to the caller while keeping sensitive diagnostics out of public responses.
Timeout or cancellation
Slow JavaScript, unreachable resources, stalled network requests, or a very large document can exceed a request deadline. Use CommandContext, remove partial output, and record whether the context expired. Do not retry indefinitely: bound retries and consider a job queue for expensive documents.
Rank #3
- SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
- INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
- KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
- PREMIUM SUPPORT - Strong technical expertise to solve issues faster
- THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
Blank or incomplete PDF
Check that the input is reachable from the conversion host, that local-file access policy permits the resources you use, and that scripts have enough time to finish. Confirm image URLs, web fonts, and CSS paths from inside the runtime environment. Compare a reduced HTML case with the full document to isolate the failing asset or script.
Different layout in production
Compare the wkhtmltopdf version, operating-system libraries, font files, locale, and input bytes between environments. A “static” package may still use system libraries and font configuration. Capture those details with a reproducible HTML/CSS/JavaScript case when requesting project support.
Concurrency, performance, and reliability
Process isolation and limits
Each conversion is an external process with CPU, memory, file, and network consumption. Limit concurrent jobs with a semaphore or worker pool. Apply request size limits, maximum page counts appropriate to your workload, wall-clock deadlines, and temporary-directory quotas. Keep the service user unable to write outside its working directories.
Network behavior and reproducibility
Remote pages make output dependent on DNS, TLS, third-party assets, login state, and changing content. Prefer self-contained HTML and locally controlled assets for invoices and archival records. If remote resources are necessary, set a controlled network policy and log the source document version or identifier.
Caching and idempotency
Use a deterministic document identifier and write to a temporary path before an atomic rename. A cache can avoid repeated rendering, but invalidate it when template, data, fonts, or renderer versions change. Never let two requests overwrite one another’s output.
Rank #4
- Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
- No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
- Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
- Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
- The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art
Security: treat conversion as untrusted execution
The project status guidance warns: “Do not use wkhtmltopdf with any untrusted HTML – be sure to sanitize any user-supplied HTML/JS, otherwise it can lead to complete takeover of the server on which it is running!” Sanitization alone is not a complete boundary. Treat the renderer as a legacy browser engine with filesystem and network implications.
- Accept only sanitized, allowlisted HTML and CSS when users supply content.
- Run the process as a dedicated least-privilege account.
- Use a disposable container or sandbox with a read-only root filesystem where practical.
- Restrict outbound network access and block access to metadata services and internal administration endpoints.
- Apply operating-system controls such as AppArmor or SELinux where available.
- Limit CPU, memory, process count, open files, and conversion duration.
- Do not place secrets in query strings or HTML visible to the renderer.
The status page also points to Puppeteer for sites that depend heavily on dynamic JavaScript, and names WeasyPrint and commercial Prince as alternatives for reports controlled by your application. These are options to evaluate, not a current head-to-head ranking. Compare HTML/CSS/JavaScript fidelity, browser-engine maintenance, security posture, runtime footprint and fonts, Go integration, and licensing for your workload.
Or skip the browser setup
If your requirement is simply a reliable URL-to-image or URL-to-PDF capture rather than a local wkhtmltopdf process, ScreenshotNeo provides a website screenshot API and MCP server. A single GET request returns a PNG, JPEG, WebP, or PDF; it handles the browser environment for you.
cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
See the ScreenshotNeo API documentation for output and capture options. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.
Final implementation checklist
- Install and verify wkhtmltopdf inside the production runtime.
- Pass URL, input path, and output path as separate
exec.CommandContextarguments. - Capture stderr and wrap process errors with safe context.
- Set deadlines, concurrency limits, and cleanup for partial files.
- Test paper settings, JavaScript readiness, fonts, images, headers, and footers on every target image.
- Sanitize untrusted HTML and isolate the renderer with least privilege and network controls.
- Record the deployed binary version and environment for reproducible troubleshooting.
Frequently Asked Questions
Can Go render HTML to PDF without installing wkhtmltopdf?
Not with this wrapper approach. Go launches wkhtmltopdf as an external executable, so the renderer and its runtime dependencies must be installed wherever the Go process runs. A different renderer or hosted capture API is required if you do not want to deploy a local binary.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Should I pass a complete shell command to exec.Command?
No. Pass the executable name and each argument as separate values. os/exec does not invoke a shell, and avoiding shell-built command strings prevents quoting mistakes and reduces injection risk.
Why does a PDF differ between two Linux containers?
The wkhtmltopdf build, libc and other libraries, fontconfig configuration, installed fonts, locale, and input resources may differ. Compare those items and reproduce the same HTML/CSS/JavaScript case in both environments.
Is wkhtmltopdf suitable for arbitrary user HTML?
No. The project explicitly warns against using it with untrusted HTML or JavaScript. Sanitize input and run conversions in a strongly isolated, least-privilege environment with resource and network limits.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Recommended Free Tools

