# How I Built a Secure LaTeX-to-PDF Service for Cloudflare Workers

DevFeed: [How I Built a Secure LaTeX-to-PDF Service for Cloudflare Workers](<https://devfeed.tech/articles/how-i-built-a-secure-latex-to-pdf-service-for-cloudflare-workers-92540.md>)

Original publisher: [Read original article](<https://hackernoon.com/how-i-built-a-secure-latex-to-pdf-service-for-cloudflare-workers?source=rss>)

Author: Bhargav Venkatesh Babu

Published: 2026-10-21T08:05:50Z

Content type: tutorial

Language: en

Sources: [HackerNoon](<https://devfeed.tech/sources/hackernoon.md>)

Topics: [Cloudflare Workers](<https://devfeed.tech/topics/cloudflare-workers.md>), [LaTeX](<https://devfeed.tech/topics/latex.md>), [pdf](<https://devfeed.tech/topics/pdf.md>), [Cloudflare](<https://devfeed.tech/topics/cloudflare.md>)

Tags: [agent](<https://devfeed.tech/tags/agent.md>), [alert](<https://devfeed.tech/tags/alert.md>), [api](<https://devfeed.tech/tags/api.md>), [apt-cache](<https://devfeed.tech/tags/apt-cache.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [assets](<https://devfeed.tech/tags/assets.md>), [atomic](<https://devfeed.tech/tags/atomic.md>), [authentication](<https://devfeed.tech/tags/authentication.md>), [aux](<https://devfeed.tech/tags/aux.md>), [await](<https://devfeed.tech/tags/await.md>), [awk](<https://devfeed.tech/tags/awk.md>), [cloud-run](<https://devfeed.tech/tags/cloud-run.md>), [cloudflare](<https://devfeed.tech/tags/cloudflare.md>), [cloudflare-workers](<https://devfeed.tech/tags/cloudflare-workers.md>), [cloudflare-workers-pdf](<https://devfeed.tech/tags/cloudflare-workers-pdf.md>), [docker](<https://devfeed.tech/tags/docker.md>), [google-cloud-run](<https://devfeed.tech/tags/google-cloud-run.md>), [latex](<https://devfeed.tech/tags/latex.md>), [latex-compilation](<https://devfeed.tech/tags/latex-compilation.md>), [latex-security](<https://devfeed.tech/tags/latex-security.md>), [pdf](<https://devfeed.tech/tags/pdf.md>), [security](<https://devfeed.tech/tags/security.md>), [serverless-architecture](<https://devfeed.tech/tags/serverless-architecture.md>), [serverless-pdf-generation](<https://devfeed.tech/tags/serverless-pdf-generation.md>), [service](<https://devfeed.tech/tags/service.md>), [workers](<https://devfeed.tech/tags/workers.md>)

## AI overview

Cloudflare Workers cannot run native TeX binaries, so the service sends LaTeX over HTTP to a container running Tectonic on Cloud Run. The Hono service gives each compile a fresh temporary directory, validates sibling file paths, runs Tectonic with shell escape disabled and `--untrusted`, and returns PDF bytes or compiler logs. Because TeX can still read files, the compiler receives a clean environment; the service token is supplied on stdin, and startup fails if the token is missing. The author chose a shared bearer token over Cloud Run identity tokens to keep the service portable, accepting that unauthorized requests still reach the container. Deployment exposed linked-library and glibc requirements, while a swallowed Docker warm-up error left Tectonic's cache empty and caused a trivial compile to time out. Checking cache size during the build caught the issue; with a 45 MB cache, reported warm compiles take about three seconds. Cold-start latency remains unmeasured, and the service has no queue or rate limit.

## Source excerpt

Learn how to generate PDFs from Cloudflare Workers using Tectonic and Cloud Run, with practical lessons on Docker, security, and deployment.