jpskill.com
📄 ドキュメント コミュニティ

pdfkit

Node.js環境で、請求書や報告書、証明書といった構造化されたPDFドキュメントを、テキストや画像、図形、表、ヘッダー/フッター、カスタムフォントなどを活用して、アプリケーションデータからプログラムで自動生成するSkill。

📜 元の英語説明(参考)

Generate PDF documents programmatically with PDFKit — add text, images, vector graphics, tables, headers/footers, and custom fonts. Use when tasks involve creating invoices, reports, certificates, or any structured PDF output from application data in Node.js.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Node.js環境で、請求書や報告書、証明書といった構造化されたPDFドキュメントを、テキストや画像、図形、表、ヘッダー/フッター、カスタムフォントなどを活用して、アプリケーションデータからプログラムで自動生成するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o pdfkit.zip https://jpskill.com/download/15244.zip && unzip -o pdfkit.zip && rm pdfkit.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15244.zip -OutFile "$d\pdfkit.zip"; Expand-Archive "$d\pdfkit.zip" -DestinationPath $d -Force; ri "$d\pdfkit.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して pdfkit.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → pdfkit フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

PDFKit

Node.js用のプログラムによるPDF生成。ストリーミングアーキテクチャ — ファイルまたはHTTPレスポンスに書き込みます。

セットアップ

# PDF生成のためにPDFKitをインストールします。
npm install pdfkit
npm install -D @types/pdfkit

基本的なドキュメント

// src/pdf/basic.ts — テキストを含む単純なPDFを作成し、ファイルに保存します。
import PDFDocument from "pdfkit";
import fs from "fs";

const doc = new PDFDocument({ size: "A4", margin: 50 });
doc.pipe(fs.createWriteStream("output.pdf"));

doc.fontSize(24).text("Monthly Report", { align: "center" });
doc.moveDown();
doc.fontSize(12).text("Generated on " + new Date().toLocaleDateString());
doc.moveDown(2);
doc.fontSize(11).text(
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
  "Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
  { align: "justify", lineGap: 4 }
);

doc.end();

テーブル

// src/pdf/table.ts — ヘッダーと行を持つテーブルを描画します。
// PDFKitには組み込みのテーブルはありません。線と配置されたテキストで描画します。
import PDFDocument from "pdfkit";

export function drawTable(
  doc: PDFKit.PDFDocument,
  headers: string[],
  rows: string[][],
  startY: number
) {
  const colWidth = (doc.page.width - 100) / headers.length;
  const rowHeight = 25;
  let y = startY;

  // ヘッダー行
  doc.font("Helvetica-Bold").fontSize(10);
  headers.forEach((header, i) => {
    doc.text(header, 50 + i * colWidth, y, { width: colWidth, align: "left" });
  });

  y += rowHeight;
  doc.moveTo(50, y).lineTo(doc.page.width - 50, y).stroke();

  // データ行
  doc.font("Helvetica").fontSize(10);
  for (const row of rows) {
    y += 5;
    row.forEach((cell, i) => {
      doc.text(cell, 50 + i * colWidth, y, { width: colWidth, align: "left" });
    });
    y += rowHeight;

    // 必要に応じて改ページ
    if (y > doc.page.height - 100) {
      doc.addPage();
      y = 50;
    }
  }
}

画像とグラフィックス

// src/pdf/graphics.ts — 画像の追加、図形の描画、ベクターグラフィックスの使用。
import PDFDocument from "pdfkit";
import fs from "fs";

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream("report.pdf"));

// 画像を埋め込む
doc.image("logo.png", 50, 50, { width: 150 });

// 色付きの長方形を描画する
doc.rect(50, 250, 200, 100).fill("#3498db");

// 円を描画する
doc.circle(400, 300, 50).fill("#e74c3c");

// 線を描画する
doc.moveTo(50, 400).lineTo(550, 400).dash(5, { space: 5 }).stroke("#999");

doc.end();

ヘッダーとフッター

// src/pdf/headers.ts — ページ番号付きの繰り返しヘッダーとフッターを追加します。
import PDFDocument from "pdfkit";
import fs from "fs";

export function createDocWithHeaderFooter(title: string, outputPath: string) {
  const doc = new PDFDocument({ size: "A4", margin: 50, bufferPages: true });
  doc.pipe(fs.createWriteStream(outputPath));

  // 複数ページにわたってコンテンツを書き込む
  doc.fontSize(20).text(title, { align: "center" });
  doc.moveDown(2);
  for (let i = 0; i < 200; i++) {
    doc.fontSize(11).text(`Line ${i + 1}: Sample content for the report.`);
  }

  // すべてのページにヘッダーとフッターを追加する
  const pageCount = doc.bufferedPageRange().count;
  for (let i = 0; i < pageCount; i++) {
    doc.switchToPage(i);

    // ヘッダー
    doc.fontSize(8).fillColor("#999")
      .text(title, 50, 20, { align: "left" })
      .text(new Date().toLocaleDateString(), 50, 20, { align: "right" });

    // ページ番号付きのフッター
    doc.text(`Page ${i + 1} of ${pageCount}`, 50, doc.page.height - 30, {
      align: "center",
    });
  }

  doc.end();
}

カスタムフォント

// src/pdf/fonts.ts — ブランドドキュメント用のカスタムフォントを登録して使用します。
import PDFDocument from "pdfkit";
import fs from "fs";

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream("branded.pdf"));

// カスタムフォントを登録する
doc.registerFont("Inter", "./fonts/Inter-Regular.ttf");
doc.registerFont("Inter-Bold", "./fonts/Inter-Bold.ttf");

