Colophon Server - HTML to PDF / Image Converter
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body {
font-family: 'ヒラギノ明朝 Pro', serif;
padding: 20px;
}
h1 { text-align: center; }
</style>
</head>
<body>
<h1>書籍タイトル</h1>
<p>著者: 山田太郎</p>
<p>発行日: 2024年1月1日</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body { font-family: sans-serif; }
.page-break {
page-break-after: always;
}
</style>
</head>
<body>
<h1>1ページ目</h1>
<p>内容...</p>
<div class="page-break"></div>
<h1>2ページ目</h1>
<p>内容...</p>
</body>
</html>
POST /api/render - PDF生成
POST /api/image - 画像生成
以下の2つの形式をサポートしています:
HTMLをそのままPOSTボディに送信(デフォルト: 192x276 mm、1ページのみ)
curl -X POST http://localhost:3000/api/render \
-H "Content-Type: text/html" \
-d '<html><body><h1>Hello</h1></body></html>' \
--output output.pdf
詳細な設定が可能なJSON形式:
{
"width": 192, // 横幅(必須)
"height": 276, // 縦幅(必須)
"unit": "mm", // 単位(必須): mm, cm, in, px
"contents": "<html>...</html>", // HTMLコンテンツ(必須)
"out_of_all": false // 全ページ出力フラグ(省略可、デフォルト: false)
}
curlでの例:
curl -X POST http://localhost:3000/api/render \
-H "Content-Type: application/json" \
-d '{
"width": 192,
"height": 276,
"unit": "mm",
"out_of_all": true,
"contents": "<html><body><h1>Page 1</h1><div style=\"page-break-after: always;\"></div><h1>Page 2</h1></body></html>"
}' \
--output output.pdf
指定したURLのWebページのスクリーンショットをPNGまたはJPG画像として生成します。
{
"url": "https://example.com", // スクリーンショットを取得するURL(必須)
"width": 1920, // 画面幅(省略可、デフォルト: 1920)
"height": 1080, // 画面高さ(省略可、デフォルト: 1080)
"format": "png" // 画像形式: "png" または "jpg"(省略可、デフォルト: "png")
}
curlでの例:
curl -X POST http://localhost:3000/api/image \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"width": 1920,
"height": 1080,
"format": "png"
}' \
--output screenshot.png
注意: JPG形式の場合、品質は90に設定されます。