API 扫描是 Look Scanned 提供的一项全新功能,通过简单的 API 接口调用,即可实现将 PDF 文档转换为仿真扫描件效果,适用于自动化流程和开发集成。它支持多种自定义参数调整,包括颜色、噪点、模糊、边框和旋转角度等,满足不同场景需求;API 扫描兼容各种开发环境和主流编程语言,让开发者轻松将 Look Scanned 的核心功能集成到自己的应用或服务中。
API Bearer Token
代码示例
TypeScript
Python
cURL
interfaceScanConfig {
rotate?: number// degrees to rotate the document
rotate_var?: number// degrees to rotate the document randomly
colorspace?: 'gray' | 'sRGB'// the colorspace of the output image
blur?: number// the amount of blur to apply to the image
noise?: number// the amount of noise to apply to the image
border?: boolean// whether to add a border to the image
brightness?: number// the brightness of the image. 1 is no change
contrast?: number// the contrast of the image. 1 is no change
resolution?: number// the resolution of the image in DPI
output_format?: 'image/png' | 'image/jpeg'// the format of the output image
}
interfaceScanOptions {
config: ScanConfig
webhookUrl?: 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: ScanConfig
inputUploadedAt?: number// timestamp when input file was uploaded
completedAt?: number// timestamp when job was completed
webhookUrl?: string// webhook URL for notifications
uploadURL?: string// S3 presigned URL for file upload
downloadURL?: 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()
}