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

推荐订阅源

博客园_首页
H
Help Net Security
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
A
About on SuperTechFans
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
博客园 - 【当耐特】
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
I
InfoQ
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
U
Unit 42
The Cloudflare Blog
Y
Y Combinator 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
Convert a PDF to PowerPoint (.pptx) entirely in the browser
Muhammad Omer Mirza · 2026-06-23 · via DEV Community

Muhammad Omer Mirza

"PDF to PowerPoint" sounds like it needs a server: parse the PDF, rebuild slides, hand back a .pptx. But you can do the whole thing in the browser — render each page to an image with pdf.js, then assemble a genuine PowerPoint file with PptxGenJS. No upload, no backend, $0 hosting.

Here's the approach, including the two things that trip people up: matching the slide size to the page aspect ratio, and getting a downloadable .pptx blob out.

The two libraries

  • pdf.js — Mozilla's PDF engine. Renders any page onto a <canvas>.
  • PptxGenJS — builds real Open-XML .pptx files in JS (it bundles JSZip to assemble the archive).
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/pptxgenjs@3.12.0/dist/pptxgen.bundle.js"></script>

Note: PptxGenJS isn't on cdnjs — use the jsDelivr pptxgen.bundle.js build, which includes JSZip so the file actually zips up.

And the worker line pdf.js needs (set it before parsing anything, and don't defer the pdf.js tag):

pdfjsLib.GlobalWorkerOptions.workerSrc =
  "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js";

Step 1 — read the file locally

const file = input.files[0];
const bytes = new Uint8Array(await file.arrayBuffer()); // never leaves the page
const pdf = await pdfjsLib.getDocument({ data: bytes }).promise;

Step 2 — size the deck from the first page

PowerPoint slides are measured in inches; PDF pages in points (1 pt = 1/72 inch). To avoid letterboxing, define a custom layout that matches the PDF's own aspect ratio instead of forcing 16:9:

const pptx = new PptxGenJS();

const firstVp = (await pdf.getPage(1)).getViewport({ scale: 1 });
const wIn = Math.min(56, firstVp.width / 72);   // PptxGenJS caps a layout at 56"
const hIn = Math.min(56, firstVp.height / 72);

pptx.defineLayout({ name: "PDFPAGE", width: wIn, height: hIn });
pptx.layout = "PDFPAGE";

Step 3 — render each page and add it as a slide

Render at a scale above 1 so the slide image is crisp (scale = 2 is a good default), then place it full-bleed. The contain math below keeps it correct even if some pages are a different size from the first:

for (let n = 1; n <= pdf.numPages; n++) {
  const page = await pdf.getPage(n);
  const scale = 2;
  const vp = page.getViewport({ scale });

  const canvas = document.createElement("canvas");
  canvas.width = Math.floor(vp.width);
  canvas.height = Math.floor(vp.height);
  const ctx = canvas.getContext("2d");
  ctx.fillStyle = "#fff";                       // JPEG has no alpha
  ctx.fillRect(0, 0, canvas.width, canvas.height);
  await page.render({ canvasContext: ctx, viewport: vp }).promise;

  const data = canvas.toDataURL("image/jpeg", 0.85);

  // fit this page into the deck slide, preserving aspect ratio
  const pwIn = vp.width / scale / 72;
  const phIn = vp.height / scale / 72;
  const fit = Math.min(wIn / pwIn, hIn / phIn);
  const dw = pwIn * fit, dh = phIn * fit;

  const slide = pptx.addSlide();
  slide.addImage({ data, x: (wIn - dw) / 2, y: (hIn - dh) / 2, w: dw, h: dh });

  canvas.width = canvas.height = 0;             // free memory between pages
}

Gotcha #1: render page-by-page, free the canvas

A 30-page deck at scale: 2 allocates a lot of canvas memory. Render one page at a time and zero out the canvas (canvas.width = canvas.height = 0) after each, or large PDFs will blow up tab memory.

Step 4 — get a downloadable .pptx blob

writeFile() triggers a download directly, but if you want to wire your own button, ask for a blob:

const blob = await pptx.write({ outputType: "blob" });

const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "presentation.pptx";
a.click();
URL.revokeObjectURL(url);

Gotcha #2: the zip step is async

PptxGenJS assembles the .pptx (a zip archive) asynchronously. await the write() — and if you ever run this in a hidden/background tab, the timers JSZip relies on get throttled and the write appears to hang. Do the conversion in a visible tab.

What you get (and don't)

Each page becomes a pixel-perfect image on its own slide — the layout is identical to the PDF, and the user can drop their own text boxes, notes and shapes on top. The trade-off: the text lives inside the image, not as editable text boxes. For getting a PDF into a deck without redoing the layout by hand, that's usually exactly what you want.

  • Privacy: the PDF never touches a server.
  • Cost: static hosting, no backend.
  • Trade-off: memory scales with page count × DPI — so render incrementally.

I shipped this exact approach as a free tool — PDFNest's PDF to PowerPoint converter — one slide per page, all in the browser, nothing uploaded. There's a PDF to Image tool built on the same pdf.js render path, and the rest of the free PDF toolkit is here. Happy to dig into the PptxGenJS layout math in the comments.