Handwriting OCR API Documentation

Handwriting OCR API Documentation

Integrate Pen to Print’s advanced handwriting recognition into your applications with a simple, REST-based handwriting to text API.

Overview

Pen to Print's API provides a simple way to add handwriting to text capabilities to your product. Your application sends a scanned handwritten page as a base64-encoded image, and our advanced handwriting OCR engine converts the content from image to text, returning clean, editable text in a structured JSON response.

Authentication is handled with a userId and API secret, making it straightforward to integrate into web, mobile, desktop, or backend services. The API is stateless and lightweight, ideal for powering handwriting to text features such as digitizing notes, processing scanned documents, or embedding handwriting OCR directly into your existing workflows.

Endpoint

POST
https://api.pen-to-print.com/V1/notes
Content-Typeapplication/json

Credentials

You can find both values in your Account Settings.

Field
Where to get it
Notes
userId
Shown on your Account Settings
Required
secret
Shown on your Account Settings
Required; keep private

Request Parameters

Send a JSON body with the following fields:

Parameter
Type
Required
Description
userId
string
Yes
Your Pen to Print user identifier.
secret
string
Yes
Your API secret (from your Account Settings).
srcImage
string
Yes
Base64 representation of the source image.

Example JSON Body

{
  "userId": "YOUR_USER_ID",
  "secret": "YOUR_API_SECRET",
  "srcImage": "BASE64_IMAGE_STRING"
}

Response

On success (HTTP 200), the response is JSON:

{
  "status": 1,
  "value": "…recognized text…"
}

Error Responses

Status
When it happens
Body
400
Missing required parameters
{'error':'Missing parameters'}
403
Invalid secret
{'error':'Unauthorized'}
405
No active subscription
{'error':'API access not allowed'}
500
Internal server error
{'error':'Scan failed'}

Code Examples

JavaScript (Node.js 18+)

import fs from "node:fs";

const endpoint = "https://api.pen-to-print.com/V1/notes";
const userId = "YOUR_USER_ID";
const secret = "YOUR_API_SECRET";

// Read an image file and convert to base64
const imageBase64 = fs.readFileSync("./image.jpg").toString("base64");

const res = await fetch(endpoint, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    userId,
    secret,
    srcImage: imageBase64,
  }),
});

const data = await res.json().catch(() => ({}));
if (!res.ok) {
  throw new Error(`Request failed: ${res.status}`);
}

console.log("Recognized text:", data.value);

Python (requests)

import base64
import requests

endpoint = "https://api.pen-to-print.com/V1/notes"
user_id = "YOUR_USER_ID"
secret = "YOUR_API_SECRET"

with open("image.jpg", "rb") as f:
    src_image = base64.b64encode(f.read()).decode("utf-8")

resp = requests.post(
    endpoint,
    json={
        "userId": user_id,
        "secret": secret,
        "srcImage": src_image,
    },
    timeout=120,
)

resp.raise_for_status()
data = resp.json()
print(data.get("value", ""))

cURL (macOS / Linux)

# 1. Export credentials
export P2P_USER_ID="YOUR_USER_ID"
export P2P_API_SECRET="YOUR_API_SECRET"

# 2. Convert image to base64
export IMG_B64="$(base64 < image.jpg | tr -d '\n')"

# 3. Call the endpoint
curl -sS -X POST "https://api.pen-to-print.com/V1/notes" \
  -H "Content-Type: application/json" \
  -d "{\"userId\":\"$P2P_USER_ID\",\"secret\":\"$P2P_API_SECRET\",\"srcImage\":\"$IMG_B64\"}" \
  | cat