• API 功能
    • 通用的识别接口, 支持标准 PDF 文件解析;
    • 多种格式输出,支持 TEXT HTML XML TAG;
    • HTML 包含完美排版格式;
    • 基于机器学习不断提高的识别率;
    • 1M 文件毫秒级识别性能;
    • 全接口支持 HTTPS(TLS v1.0 / v1.1 / v1.2 / v1.3);
    • 全面兼容 Apple ATS;
    • 全国多节点 CDN 部署;
    • 接口极速响应,多台服务器构建 API 接口负载均衡。
    • 接口调用状态与状态监控
  • API 文档

    接口地址: https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}

    返回格式: application/json; charset=utf-8

    请求方式: POST

    请求协议: HTTPS

    请求示例: https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}

    数据预览: https://www.gugudata.com/preview/pdf2format

    接口测试: https://api.gugudata.com/imagerecognition/pdf2format/demo

    请求参数(POST 请求参数以 application/x-www-form-urlencoded 格式、文件流以 formdata 格式传递,具体可参见下方示例代码)

    参数名 参数类型 是否必须 默认值 备注
    appkey string YOUR_APPKEY 付费后获取的 APPKEY
    type string YOUR_VALUE 定义输出格式,可选 text|html|xml|tag
    pdffile file YOUR_VALUE 文件格式参数,待转换的 PDF 文件

    返回参数

    参数名 参数类型 备注
    DataStatus.StatusCode int 接口返回状态码
    DataStatus.StatusDescription string 接口返回状态说明
    DataStatus.ResponseDateTime string 接口数据返回时间
    DataStatus.DataTotalCount int 此条件下的总数据量,一般用于分页计算
    Data.Data string 接口解析 PDF 返回数据,格式由 type 参数决定
  • 接口 HTTP 响应标准状态码
    状态码 状态码解释 备注
    200 接口正常响应 业务状态码参见下方 接口自定义状态码
    403 / 429 请求频率超限 CDN 层通过 IP 请求频率智能判断,一般不同 IP 高频请求不会触发此状态码。
  • 接口自定义状态码
    自定义状态码 自定义状态码解释 备注
    100 正常返回 可通过判断此状态码断言接口正常返回。
    -1 请求失败 请求处理请求失败。
    501 参数错误 请检查您传递的参数个数以及参数类型是否匹配。
    429 / 502 请求频率受限 一般建议同一个 IP 每秒请求不超过 5 次 (QPS<=5),我们不限制同一个 key 的请求总次数,但当单位时间内同一个 IP 请求次数过多,或 AI CDN 判定为恶意抓取数据、流量攻击等异常时,CDN 会返回此状态码,请适当降低请求频率。如有特殊大并发请求场景需求,可联系我们添加白名单处理。
    503 APPKEY 权限超限/订单到期 请至开发者中心检查您的 APPKEY 是否到期或是否权限超限。
    504 APPKEY 错误 请检查传递的 APPKEY 是否为开发者中心获取到的值。
    505 请求的次数超出接口限制 请检查对应接口是否有请求次数限制以及您目前的接口请求剩余次数。
    900 接口内部响应错误 接口可用性为 99.999%,如获取到此状态码请邮件联系我们。
  • 请求示例代码
    curl --location 'https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}' \
    --form 'pdffile=@"localfile_path.png"'
    CURL *curl;
    CURLcode res;
    curl = curl_easy_init();
    if(curl) {
      curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
      curl_easy_setopt(curl, CURLOPT_URL, "https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}");
      curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
      curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
      struct curl_slist *headers = NULL;
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
      curl_mime *mime;
      curl_mimepart *part;
      mime = curl_mime_init(curl);
      part = curl_mime_addpart(mime);
      curl_mime_name(part, "pdffile");
      curl_mime_filedata(part, "localfile_path.png");
      curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
      res = curl_easy_perform(curl);
      curl_mime_free(mime);
    }
    curl_easy_cleanup(curl);
    var formdata = new FormData();
    formdata.append("pdffile"), fileInput.files[0], "localfile_path.png");
    var requestOptions = {
      method: 'POST',
      body: formdata,
      redirect: 'follow'
    };
    fetch("https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}", requestOptions)
      .then(response => response.text())
      .then(result => console.log(result))
      .catch(error => console.log('error', error));
    var options = new RestClientOptions("https://api.gugudata.com")
    {
     MaxTimeout = -1,
    };
    var client = new RestClient(options);
    var request = new RestRequest("/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}", Method.Post);
    request.AlwaysMultipartFormData = true;
    request.AddFile(pdffile, "localfile_path.png");
    RestResponse response = await client.ExecuteAsync(request);
    Console.WriteLine(response.Content)
    package main
    import (
      "fmt"
      "bytes"
      "mime/multipart"
      "os"
      "path/filepath"
      "io"
      "net/http"
      "io/ioutil"
    )
    func main() {
      url := "https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}"
      method := "POST"
      payload := &bytes.Buffer{}
      writer := multipart.NewWriter(payload)
      file, errFile1 := os.Open("localfile_path.png")
      defer file.Close()
      part1,
      errFile1 := writer.CreateFormFile("pdffile",filepath.Base("localfile_path.png"))
      _, errFile1 = io.Copy(part1, file)
      if errFile1 != nil {
        fmt.Println(errFile1)
        return
      }
      err := writer.Close()
      if err != nil {
        fmt.Println(err)
        return
      }
      client := &http.Client {
      }
      req, err := http.NewRequest(method, url, payload)
      if err != nil {
        fmt.Println(err)
        return
      }
      req.Header.Set("Content-Type", writer.FormDataContentType())
      res, err := client.Do(req)
      if err != nil {
        fmt.Println(err)
        return
      }
      defer res.Body.Close()
      body, err := ioutil.ReadAll(res.Body)
      if err != nil {
        fmt.Println(err)
        return
      }
      fmt.Println(string(body))
    }
    OkHttpClient client = new OkHttpClient().newBuilder().build();
       MediaType mediaType = MediaType.parse("text/plain");
       RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("pdffile","localfile_path.png",
       RequestBody.create(MediaType.parse("application/octet-stream"),
       new File("localfile_path.png"))).build();
    Request request = new Request.Builder()
     .url("https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}")
     .method("POST", body).build();
    Response response = client.newCall(request).execute();
    var form = new FormData();
    form.append("pdffile", fileInput.files[0], "localfile_path.png");
    var settings = {
        "url": "https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}",
        "method": "POST",
        "timeout": 0,
        "processData": false,
        "mimeType": "multipart/form-data",
        "contentType": false,
        "data": form
    };
    $.ajax(settings).done(function (response) {
    console.log(response);
    });
    #import <Foundation/Foundation.h>
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}"]
      cachePolicy:NSURLRequestUseProtocolCachePolicy
      timeoutInterval:10.0];
    NSArray *parameters = @[@{ @"name": @"pdffile", @"fileName": @"localfile_path.png" } ];
    NSString *boundary = @"----WebKitFormBoundary7MA4YWxkTrZu0gW";
    NSError *error;
    NSMutableString *body = [NSMutableString string];
    for (NSDictionary *param in parameters) {
      [body appendFormat:@"--%@\r\n", boundary];
      if (param[@"fileName"]) {
        [body appendFormat:@"Content-Disposition:form-data; name=\"%@\"; filename=\"%@\"\r\n", param[@"name"], param[@"fileName"]];
        [body appendFormat:@"Content-Type: %@\r\n\r\n", param[@"contentType"]];
        [body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];
        if (error) {
          NSLog(@"%@", error);
        }
      } else {
        [body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
        [body appendFormat:@"%@", param[@"value"]];
      }
    }
    [body appendFormat:@"\r\n--%@--\r\n", boundary];
    NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:postData];
    [request setHTTPMethod:@"POST"];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
    completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
      if (error) {
        NSLog(@"%@", error);
        dispatch_semaphore_signal(sema);
      } else {
        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
        NSError *parseError = nil;
        NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
        NSLog(@"%@",responseDictionary);
        dispatch_semaphore_signal(sema);
      }
    }];
    [dataTask resume];
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
    import requests
    url = "https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}"
    payload={}
    files=[('imagefile',('   pdffile',open('localfile_path.png','rb'),'image/png'))]
    headers = {}
    response = requests.request("POST", url, headers=headers, data=payload, files=files)
    print(response.text)
    require "uri"
    require "net/http"
    url = URI("https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}")
    https = Net::HTTP.new(url.host, url.port)
    https.use_ssl = true
    request = Net::HTTP::Post.new(url)
    form_data = [['pdffile', File.open('localfile_path.png')]]
    request.set_form form_data, 'multipart/form-data'
    response = https.request(request)
    puts response.read_body
    let parameters = [["key": "pdffile",
       "src": "localfile_path.png",
       "type": "file"]] as [[String: Any]]
    let boundary = "Boundary-\(UUID().uuidString)"
    var body = ""
    var error: Error? = nil
    for param in parameters {
     if param["disabled"] != nil { continue }
     let paramName = param["key"]!
     body += "--\(boundary)\r\n"
     body += "Content-Disposition:form-data; name=\"\(paramName)\""
     if param["contentType"] != nil {
       body += "\r\nContent-Type: \(param["contentType"] as! String)"
     }
     let paramType = param["type"] as! String
     if paramType == "text" {
       let paramValue = param["value"] as! String
       body += "\r\n\r\n\(paramValue)\r\n"
     } else {
       let paramSrc = param["src"] as! String
       let fileData = try NSData(contentsOfFile: paramSrc, options: []) as Data
       let fileContent = String(data: fileData, encoding: .utf8)!
       body += "; filename=\"\(paramSrc)\"\r\n"
         + "Content-Type: \"content-type header\"\r\n\r\n\(fileContent)\r\n"
     }
    }
    body += "--\(boundary)--\r\n";
    let postData = body.data(using: .utf8)
    var request = URLRequest(url: URL(string: "https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}")!,timeoutInterval: Double.infinity)
    request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
    request.httpMethod = "POST"
    request.httpBody = postData
    let task = URLSession.shared.dataTask(with: request) { data, response, error in
     guard let data = data else {
       print(String(describing: error))
       return
     }
     print(String(data: data, encoding: .utf8)!)
    }
    task.resume()
    var request = require('request');
    var fs = require('fs');
    var options = {
      'method': 'POST',
      'url': 'https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}',
      'headers': {
      },
      formData: {
        'pdffile': {
          'value': fs.createReadStream('localfile_path.png'),
          'options': {
            'filename': 'localfile_path.png',
            'contentType': null
          }
        }
      }
    };
    request(options, function (error, response) {
      if (error) throw new Error(error);
      console.log(response.body);
    });
    <?php
    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_POSTFIELDS => array('pdffile'=> new CURLFILE('localfile_path.png')),
    ));
    $response = curl_exec($curl);
    curl_close($curl);
    echo $response;
  • 常见问题 Q&A
    • Q: 数据请求有缓存吗?

      A: 我们为所有数据请求提供实时响应。对于定期更新的数据,我们在其更新周期内实施缓存策略,以优化性能。

    • Q: 如何保证请求时 key 的安全性?

      A: 我们建议将对 API 的请求操作放置在您的应用程序后端。这样,前端请求只与您的后端服务交互,确保了更高的安全性和易于维护的架构。

    • Q: 接口可以用于哪些开发语言?

      A: 我们的接口支持所有能进行网络请求的开发语言,便于在各类项目中快速整合数据。

    • Q: 接口的性能可以保证吗?

      A: 我们的接口后台使用与商业级项目相同的架构,保证了稳定且高效的性能。您可以通过访问测试接口了解更多性能信息。

  • 服务协议以及服务免责声明

    用户应当充分阅读 服务协议 以及 服务免责声明 ,用户购买与使用咕咕数据 API 服务亦视为接受本协议。

  • 技术支持
    • 技术支持邮箱: support@gugudata.com
    • 微信客服: 客服链接

业务相关接口推荐

稳定提供服务 10 年 通用 PDF 文件流 OCR 到文本
  • 高可用图像识别引擎
  • 基于机器学习 / 高效文本提取
  • 1999元/年限时折扣 999元/年
查看详情 被调用于 1 秒前
50% 折扣
PDF 转 HTML
  • 高效 PDF 转 HTML 工具
  • 生成HTML站点 / 可永久存储
  • 999元/年限时折扣 499元/年
查看详情 被调用于 3 秒前
50% 折扣
PDF 分割拆分
  • 高效的 PDF 分割工具
  • 高效处理 / 可永久存储
  • 999元/年限时折扣 499元/年
查看详情 被调用于 6 秒前
50% 折扣
稳定提供服务 10 年 通用 PDF 文件流 OCR 到 Word
  • 高可用图像识别引擎
  • 基于机器学习 / 超精准识别率
  • 2999元/年限时折扣 999元/年
查看详情 被调用于 3 秒前
30% 折扣