1.获取secretId、secretKey
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b25aa6a99279d3b33e8ee4a1cd7ab4c8.png)
2.代码
package com.demo.util;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.ocr.v20181119.OcrClient;
import com.tencentcloudapi.ocr.v20181119.models.VatInvoiceOCRRequest;
import com.tencentcloudapi.ocr.v20181119.models.VatInvoiceOCRResponse;
public class VatInvoiceOCR {
public static void main(String[] args) {
try {
String secretId = "腾讯云服务器secretId";
String secretKey = "腾讯云服务器secretKey";
Credential cred = new Credential(secretId, secretKey);
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("ocr.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
OcrClient client = new OcrClient(cred, "ap-shanghai", clientProfile);
VatInvoiceOCRRequest req = new VatInvoiceOCRRequest();
req.setIsPdf(true);
req.setImageUrl("img/pdf url");
VatInvoiceOCRResponse resp = client.VatInvoiceOCR(req);
System.out.println(VatInvoiceOCRResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
}