Soundbyte
Soundbyte

Reputation: 93

Detect Text in PDF/TIFF Files with Google Cloud Vision

I want to detect text in PDF and TIFF files with Google Cloud Vision, but from the looks of it that can only be done if you first store the file to the Google Cloud Storage. Can this also be done without storing it in the cloud?

Upvotes: 1

Views: 493

Answers (3)

laurian
laurian

Reputation: 809

It is now possible. Just convert your file into base64 and put it in your inputConfig's content. Supported formats are PDF, gif and tiff.

Upvotes: 0

F10
F10

Reputation: 2893

Currently, you need to store the content in a Google Cloud Storage Bucket. However, there's a feature request to read PDF files without having to be stored in the bucket. I suggest starring this issue and put a comment to indicate this could help you with your current scenario.

Upvotes: 2

Mark Redman
Mark Redman

Reputation: 24515

If you have the image (haven't tried PDF, which you might need to cover to an image) you can convert it to base 64 and send that..

some code snippets:

// MAIN ABBREVIATED CODE -----

var cloudVisionUrl = $"{annotationTextApiUrl}{annotationTextApiKey}";

            var imageBase64 = DoYourOwnImageToBase64(path);

            var client = new HttpClient();

            var requests = new ApiRequest { Requests = new List<Request> { new Request { Image = new Image {Content = imageBase64}, Features = new List<Feature> {new Feature {Type = "TEXT_DETECTION"}} } } };

            var httpResponse = await client.PostAsJsonAsync(cloudVisionUrl, requests);

// -----------------------------------------

public class ApiRequest
    {
        public ApiRequest()
        {
            Requests = new List<Request>();
        }

        [JsonProperty("requests")]
        public List<Request> Requests { get; set; }
    }

public class Request
    {
        [JsonProperty("image")]
        public Image Image { get; set; }

        [JsonProperty("features")]
        public List<Feature> Features { get; set; }
    }

public class Feature
    {
        [JsonProperty("type")]
        public string Type { get; set; }
    }

Upvotes: 0

Related Questions