本文へ移動
cccskills
無料GitHub で公開

markdown-to-pdf

Convert Markdown (.md) files to a polished PDF with ALL images preserved and scaled to the page. Use whenever the user asks to "save this markdown as a PDF", "convert README.md to pdf", "export the .md as a pdf", "turn these notes/docs into a PDF", or wants a PDF deliverable of any GitHub-flavored Markdown document (README, design doc, report, notes) — especially when it contains images or diagrams (remote or local), tables, code blocks, or a linked table of contents. Pipeline: pandoc (GFM → standalone HTML with embedded resources) → headless Chrome print-to-pdf with a GitHub-like print stylesheet → pypdf verification that every referenced image is embedded. Do NOT use for .tex → PDF (use a LaTeX toolchain) or for .docx work (use word-docx / tex2docx).

インストール方法を見る

含まれるファイル(4)

  • SKILL.md6.1 KB
  • assets/print.css1.6 KB
  • README.md5.5 KB
  • scripts/md2pdf.py7.5 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Markdown → PDF (pandoc + headless Chrome)

Problem

Converting Markdown to PDF through pandoc's default LaTeX route breaks on real-world GitHub-flavored documents: Unicode box-drawing characters in code blocks (├──) crash pdflatex, wide GFM tables overflow the page, remote images need manual download, and the output looks nothing like the rendered Markdown the author reviewed. Naive HTML routes drop images or paste them at native resolution so they spill off the page.

Context / Trigger Conditions

  • User asks to save/convert/export a .md file as PDF.
  • The document carries images (hosted PNGs, local figures), GFM tables, fenced code blocks, blockquotes, or #-anchor TOC links.
  • Requirements like "all images must be preserved" or "scaled appropriately".

Solution

Render the Markdown to HTML exactly as a browser would, then print it.

One command (preferred):

python ~/.claude/skills/markdown-to-pdf/scripts/md2pdf.py <input.md> [-o out.pdf]

The script: (1) runs pandoc -f gfm -t html5 --standalone --embed-resources with assets/print.css, executed from the Markdown's own directory so relative image paths resolve, and with remote images fetched and inlined as data URIs; (2) prints with headless Chrome (Edge/Chromium fallback) using --no-pdf-header-footer --virtual-time-budget=30000; (3) verifies with pypdf that the embedded raster-image count is at least the number of image references in the source, printing each image's page and dimensions. Exit code 2 flags a missing-image warning.

Manual equivalent (what the script automates):

pandoc input.md -f gfm -t html5 -s --embed-resources -c print.css \
    --metadata pagetitle="input" -o /tmp/input.html
"/c/Program Files/Google/Chrome/Application/chrome.exe" --headless \
    --disable-gpu --no-pdf-header-footer --virtual-time-budget=30000 \
    --print-to-pdf="out.pdf" "file:///tmp/input.html"

Why this works for images. The stylesheet constrains every image with max-width: 100%; max-height: 240mm; width/height: auto; break-inside: avoid, so each image scales to the printable width, a very tall diagram still fits a single page, aspect ratio is preserved, and no image is split across a page break. --virtual-time-budget makes Chrome wait for image loading before printing; --embed-resources makes the HTML self-contained so nothing depends on the network at print time.

Verification

  1. The script's pypdf pass: page count, plus one line per embedded image with its page number and pixel dimensions; compare against the source's image count.
  2. Visual spot-check: the Read tool renders PDF pages as images — read the pages the verifier listed and confirm each diagram is legible and fits the page.

Example

style-emulation/README.md (~800 lines: 4 hosted PNG diagrams up to 1410×2998 px, two request/command tables, a box-drawing module map, a linked TOC) → 19-page, 1.35 MB PDF; all 4 images embedded on pages 6/7/9/10, each scaled to one page; tables bordered with zebra striping; code blocks styled; TOC links live.

Notes

  • Page-break trade-off: break-inside: avoid keeps images whole, so an image that does not fit the space left on a page pushes to the next page, leaving white space behind. Acceptable for reports; mention it to the user.
  • TOC anchors: pandoc's GFM reader auto-generates GitHub-style heading ids, so existing (#section-name) links keep working in the PDF.
  • SVG images may be drawn as vector art rather than raster XObjects; the pypdf count then under-reports and the warning is a false positive — check visually.
  • Same image referenced twice can be embedded once; the embedded < referenced check is a heuristic, not an exact equality test.
  • Wide code blocks are handled by white-space: pre-wrap (wrap, never clip); long table cells wrap inside bordered cells at 8.5pt.
  • Paper/margins live in assets/print.css (@page { size: A4; margin: 16mm 15mm; }); pass --css <file> for a per-job override (e.g. letter, landscape).
  • --no-embed reverts to link-only HTML with Chrome fetching images at print time — useful if pandoc cannot reach a host that Chrome can.
  • If headless Chrome ever hangs on a remote-image page, raise --budget.
  • Locked targets (cloud sync / open viewers): Chrome can fail to overwrite a PDF in a Dropbox/OneDrive-synced folder — or one open in Acrobat — while still exiting 0, silently leaving the stale file in place (the byte-identical output size is the tell). The script therefore prints to its temp dir and moves the result over the target with retries; if the target stays locked (e.g. the user has the old PDF open), it saves to <name>.new.pdf and says so. The pypdf verification step is what catches this class of failure — keep it on.

