API 扫描

API 扫描是 Look Scanned 提供的一项全新功能,通过简单的 API 接口调用,即可实现将 PDF 文档转换为仿真扫描件效果,适用于自动化流程和开发集成。它支持多种自定义参数调整,包括颜色、噪点、模糊、边框和旋转角度等,满足不同场景需求;API 扫描兼容各种开发环境和主流编程语言,让开发者轻松将 Look Scanned 的核心功能集成到自己的应用或服务中。

API Bearer Token

代码示例

TypeScript TypeScript
Python Python
curl cURL
interface ScanConfig {
  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
}

interface ScanOptions {
  config: ScanConfig
  webhookUrl?: string        // webhook URL to notify when job is completed
}

interface ScanResponse {
  jobID: string              // UUID of the scan job
  userID: string             // UUID of the user who created the job
  createdAt: number          // timestamp of job creation
  status: '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
}

async function apiScan(pdfBlob: Blob, scanOptions: ScanOptions, token: string): Promise<ScanResponse> {
  const response = await fetch('https://api.lookscanned.io/v1/scan-jobs', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${token}`
    },
    body: JSON.stringify(scanOptions)
  })
  const result: ScanResponse = await response.json()

  // PUT PDF Blob to upload URL
  const uploadURL = result.uploadURL
  await fetch(uploadURL, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/pdf',
      'Content-Length': pdfBlob.size.toString()
    },
    body: pdfBlob
  })
  
  // get scan job status
  const jobStatusResponse = await fetch(`https://api.lookscanned.io/v1/scan-jobs/${result.jobID}`, {
    headers: {
      'Authorization': `Bearer ${token}`
    }
  })
  return await jobStatusResponse.json()
}

试一试

Grayscale
image/jpeg
{
  "config": {
    "rotate": 1,
    "rotate_var": 0.5,
    "colorspace": "gray",
    "blur": 0,
    "noise": 0,
    "border": false,
    "brightness": 1.3,
    "contrast": 1.3,
    "resolution": 150,
    "output_format": "image/jpeg"
  }
}