doc.font("Inter-Bold").fontSize(24).text("Branded Report");
doc.font("Inter").fontSize(12).text("Using custom Inter font throughout.");

doc.end();

HTTPレスポンスへのストリーミング

// src/pdf/stream.ts — PDFをオンザフライで生成し、Expressレスポンスにストリーミングします。
import PDFDocument from "pdfkit";
import type { Response } from "express";

export function streamPdf(res: Response, title: string) {
  const doc = new PDFDocument();
  res.setHeader("Content-Type", "application/pdf");
  res.setHeader("Content-Disposition", `attachment; filename="${title}.pdf"`);

  doc.pipe(res);
  doc.fontSize(20).text(title);
  doc.end();
}
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

PDFKit

Programmatic PDF generation for Node.js. Streaming architecture — write to files or HTTP responses.

Setup

# Install PDFKit for PDF generation.
npm install pdfkit
npm install -D @types/pdfkit

Basic Document

// src/pdf/basic.ts — Create a simple PDF with text and save to file.
import PDFDocument from "pdfkit";
import fs from "fs";

const doc = new PDFDocument({ size: "A4", margin: 50 });
doc.pipe(fs.createWriteStream("output.pdf"));

doc.fontSize(24).text("Monthly Report", { align: "center" });
doc.moveDown();
doc.fontSize(12).text("Generated on " + new Date().toLocaleDateString());
doc.moveDown(2);
doc.fontSize(11).text(
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
  "Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
  { align: "justify", lineGap: 4 }
);

doc.end();

Tables

// src/pdf/table.ts — Draw a table with headers and rows.
// PDFKit has no built-in table; draw it with lines and positioned text.
import PDFDocument from "pdfkit";

export function drawTable(
  doc: PDFKit.PDFDocument,
  headers: string[],
  rows: string[][],
  startY: number
) {
  const colWidth = (doc.page.width - 100) / headers.length;
  const rowHeight = 25;
  let y = startY;

  // Header row
  doc.font("Helvetica-Bold").fontSize(10);
  headers.forEach((header, i) => {
    doc.text(header, 50 + i * colWidth, y, { width: colWidth, align: "left" });
  });

  y += rowHeight;
  doc.moveTo(50, y).lineTo(doc.page.width - 50, y).stroke();

  // Data rows
  doc.font("Helvetica").fontSize(10);
  for (const row of rows) {
    y += 5;
    row.forEach((cell, i) => {
      doc.text(cell, 50 + i * colWidth, y, { width: colWidth, align: "left" });
    });
    y += rowHeight;

    // Page break if needed
    if (y > doc.page.height - 100) {
      doc.addPage();
      y = 50;
    }
  }
}

Images and Graphics

// src/pdf/graphics.ts — Add images, draw shapes, and use vector graphics.
import PDFDocument from "pdfkit";
import fs from "fs";

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream("report.pdf"));

// Embed an image
doc.image("logo.png", 50, 50, { width: 150 });

// Draw a colored rectangle
doc.rect(50, 250, 200, 100).fill("#3498db");

// Draw a circle
doc.circle(400, 300, 50).fill("#e74c3c");

// Draw a line
doc.moveTo(50, 400).lineTo(550, 400).dash(5, { space: 5 }).stroke("#999");

doc.end();

Headers and Footers

// src/pdf/headers.ts — Add repeating headers and footers with page numbers.
import PDFDocument from "pdfkit";
import fs from "fs";

export function createDocWithHeaderFooter(title: string, outputPath: string) {
  const doc = new PDFDocument({ size: "A4", margin: 50, bufferPages: true });
  doc.pipe(fs.createWriteStream(outputPath));

  // Write content across multiple pages
  doc.fontSize(20).text(title, { align: "center" });
  doc.moveDown(2);
  for (let i = 0; i < 200; i++) {
    doc.fontSize(11).text(`Line ${i + 1}: Sample content for the report.`);
  }

  // Add headers and footers to all pages
  const pageCount = doc.bufferedPageRange().count;
  for (let i = 0; i < pageCount; i++) {
    doc.switchToPage(i);

    // Header
    doc.fontSize(8).fillColor("#999")
      .text(title, 50, 20, { align: "left" })
      .text(new Date().toLocaleDateString(), 50, 20, { align: "right" });

    // Footer with page number
    doc.text(`Page ${i + 1} of ${pageCount}`, 50, doc.page.height - 30, {
      align: "center",
    });
  }

  doc.end();
}

Custom Fonts

// src/pdf/fonts.ts — Register and use custom fonts for branded documents.
import PDFDocument from "pdfkit";
import fs from "fs";

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream("branded.pdf"));

// Register custom font
doc.registerFont("Inter", "./fonts/Inter-Regular.ttf");
doc.registerFont("Inter-Bold", "./fonts/Inter-Bold.ttf");

doc.font("Inter-Bold").fontSize(24).text("Branded Report");
doc.font("Inter").fontSize(12).text("Using custom Inter font throughout.");

doc.end();

Streaming to HTTP Response

// src/pdf/stream.ts — Generate PDFs on the fly and stream to Express responses.
import PDFDocument from "pdfkit";
import type { Response } from "express";

export function streamPdf(res: Response, title: string) {
  const doc = new PDFDocument();
  res.setHeader("Content-Type", "application/pdf");
  res.setHeader("Content-Disposition", `attachment; filename="${title}.pdf"`);

  doc.pipe(res);
  doc.fontSize(20).text(title);
  doc.end();
}