0
votes

Im using cloud vision to detect text in a pdf file.Ive used the code provided in the documentation but it throws an error saying unsupported input file format.im using 100% sure the file is pdf and i even used the sample resource file https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/vision/cloud-client/detect/resources/kafka.pdf what should i do?????????

EDIT

This is the code taken staright from the documentation which i used.

const vision = require('@google-cloud/vision').v1;

const client = new vision.ImageAnnotatorClient();


const gcsSourceUri = `gs://${bucketName}/${fileName}`;
const gcsDestinationUri = `gs://${bucketName}/${outputPrefix}/`;

const inputConfig = {
  // Supported mime_types are: 'application/pdf' and 'image/tiff'
  mimeType: 'application/pdf',
  gcsSource: {
    uri: gcsSourceUri,
  },
};
const outputConfig = {
  gcsDestination: {
    uri: gcsDestinationUri,
  },
};
const features = [{type: 'DOCUMENT_TEXT_DETECTION'}];
const request = {
  requests: [
    {
      inputConfig: inputConfig,
      features: features,
      outputConfig: outputConfig,
    },
  ],
};

const [operation] = await client.asyncBatchAnnotateFiles(request);
const [filesResponse] = await operation.promise();
const destinationUri =
  filesResponse.responses[0].outputConfig.gcsDestination.uri;
console.log('Json saved to: ' + destinationUri);
2
Can you post your code and the exact error in your question? - Brendan
@Brendan Error: Unsupported input file format thats error you get when you run this code - SujithaW
So you moved that kafka.pdf file from github to your personal gcs bucket and then ran DOCUMENT_TEXT_DETECTION on that file in your gcs bucket? Then you called GetOperation to see the error "Unsupported input file format." - Brendan
ya i feel like i done something stupid... @Brendan anyway i ended up using image detection by just converting the pdf to an image - SujithaW

2 Answers

1
votes

I tried moving that kafka.pdf to my gcs bucket and ran the python sample code, which worked as expected. Maybe something went wrong with the kafka.pdf file when you moved it into the gcs bucket.

Try using the sample file they provide to see if it works for you 'gs://cloud-samples-data/vision/pdf_tiff/census2010.pdf'. The census file works for me as well.

1
votes

I was getting the same response from the batch annotation service on otherwise valid PDF files. In my case it had to do with copy/pasting the example code from the node sample for file uploading to google cloud storage, and including the keys for gzip and cacheControl

It doesn't look like you've included those values, but after a lot of head scratching I ended up finding that if I uploaded my pdfs without those options then the annotation service tolerated them, not an exact reproduction but I hope it leads to progress for you :)