我已经用C#编写了以下代码,用于使用Google视觉api将pdf转换为json。Api一次打一个pdf,我有成千上万个pdf文件。这是非常耗时的过程。
我想知道是否有一种方法可以批量处理所有PDF,而不是为要转换的每个PDF单独的api调用?
var asyncRequest = new AsyncAnnotateFileRequest
{
InputConfig = new InputConfig
{
GcsSource = new GcsSource
{
Uri = gcsSourceUri
},
// Supported mime_types are: 'application/pdf' and 'image/tiff'
MimeType = "application/pdf"
},
OutputConfig = new OutputConfig
{
// How many pages should be grouped into each json output file.
BatchSize = 2,
GcsDestination = new GcsDestination
{
Uri = $"gs://{gcsDestinationBucketName}/Converted/{gcsDestinationPrefixName}"
}
}
};
asyncRequest.Features.Add(new Feature
{
Type = Feature.Types.Type.DocumentTextDetection
});
List<AsyncAnnotateFileRequest> requests =
new List<AsyncAnnotateFileRequest>();
requests.Add(asyncRequest);
var operation = client.AsyncBatchAnnotateFiles(requests);
//Console.WriteLine("Waiting for the operation to finish");
operation.PollUntilCompleted();
您正在调用异步方法,因此您不必等待操作完成。删除以下行:operation.PollUntilCompleted();
只需发送您的所有请求,并确保每个请求都指定一个唯一的目的地。