How to extract text from PDF in Flutter

{"error":{"code":"errorItemNotFound","message":"Can't find file located at '/data/user/0/com.example.tts/cache/file_picker/wavenet.pdf'.","description":"Operation Failed. Item Not Found.","innerError":{"requestId":null,"date":"2021-12-01T12:54:17.7478679Z"}}}

I am using the group docs parser rest api to extract text from the whole document and i am getting the above error. Here is the code i am using to send the http post request.

Future<String?> getParsedText(File? file) async {
var accessToken = await generateJwt();
// print(accessToken);
var url = Uri.parse('https://api.groupdocs.cloud/v1.0/parser/text');
var body = jsonEncode({
  "FileInfo": {
    "FilePath": file!.absolute.path,
  }
});
var headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer $accessToken',
};
var response = await http.post(url, body: body, headers: headers);
if (response.statusCode == 200) {
  print(response.body);
} else {
  print(response.body);
  print('reason : ${response.reasonPhrase}');
  print(response.statusCode);
}

}

@hardhguy

Please share your input document with us as well. We will test the scenario at our end and will guide you accordingly.

wavenet.pdf (33.6 KB)

I am using this api with flutter and testing the app on android and i have used multiple different documents but the api is giving the same response. I have attached the input document.

@hardhguy

It seems your file path is not correct. Please note GroupDocs.Parser API expects file from cloud storage. So kindly double check the file path/availability on the cloud storage. It will resolve the issue.

Upload File to Cloud Storage

curl -X PUT "https://api.groupdocs.cloud/v1.0/parser/storage/file/wavenet.pdf" 
-H "accept: application/json" 
-H "authorization: Bearer [Access_Token]" 
-H "Content-Type: multipart/form-data" 
-H "x-aspose-client: Containerize.Swagger" 
-F "file"="@C:/Temp/wavenet.pdf"

Extract Text from Cloud Storage

curl -X POST "https://api.groupdocs.cloud/v1.0/parser/text" -H "accept: application/json" -H "authorization: Bearer [Access_Token]" 
-H "Content-Type: application/json" 
-H "x-aspose-client: Containerize.Swagger" 
-d "{ \"FileInfo\": { \"FilePath\": \"wavenet.pdf\" }}"

Thanks for the help now its working

1 Like