惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
M
MIT News - Artificial intelligence
D
Docker
S
SegmentFault 最新的问题
B
Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
C
Check Point Blog
GbyAI
GbyAI
美团技术团队
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
PdfKmp 1.0 — A Kotlin Multiplatform PDF Library for Andro...
Nurmuhammad · 2026-05-16 · via DEV Community

Nurmuhammad

Built specifically for Kotlin Multiplatform

PdfKmp is a KMP-first library. The DSL, the layout engine, and the document model all live in commonMain. Rendering dispatches to each OS's native PDF stack — android.graphics.pdf.PdfDocument on Android, UIGraphicsBeginPDFContextToData + Core Graphics on iOS. You write the document once and ship it to both stores.

If you only target Android, you can still use it as a plain Android library (pdfkmp-android artifact).


What's in the box

Document structure

  • A Compose-style DSL: pdf { … }, page { … }, column, row, box, card
  • Spacing, padding, weighted children, alignment
  • Multi-page documents with automatic pagination

Text rendering

  • Vector glyph paths — every character is a real PDF text operator, not a bitmap
  • Single-style text(...) blocks and multi-style richText { span(...) } runs
  • Font weights, italics, underline, strikethrough, letter spacing, line height, alignment

Tables

  • Column weights and per-cell styling
  • Header rows that repeat on every page
  • Automatic page-break across long tables — no orphan rows

Decorations

  • Backgrounds, rounded corners, borders, gradients
  • Dividers, lines, circles, ellipses
  • Bullet and numbered lists

Page-level features

  • Headers and footers with access to current page number and total page count
  • Watermarks
  • Page numbers in any format you write

Hyperlinks

  • link(url) { … } emits real PDF link annotations — clickable in Adobe Reader, Preview, Chrome, and any spec-compliant viewer

Internationalisation

  • Bundled Inter font, exposed as PdfFont.Default, identical bytes on both platforms
  • Opt-in system fallbacks for non-Latin scripts: PdfFont.SystemCJK, PdfFont.SystemArabic, PdfFont.SystemPersian
  • Custom fonts via registerFont(PdfFont.Custom(name, bytes)) for brand or licence-bound typefaces

Images and vector graphics

  • Raster images (JPEG / PNG) embedded as-is for real photos
  • Vector and SVG images stay vector — sharp at any zoom

Storage

  • StorageLocation.Documents / Downloads / Cache / AppFiles / Temp / Custom
  • MediaStore on Android Q+ (no runtime permission needed)
  • Sandboxed paths on iOS

Opt-in companion modules

  • pdfkmp-viewer — a Compose Multiplatform PDF viewer composable with topbar, share sheet, zoom, search, and text selection. Works as a standalone viewer for any PDF, not just PdfKmp-generated ones.
  • pdfkmp-compose-resources — bridges Compose Multiplatform DrawableResource references into the PdfKmp DSL.

The core pdfkmp artifact stays Compose-free. If you don't use Compose, you don't pay for it.


Why vector matters

Most "save to PDF" flows on mobile rasterise — they snapshot a View and embed that bitmap. PdfKmp is vector-only for everything except real photos. That gives you three things:

  • Small file size. A typical text-heavy invoice lands in the tens of kilobytes, not megabytes.
  • Crisp output at any zoom. Path operators are resolution-independent.
  • Searchable, accessible documents. Real text means Preview's ⌘F finds the order number, and screen readers can read the page.

Cross-platform parity is the contract

PdfKmp pins the bundled Inter font on both platforms so glyph metrics match exactly. Same DSL → same line breaks → same page splits → same final file. For non-Latin scripts that rely on system fonts, the fallback is named explicitly so any divergence is visible instead of silent.

If the output ever differs between Android and iOS on a document you care about, that's a bug — open an issue with the DSL snippet.


Stability signals

  • 1.0 stable, follows SemVer — no breaking changes within the 1.x line
  • explicitApi() enforced — every public declaration is intentional
  • Apache 2.0 — drop-in for enterprise, no AGPL friction
  • R8-clean — no keep rules required
  • No third-party engines — output goes through the OS's native PDF stack

Links

https://github.com/ConaMobileDev/PdfKmp