> ## Documentation Index
> Fetch the complete documentation index at: https://docs-docflow.textin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 手書き情報

> 文書抽出における手書き情報の構造と処理方法の詳細説明

文書抽出機能は、文書内の手書き情報を認識できます。手書きテキストの内容、位置座標などの詳細情報が含まれます。手書き認識は、手書き署名や手書きメモなど、手書きコンテンツを含む文書の処理において重要な意味を持ちます。

## 手書き情報の構造

手書き情報は `result.files[].data.handwritings[]` に格納されており、各手書き項目には以下の属性が含まれます：

* `page`：手書きコンテンツが位置するページ番号（0 から開始）
* `text`：認識された手書きテキスト内容
* `position[]`：文書内における手書きコンテンツの位置座標情報

### 手書き情報のデータ構造

```json theme={null}
{
  "page": 0,           // ページ番号
  "text": "3月1日",    // 手書きテキスト内容
  "position": [
    {
      "page": 0,       // ページ番号
      "vertices": [    // 四隅の座標 [x1,y1,x2,y2,x3,y3,x4,y4]
        100, 200,      // 左上
        200, 200,      // 右上
        200, 250,      // 右下
        100, 250       // 左下
      ]
    }
  ]
}
```

### 位置座標の構造

```json theme={null}
{
  "page": 0,           // ページ番号（0 から開始）
  "vertices": [        // 四隅の座標 [x1,y1,x2,y2,x3,y3,x4,y4]
    100, 200,          // 左上
    200, 200,          // 右上
    200, 250,          // 右下
    100, 250           // 左下
  ]
}
```

座標の詳細については、[座標系](../03-parse/coordinate.mdx) のドキュメントを参照してください。

## サンプルコード

<CodeGroup>
  ```python Python icon=python expandable theme={null}
  import requests
  import json

  def extract_handwritings(workspace_id, batch_number, app_id, secret_code):
      """Extract handwriting information from documents"""

      host = "https://docflow.textin.ai"
      url = "/api/app-api/sip/platform/v2/file/fetch"

      resp = requests.get(
          f"{host}{url}",
          params={
              "workspace_id": workspace_id,
              "batch_number": batch_number
          },
          headers={
              "x-ti-app-id": app_id,
              "x-ti-secret-code": secret_code
          },
          timeout=60,
      )

      if resp.status_code != 200:
          print(f"Request failed: {resp.status_code}")
          return None

      data = resp.json()

      for file in data.get("result", {}).get("files", []):
          print(f"File name: {file.get('name')}")

          # Extract handwriting information
          handwritings = file.get("data", {}).get("handwritings", [])

          if handwritings:
              print(f"\n=== 手書き情報 ===")
              print(f"Number of handwriting items: {len(handwritings)}")

              for i, handwriting in enumerate(handwritings):
                  page = handwriting.get("page", 0)
                  text = handwriting.get("text", "")
                  positions = handwriting.get("position", [])

                  print(f"\nHandwriting item {i+1}:")
                  print(f"  Page: Page {page+1}")
                  print(f"  Content: {text}")

                  # Display position information
                  for j, pos in enumerate(positions):
                      pos_page = pos.get("page", 0)
                      vertices = pos.get("vertices", [])
                      print(f"  Position {j+1} (Page {pos_page+1}): {vertices}")
          else:
              print("No handwriting information found")

      return data

  # Usage example
  if __name__ == "__main__":
      workspace_id = "<your-workspace-id>"
      batch_number = "<your-batch-number>"
      app_id = "<your-app-id>"
      secret_code = "<your-secret-code>"

      result = extract_handwritings(workspace_id, batch_number, app_id, secret_code)
  ```
</CodeGroup>

## 返却データ例

```json expandable theme={null}
{
  "code": 200,
  "result": {
    "files": [
      {
        "id": "202412190001",
        "name": "contract.pdf",
        "recognition_status": 1,
        "data": {
          "handwritings": [
            {
              "page": 0,
              "text": "John Smith",
              "position": [
                {
                  "page": 0,
                  "vertices": [100, 500, 150, 500, 150, 520, 100, 520]
                }
              ]
            },
            {
              "page": 0,
              "text": "December 19, 2024",
              "position": [
                {
                  "page": 0,
                  "vertices": [200, 500, 300, 500, 300, 520, 200, 520]
                }
              ]
            },
            {
              "page": 0,
              "text": "Agree to this clause",
              "position": [
                {
                  "page": 0,
                  "vertices": [100, 600, 200, 600, 200, 620, 100, 620]
                }
              ]
            },
            {
              "page": 1,
              "text": "Jane Doe",
              "position": [
                {
                  "page": 1,
                  "vertices": [100, 300, 150, 300, 150, 320, 100, 320]
                }
              ]
            }
          ]
        }
      }
    ]
  }
}
```
