Imbas API ialah ciri pemprosesan jauh daripada Look Scanned. Muat naik PDF untuk mencipta tugas imbasan, kemudian gunakan panggilan API yang ringkas untuk menyemak statusnya dan mendapatkan hasil imbasan yang realistik—sesuai untuk automasi dan integrasi pembangunan. Parameter seperti warna, hingar, kabur, sempadan dan sudut putaran boleh disesuaikan; ciri ini berfungsi dengan persekitaran pembangunan dan bahasa pengaturcaraan lazim, jadi fungsi teras Look Scanned mudah diintegrasikan ke dalam aplikasi atau perkhidmatan.
API Bearer Token
Contoh kod
interfaceScanConfig {
rotate?: number// degrees to rotate the documentrotate_var?: number// degrees to rotate the document randomlycolorspace?: 'gray' | 'sRGB'// the colorspace of the output imageblur?: number// the amount of blur to apply to the imagenoise?: number// the amount of noise to apply to the imageborder?: boolean// whether to add a border to the imagebrightness?: number// the brightness of the image. 1 is no changecontrast?: number// the contrast of the image. 1 is no changeresolution?: number// the resolution of the image in DPIoutput_format?: 'image/png' | 'image/jpeg'// the format of the output image
}
interfaceScanOptions {
config: ScanConfigwebhookUrl?: string// webhook URL to notify when job is completed
}
interfaceScanResponse {
jobID: string// UUID of the scan jobuserID: string// UUID of the user who created the jobcreatedAt: number// timestamp of job creationstatus: 'pending' | 'processing' | 'completed' | 'failed'config: ScanConfiginputUploadedAt?: number// timestamp when input file was uploadedcompletedAt?: number// timestamp when job was completedwebhookUrl?: string// webhook URL for notificationsuploadURL?: string// S3 presigned URL for file uploaddownloadURL?: string// S3 presigned URL for file download
}
asyncfunctionapiScan(pdfBlob: Blob, scanOptions: ScanOptions, token: string): Promise<ScanResponse> {
const response = awaitfetch('https://api.lookscanned.io/v1/scan-jobs', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
},
body: JSON.stringify(scanOptions)
})
constresult: ScanResponse = await response.json()
// PUT PDF Blob to upload URLconst uploadURL = result.uploadURLawaitfetch(uploadURL, {
method: 'PUT',
headers: {
'Content-Type': 'application/pdf',
'Content-Length': pdfBlob.size.toString()
},
body: pdfBlob
})
// get scan job statusconst jobStatusResponse = awaitfetch(`https://api.lookscanned.io/v1/scan-jobs/${result.jobID}`, {
headers: {
'Authorization': `Bearer ${token}`
}
})
returnawait jobStatusResponse.json()
}
import requests
defapi_scan(pdf_file, scan_options, token):
# Create scan job
response = requests.post(
'https://api.lookscanned.io/v1/scan-jobs',
headers={'Authorization': f'Bearer {token}'},
json=scan_options
)
result = response.json()
# Upload PDF to presigned URL
upload_url = result['uploadURL']
requests.put(
upload_url,
headers={
'Content-Type': 'application/pdf',
'Content-Length': str(len(pdf_file))
},
data=pdf_file
)
# Get scan job status
job_status = requests.get(
f'https://api.lookscanned.io/v1/scan-jobs/{result["jobID"]}',
headers={'Authorization': f'Bearer {token}'}
)
return job_status.json()
# Example usageif __name__ == "__main__":
withopen('document.pdf', 'rb') as f:
pdf_content = f.read()
options = {
'config': {
# Optional parameters:# 'rotate': 0, # degrees to rotate the document# 'colorspace': 'gray', # gray or sRGB# 'resolution': 300, # DPI# 'rotate_var': 0, # random rotation variance in degrees# 'blur': 0, # amount of blur# 'noise': 0, # amount of noise# 'border': False, # whether to add border# 'brightness': 1, # 1 is no change# 'contrast': 1, # 1 is no change# 'output_format': 'image/png' # image/png or image/jpeg
},
'webhookUrl': 'https://example.com/webhook'
}
result = api_scan(pdf_content, options, 'your-api-token')
print(f"Scan job created with ID: {result['jobID']}")
# Set your API token and PDF file as environment variablesexport LOOKSCANNED_API_TOKEN='your_api_token_here'# Create a new scan job
curl -X POST 'https://api.lookscanned.io/v1/scan-jobs' \
-H "Authorization: Bearer ${LOOKSCANNED_API_TOKEN}" \
-H 'Content-Type: application/json' \
-d '{
"config": {
"rotate": 0,
"rotate_var": 1,
"colorspace": "gray",
"blur": 0.2,
"noise": 0.1,
"border": true,
"brightness": 1.0,
"contrast": 1.0,
"resolution": 300,
"output_format": "image/jpeg"
},
"webhookUrl": "https://your-domain.com/webhook"
}'# Response will include uploadURL and jobID# {# "jobID": "550e8400-e29b-41d4-a716-446655440000",# "userID": "446655440000-e29b-41d4-a716-550e8400",# "createdAt": 1616161616,# "status": "created",# "uploadURL": "...",# "config": { ... }# }# Upload PDF file to the presigned URL
curl -X PUT 'PRESIGNED_UPLOAD_URL' \
-H 'Content-Type: application/pdf' \
-H "Content-Length: PDF_FILE_SIZE" \
--data-binary "@path/to/your/file.pdf"# Check job status
curl 'https://api.lookscanned.io/v1/scan-jobs/JOB_ID' \
-H "Authorization: Bearer ${LOOKSCANNED_API_TOKEN}"# Response will include status and downloadURL when completed# {# "jobID": "550e8400-e29b-41d4-a716-446655440000",# "status": "completed",# "downloadURL": "...",# ...# }# Download the PDF
curl -o scanned.pdf 'DOWNLOAD_URL'