Pages in scanned documents are often times not oriented correctly because of a mistake during the manual scanning process. These orientation issues make reading the document more cumbersome and require the reader to manually rotate the document. Our new /document/autorotate Robot can automatically correct the orientation based on the text available in the document and improve user experience.

Using 🤖/document/autorotate

Let's start with an example document. The following screenshot shows a scanned document with a wrong orientation that is the result of the paper being fed incorrectly into the scanner. Instead of the text being upright, we can see that the text is oriented sideways.

Window showing a scanned document with a wrong orientation.

In order to correct the problem using the /document/autorotate Robot, we can use the following Template.

{
  "steps": {
    ":original": {
      "robot": "/upload/handle"
    },
    "autorotate": {
      "use": ":original",
      "robot": "/document/autorotate",
      "result": true
    },
    "thumbnail": {
      "use": "autorotate",
      "robot": "/document/thumbs",
      "width": 200,
      "format": "png",
      "resize_strategy": "fit",
      "trim_whitespace": false,
      "result": true
    },
    "export": {
      "use": [":original", "autorotate", "thumbnail"],
      "robot": "/s3/store",
      "credentials": "YOUR_AWS_CREDENTIALS",
      "path": "my_target_folder/${unique_prefix}/${file.url_name}"
    }
  }
}

In the Template above, we first pass the document through the /document/autorotate Robot. It does not require you to specify any additional parameters. If the document is already oriented correctly or the Robot cannot infer the correct orientation, it leaves the document unchanged and allows it to proceed to the next step without a fallback.

Next, we pass the corrected document through the /document/thumbs Robot to generate a thumbnail of the document, which can be used to preview the document in a dashboard, for example.

Finally, the original file, the corrected document, and the thumbnail are passed through the /s3/store Robot to store the document in an S3 bucket. Of course, you can replace this with any of our other file exporting Robots, which support Google Cloud Storage, Azure Blob Storage, and Digital Ocean Spaces, among others.

Once our example file has been processed, we can see that the orientation has been corrected and the document is now upright:

Window showing a scanned document with the corrected orientation.

Supported formats

This Robot not only supports PDFs, but also the most common image formats: JPEG, PNG, GIF, TIFF, WebP, BMP, and JPEG 2000. This allows you to correct orientation issues in documents that were photographed using a mobile phone or camera. To use this Robot with other formats, use 🤖/document/convert first to convert the document into a PDF or a supported image format.

Please be aware that documents and images must contain sufficient text to infer the correct orientation. Images without text will not be rotated.

Conclusion

With the new /document/autorotate Robot, you can automatically correct the orientation of documents and images. This is a great way to improve the readability of scanned and photographed documents and is a useful addition to your document processing pipeline.

For a comprehensive look at everything available to you with the Robot, check out its documentation.