# クイックスタート
最初の認証付きリクエストを最初から最後まで実行する方法です。キーを取得し、PDF を送信し、返ってきたドキュメントを保存します。
ゼロから処理済みの PDF にたどり着く最短経路です。キーを取得し、1回呼び出し、結果を保存するだけです。SDK は不要で、API キーとディスク上の PDF 以外に準備するものはありません。
<Steps>
<Step title="API キーを取得する">
[ダッシュボード](https://dashboard.pdfblocks.com)にサインインし、API キーを作成します。安全な場所にコピーしてください。すべてのリクエストで送信することになります。キーの仕組みと安全な保管方法については、[認証](/docs/api/authentication)を参照してください。
</Step>
<Step title="リクエストを1回送信する">
作業ディレクトリに `input.pdf` という名前の PDF を置き、`your_api_key` を自分のキーに置き換えて、次のいずれかを実行します。どの例も、ドキュメントに透かしを付与し、結果を `watermarked.pdf` に書き込みます。
<CodeGroup>
```bash title="cURL"
curl https://api.pdfblocks.com/v1/add_text_watermark \
-H 'X-API-Key: your_api_key' \
-F file=@input.pdf \
-F line_1='CONFIDENTIAL' \
-o watermarked.pdf
```
```python title="Python"
# pip install requests
import requests
with open('input.pdf', 'rb') as file:
response = requests.post(
'https://api.pdfblocks.com/v1/add_text_watermark',
headers={'X-API-Key': 'your_api_key'},
files={'file': file},
data={'line_1': 'CONFIDENTIAL'},
)
response.raise_for_status()
with open('watermarked.pdf', 'wb') as output:
output.write(response.content)
```
```javascript title="Node.js"
// Node.js 18+
import { readFile, writeFile } from 'node:fs/promises';
const body = new FormData();
body.set('file', new Blob([await readFile('input.pdf')]), 'input.pdf');
body.set('line_1', 'CONFIDENTIAL');
const response = await fetch('https://api.pdfblocks.com/v1/add_text_watermark', {
method: 'POST',
headers: { 'X-API-Key': 'your_api_key' },
body,
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
await writeFile('watermarked.pdf', Buffer.from(await response.arrayBuffer()));
```
```php title="PHP"
<?php
$ch = curl_init('https://api.pdfblocks.com/v1/add_text_watermark');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: your_api_key'],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'file' => new CURLFile('input.pdf', 'application/pdf'),
'line_1' => 'CONFIDENTIAL',
],
]);
$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
file_put_contents('watermarked.pdf', $pdf);
}
```
```ruby title="Ruby"
# gem install http
require 'http'
response = HTTP
.headers('X-API-Key' => 'your_api_key')
.post('https://api.pdfblocks.com/v1/add_text_watermark', form: {
file: HTTP::FormData::File.new('input.pdf'),
line_1: 'CONFIDENTIAL',
})
File.write('watermarked.pdf', response.body) if response.status.success?
```
```go title="Go"
package main
import (
"bytes"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var buf bytes.Buffer
form := multipart.NewWriter(&buf)
file, _ := os.Open("input.pdf")
defer file.Close()
part, _ := form.CreateFormFile("file", "input.pdf")
io.Copy(part, file)
form.WriteField("line_1", "CONFIDENTIAL")
form.Close()
req, _ := http.NewRequest("POST", "https://api.pdfblocks.com/v1/add_text_watermark", &buf)
req.Header.Set("Content-Type", form.FormDataContentType())
req.Header.Set("X-API-Key", "your_api_key")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
out, _ := os.Create("watermarked.pdf")
defer out.Close()
io.Copy(out, res.Body)
}
```
```csharp title="C#"
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", "your_api_key");
using var form = new MultipartFormDataContent
{
{ new ByteArrayContent(File.ReadAllBytes("input.pdf")), "file", "input.pdf" },
{ new StringContent("CONFIDENTIAL"), "line_1" },
};
var response = await client.PostAsync(
"https://api.pdfblocks.com/v1/add_text_watermark", form);
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync(
"watermarked.pdf", await response.Content.ReadAsByteArrayAsync());
```
</CodeGroup>
</Step>
<Step title="PDF を開く">
成功すると、API は `200 OK` で応答し、透かし入りのドキュメントをレスポンスボディに含めます。
```http
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Length: 48213
```
`watermarked.pdf` を開いてください。すべてのページに `CONFIDENTIAL` が付与された、あなたの入力そのものです。これがすべての契約です。PDF が1つ入り、PDF が1つ出てきて、こちら側には何も保存されません。
</Step>
</Steps>
<Tip>
`200` が返ってこない場合、キーが未指定または誤っていると `401` が、`file` を読み取れない場合は `400` が、いずれも `application/problem+json` として返されます。すべてのステータスコードの一覧については、[エラー](/docs/api/errors)を参照してください。
</Tip>
## 次のステップ
<CardGroup cols={2}>
<Card title="認証" href="/docs/api/authentication">
キーを管理し、ローテーションし、ソース管理の外に保ちましょう。
</Card>
<Card title="アクションの概要" href="/docs/api/actions-overview">
17のアクションすべてを確認し、それらをどう組み合わせられるか見てみましょう。
</Card>
<Card title="リクエストとレスポンス" href="/docs/api/requests-and-responses">
すべてのアクションが共有する、統一されたリクエストとレスポンスの形式です。
</Card>
</CardGroup>
クイックスタート
最初の認証付きリクエストを最初から最後まで実行する方法です。キーを取得し、PDF を送信し、返ってきたドキュメントを保存します。
ゼロから処理済みの PDF にたどり着く最短経路です。キーを取得し、1回呼び出し、結果を保存するだけです。SDK は不要で、API キーとディスク上の PDF 以外に準備するものはありません。
リクエストを1回送信する
作業ディレクトリに input.pdf という名前の PDF を置き、your_api_key を自分のキーに置き換えて、次のいずれかを実行します。どの例も、ドキュメントに透かしを付与し、結果を watermarked.pdf に書き込みます。
curl https://api.pdfblocks.com/v1/add_text_watermark \
-H 'X-API-Key: your_api_key' \
-F file=@input.pdf \
-F line_1='CONFIDENTIAL' \
-o watermarked.pdf# pip install requests
import requests
with open('input.pdf', 'rb') as file:
response = requests.post(
'https://api.pdfblocks.com/v1/add_text_watermark',
headers={'X-API-Key': 'your_api_key'},
files={'file': file},
data={'line_1': 'CONFIDENTIAL'},
)
response.raise_for_status()
with open('watermarked.pdf', 'wb') as output:
output.write(response.content)// Node.js 18+
import { readFile, writeFile } from 'node:fs/promises';
const body = new FormData();
body.set('file', new Blob([await readFile('input.pdf')]), 'input.pdf');
body.set('line_1', 'CONFIDENTIAL');
const response = await fetch('https://api.pdfblocks.com/v1/add_text_watermark', {
method: 'POST',
headers: { 'X-API-Key': 'your_api_key' },
body,
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
await writeFile('watermarked.pdf', Buffer.from(await response.arrayBuffer()));<?php
$ch = curl_init('https://api.pdfblocks.com/v1/add_text_watermark');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: your_api_key'],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'file' => new CURLFile('input.pdf', 'application/pdf'),
'line_1' => 'CONFIDENTIAL',
],
]);
$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
file_put_contents('watermarked.pdf', $pdf);
}# gem install http
require 'http'
response = HTTP
.headers('X-API-Key' => 'your_api_key')
.post('https://api.pdfblocks.com/v1/add_text_watermark', form: {
file: HTTP::FormData::File.new('input.pdf'),
line_1: 'CONFIDENTIAL',
})
File.write('watermarked.pdf', response.body) if response.status.success?package main
import (
"bytes"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var buf bytes.Buffer
form := multipart.NewWriter(&buf)
file, _ := os.Open("input.pdf")
defer file.Close()
part, _ := form.CreateFormFile("file", "input.pdf")
io.Copy(part, file)
form.WriteField("line_1", "CONFIDENTIAL")
form.Close()
req, _ := http.NewRequest("POST", "https://api.pdfblocks.com/v1/add_text_watermark", &buf)
req.Header.Set("Content-Type", form.FormDataContentType())
req.Header.Set("X-API-Key", "your_api_key")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
out, _ := os.Create("watermarked.pdf")
defer out.Close()
io.Copy(out, res.Body)
}using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", "your_api_key");
using var form = new MultipartFormDataContent
{
{ new ByteArrayContent(File.ReadAllBytes("input.pdf")), "file", "input.pdf" },
{ new StringContent("CONFIDENTIAL"), "line_1" },
};
var response = await client.PostAsync(
"https://api.pdfblocks.com/v1/add_text_watermark", form);
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync(
"watermarked.pdf", await response.Content.ReadAsByteArrayAsync());PDF を開く
成功すると、API は 200 OK で応答し、透かし入りのドキュメントをレスポンスボディに含めます。
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Length: 48213watermarked.pdf を開いてください。すべてのページに CONFIDENTIAL が付与された、あなたの入力そのものです。これがすべての契約です。PDF が1つ入り、PDF が1つ出てきて、こちら側には何も保存されません。
200 が返ってこない場合、キーが未指定または誤っていると 401 が、file を読み取れない場合は 400 が、いずれも application/problem+json として返されます。すべてのステータスコードの一覧については、エラーを参照してください。