Related skills

  • pdf — probing, extracting, manipulating existing PDFs (and reportlab generation from scratch). Markdown sources route here instead.
  • tex2docx, manuscript-editing-template-latex — LaTeX/docx conversion pipelines; use those for .tex/.docx, not this skill.

References

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Build human adjudication / hand-labeling sheets from LLM-pipeline data without evidence truncation. Use when: (1) preparing a CSV/Excel sheet for a human to rule on cases an LLM classifier or rater panel judged, (2) a labeler reports "there is no information to label from" or cells look empty in Excel, (3) excerpt columns cluster at one exact length (e.g. all 1,500 chars — a hard truncation cap). Covers: full rating-basis recovery, Excel 32,767-char cell cap, multi-line CSV mangling, ruling dropdowns, companion text files.

日本語の概要は準備中です。原文の説明を表示しています。

kennethkhoocy/applied-micro-skills222026年9月5日 更新

N-round adversarial review pipeline for empirical research output — the chain from data to LaTeX tables to a manuscript that cites them. A Claude drafter proposes minimal diffs, a deterministic mechanical battery gates every diff from a clean state with a regression gate, a Codex reviewer files check-backed critiques, and a blind judge panel decides residual disputes. Manual-invoke ONLY: trigger when the user explicitly runs /adversarial-empirical-review or names 'adversarial-empirical-review' / 'adversarial empirical review'. Do NOT auto-trigger on generic 'review my results', 'check my tables', or manuscript-editing requests. For prose-style refinement use style-emulation instead; this skill AUDITS WHETHER THE TABLES ARE CORRECT — that each number in the tables is what the analysis code computes, reproduces from the data, and is internally consistent. It is an empirical + code review: the manuscript is read only to resolve table numbering, and prose is not examined.

日本語の概要は準備中です。原文の説明を表示しています。

kennethkhoocy/applied-micro-skills222026年9月5日 更新

Before designing, training, or auditing ANY model that replicates human-annotated labels, audit the annotation protocol's INPUT — the exact document/evidence the human labelers consulted — and give the model that same input. Use when: (1) designing a classifier/LLM extractor whose target is a hand-coded label set, (2) a label-replication model shows low recall concentrated in a label subset and the diagnosis on offer is "the label's information is not in the features", (3) reviewers propose construct splits (e.g. "designation vs record-evident"), adjudication sittings, or per-domain stop rules to explain residual disagreement with gold, (4) validating an extraction pipeline against labels transcribed from a source document. Symptom of the underlying failure: elaborate theory accumulates to explain why gold is "partially unpredictable" when the model was simply never shown the document the annotators read.

日本語の概要は準備中です。原文の説明を表示しています。

kennethkhoocy/applied-micro-skills222026年9月5日 更新

Raise real concurrency in asyncio LLM batch scorers built on the OpenAI SDK (AsyncOpenAI, including OpenAI-compatible providers like DeepSeek). Use when: (1) raising an asyncio.Semaphore above ~100 produces no throughput gain, (2) a batch pipeline saturates near 100 in-flight requests despite a larger semaphore, (3) planning a high-concurrency campaign against a provider with no hard rate limit (DeepSeek v4-flash tolerates 2000+ in flight). Root cause: AsyncOpenAI's default httpx pool caps max_connections at 100, silently bottlenecking any larger semaphore — you must pass a custom http_client with httpx.Limits sized to the semaphore.

日本語の概要は準備中です。原文の説明を表示しています。

kennethkhoocy/applied-micro-skills222026年9月5日 更新

Place pre-screened literature citations into a LaTeX or Word manuscript, or restyle the citations already in one. Three modes: (1) inline placement — inline \cite{}/\citet{}/\citep{} with a compiled references.bib, for author-date journals (APA, MLA, Harvard, Chicago author-date, IEEE, Vancouver); (2) footnote placement — full formatted \footnote{} or OOXML footnotes for legal and notes styles (Bluebook, OSCOLA, Chicago, APA, McGill) with Id./supra short forms; (3) restyle — convert existing footnote citations from one style to another. This skill is manual-invoke ONLY — trigger ONLY when the user explicitly runs /cite-placement or explicitly names the "cite-placement" skill. Do NOT auto-trigger on general citation, footnote, or reference requests.

日本語の概要は準備中です。原文の説明を表示しています。

kennethkhoocy/applied-micro-skills222026年9月5日 更新

Download the actual PDF binary from bot-gated sites (taxpolicycenter.org, urban.org, SSRN-hosted mirrors, think-tank/publisher sites) via the Wayback Machine id_ URL form. Use when: (1) curl/WebFetch of a .pdf URL returns HTML instead of a PDF even with a browser User-Agent, (2) pypdf fails with "invalid pdf header: b'<!DOC'" or "EOF marker not found" on a freshly downloaded file, (3) Firecrawl can parse the PDF to markdown but you need the original file on disk (e.g., filing a reference copy).

日本語の概要は準備中です。原文の説明を表示しています。

kennethkhoocy/applied-micro-skills222026年9月5日 更新

kennethkhoocy のスキルをすべて見る

このスキルの問題を報告する