API 요청
/rest/html_to_pdf요청 파라미터 2개 · 필수 1
html- 예시
<html><head><meta charset="utf-8"></head><body><h1>주문서</h1><p>주문번호 A-1001</p></body></html>
pagination- 예시
0
응답 필드 파일
정상 응답은 파일 본문입니다. 실패 시 JSON 오류가 올 수 있으므로 HTTP 상태와 Content-Type을 먼저 확인하세요.
HTML 코드를 보내면 화면에 그린 모습 그대로 PDF 파일로 돌려줍니다. 응답은 JSON이 아닌 PDF 파일입니다.
https://apick.app/rest/html_to_pdf왜 HTML PDF 변환인가
영수증·견적서·리포트를 PDF로 만들려고 별도 템플릿 작업을 반복하고 있다면 이제 멈추세요. 이미 만든 HTML을 보내면 그 모양 그대로 PDF 파일로 변환합니다.
주문서·영수증·보고서를 HTML 템플릿으로 만든 뒤 PDF로 내려주거나 메일에 첨부할 때 사용합니다.
스타일은 <style> 태그나 인라인 스타일로 HTML 안에 넣으세요. 상대 경로(./logo.png)로 연결한 이미지·CSS는 불러오지 못하고, 외부 주소로 연결한 리소스도 결과에서 빠질 수 있습니다. 이미지는 data:image/png;base64,… 형식으로 넣으면 안전합니다.
페이지를 나누고 싶은 위치에는 CSS page-break-after: always를 준 빈 블록 요소를 넣으세요. 용지는 A4(21cm × 29.7cm), 여백은 위·아래 1cm, 좌·우 2cm로 고정입니다. pagination=1을 보내면 각 페이지 하단 가운데에 현재 / 전체 형식의 페이지 번호가 들어갑니다.
성공한 건당 30P입니다. 실패·시간 초과 응답은 과금되지 않습니다.
/rest/html_to_pdfhtml<html><head><meta charset="utf-8"></head><body><h1>주문서</h1><p>주문번호 A-1001</p></body></html>pagination0정상 응답은 파일 본문입니다. 실패 시 JSON 오류가 올 수 있으므로 HTTP 상태와 Content-Type을 먼저 확인하세요.
POST https://apick.app/rest/html_to_pdfAuthorization: Bearer 내 계정의 API 인증키multipart/form-data상황별로 보내는 값과 응답에서 확인할 값을 모았습니다. 언어 탭에서 그대로 복사해 쓸 수 있습니다.
스타일을 HTML 안에 넣은 템플릿을 그대로 PDF로 만듭니다.
/rest/html_to_pdfcurl --fail-with-body --request POST 'https://apick.app/rest/html_to_pdf' \
--header "Authorization: Bearer $APICK_API_KEY" \
--form-string 'pagination=0' \
--form-string 'html=<html><head><meta charset="utf-8"><style>h1{font-size:20px}</style></head><body><h1>주문서</h1><p>주문번호 A-1001</p><p>홍길동 님</p></body></html>' \
--dump-header response.headers --output result.bin
# response.headers의 Content-Type을 확인한 뒤 파일을 사용하세요.const form = new FormData();
form.append("pagination", "0");
form.append("html", "<html><head><meta charset=\"utf-8\"><style>h1{font-size:20px}</style></head><body><h1>주문서</h1><p>주문번호 A-1001</p><p>홍길동 님</p></body></html>");
const response = await fetch("https://apick.app/rest/html_to_pdf", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.APICK_API_KEY },
body: form,
signal: AbortSignal.timeout(120_000),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
if ((response.headers.get("content-type") || "").includes("json")) {
throw new Error(JSON.stringify(await response.json()));
}
const { writeFile } = await import("node:fs/promises");
await writeFile("result.bin", new Uint8Array(await response.arrayBuffer()));import os
import requests
parts = [
("pagination", (None, "0")),
("html", (None, "<html><head><meta charset=\"utf-8\"><style>h1{font-size:20px}</style></head><body><h1>주문서</h1><p>주문번호 A-1001</p><p>홍길동 님</p></body></html>")),
]
response = requests.request("POST", "https://apick.app/rest/html_to_pdf",
headers={"Authorization": "Bearer " + os.environ["APICK_API_KEY"]},
files=parts,
timeout=(10, 120), stream=True)
response.raise_for_status()
if "json" in response.headers.get("Content-Type", ""):
raise RuntimeError(response.json())
with open("result.bin", "wb") as output:
for chunk in response.iter_content(65536):
output.write(chunk)<?php
$headers = ["Authorization: Bearer " . getenv("APICK_API_KEY")];
$form = [
'pagination' => '0',
'html' => '<html><head><meta charset="utf-8"><style>h1{font-size:20px}</style></head><body><h1>주문서</h1><p>주문번호 A-1001</p><p>홍길동 님</p></body></html>',
];
$curl = curl_init('https://apick.app/rest/html_to_pdf');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $form,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 120,
]);
$body = curl_exec($curl);
if ($body === false) { throw new RuntimeException(curl_error($curl)); }
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$type = curl_getinfo($curl, CURLINFO_CONTENT_TYPE) ?: "";
curl_close($curl);
if ($status >= 400) { throw new RuntimeException($body); }
if (strpos($type, "json") !== false) { throw new RuntimeException($body); }
file_put_contents('result.bin', $body);Content-Type이 application/pdf이면 output.pdf로 저장합니다.<meta charset="utf-8">이 들어 있는지 확인하세요.페이지를 나눌 위치에 page-break-after를 넣고 pagination=1로 하단 쪽 번호를 표시합니다.
/rest/html_to_pdfcurl --fail-with-body --request POST 'https://apick.app/rest/html_to_pdf' \
--header "Authorization: Bearer $APICK_API_KEY" \
--form-string 'html=<html><head><meta charset="utf-8"></head><body><h1>1장</h1><div style="page-break-after: always"></div><h1>2장</h1></body></html>' \
--form-string 'pagination=1' \
--dump-header response.headers --output result.bin
# response.headers의 Content-Type을 확인한 뒤 파일을 사용하세요.const form = new FormData();
form.append("html", "<html><head><meta charset=\"utf-8\"></head><body><h1>1장</h1><div style=\"page-break-after: always\"></div><h1>2장</h1></body></html>");
form.append("pagination", "1");
const response = await fetch("https://apick.app/rest/html_to_pdf", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.APICK_API_KEY },
body: form,
signal: AbortSignal.timeout(120_000),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
if ((response.headers.get("content-type") || "").includes("json")) {
throw new Error(JSON.stringify(await response.json()));
}
const { writeFile } = await import("node:fs/promises");
await writeFile("result.bin", new Uint8Array(await response.arrayBuffer()));import os
import requests
parts = [
("html", (None, "<html><head><meta charset=\"utf-8\"></head><body><h1>1장</h1><div style=\"page-break-after: always\"></div><h1>2장</h1></body></html>")),
("pagination", (None, "1")),
]
response = requests.request("POST", "https://apick.app/rest/html_to_pdf",
headers={"Authorization": "Bearer " + os.environ["APICK_API_KEY"]},
files=parts,
timeout=(10, 120), stream=True)
response.raise_for_status()
if "json" in response.headers.get("Content-Type", ""):
raise RuntimeError(response.json())
with open("result.bin", "wb") as output:
for chunk in response.iter_content(65536):
output.write(chunk)<?php
$headers = ["Authorization: Bearer " . getenv("APICK_API_KEY")];
$form = [
'html' => '<html><head><meta charset="utf-8"></head><body><h1>1장</h1><div style="page-break-after: always"></div><h1>2장</h1></body></html>',
'pagination' => '1',
];
$curl = curl_init('https://apick.app/rest/html_to_pdf');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $form,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 120,
]);
$body = curl_exec($curl);
if ($body === false) { throw new RuntimeException(curl_error($curl)); }
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$type = curl_getinfo($curl, CURLINFO_CONTENT_TYPE) ?: "";
curl_close($curl);
if ($status >= 400) { throw new RuntimeException($body); }
if (strpos($type, "json") !== false) { throw new RuntimeException($body); }
file_put_contents('result.bin', $body);현재 / 전체 형식 번호가 들어갑니다.HTTP 성공과 업무 결과를 구분하세요. 경로별 응답 필드와 예시는 위 요청과 응답에 함께 있습니다.
성공하면 PDF 본문이 바로 옵니다. 내려받기 파일명은 output.pdf입니다.
1이면 변환에 성공한 것입니다.application/pdf응답을 아래 순서로 확인하세요. 결과 유무와 과금 여부는 서로 다릅니다.
실패하면 PDF 대신 JSON이 옵니다. HTTP 상태와 Content-Type을 먼저 확인하고, JSON이면 data.error 문구를 기록하세요. 실패 응답의 api.cost는 0입니다.
html에 내용이 있는지 확인하세요.data.success가 3입니다. 큰 이미지·긴 표를 줄이거나 문서를 나눠 요청하세요.FORM_DATA_INVALIDFORM_DATA_FIELD_CONFLICTMULTIPART_LIMIT_OR_PARSE_ERROR실제 차감 금액은 응답의 api.cost로 확인하세요. 상세 요금은 요금정책에서 볼 수 있습니다.