# `deskew`
Automatically detect and correct document skew
## Usage
> pdftl `` `deskew` `[...]` `[max_skew=]` `[dpi=]` `output` ``
## Details
The `deskew` operation automatically detects rotational misalignment (skew)
commonly found in scanned documents and aligns the text horizontally.
### How it works
This operation runs a page-level hybrid vector/raster deskew:
1. The page is rendered at a low resolution to analyze its layout.
2. A projection profile variance analysis (Radon-style line search)
detects the dominant text angle within the specified `max_skew` range.
3. If the active text region or page size is too small for a high-fidelity line search,
the page is dynamically re-rendered at a higher resolution (up to 600 DPI) to prevent
coarse-grain estimation and boundary errors.
4. The entire page coordinate space is rotated around its visual center
to correct the alignment.
5. Vector content, high-resolution image assets, and text rendering remains
lossless because the coordinate grid itself is rotated.
6. Clickable hyperlinks, highlights, and annotations are transformed
automatically to match their new visual locations.
### Parameters
* `max_skew=` (default: 10.0) — The maximum search limit for skew detection,
in degrees. Restricting this window speeds up analysis and avoids false-positive
rotations on non-standard layouts.
* `dpi=` (default: 75) — Resolution of the rasterized page used for
skew analysis. 75 DPI is generally optimal for fast, robust line detection.
* `max_render_dpi=` (default: 600) — Ceiling on the resolution used when
a small text region is re-rendered for closer analysis. This controls how
much detail is *captured*; it is independent of `coarse_res`/`fine_res`
below, which control how much of that captured detail is *analyzed*.
* `coarse_res=` (default: 300) — Target pixel footprint (long edge) used
for the initial coarse angle search. Lower values are faster but risk
missing the correct angle's neighborhood on very fine or sparse text.
* `fine_res=` (default: 600) — Target pixel footprint (long edge) used
for the fine, sub-degree angle search. Higher values improve precision
(reducing residual jitter of a few tenths of a degree) at the cost of
slower analysis; lower values trade some precision for speed.
## Examples
> Automatically detect and correct skew on all pages.
```
pdftl in.pdf deskew output out.pdf
```
> Automatically deskew only the even pages, limiting search to 5 degrees.
```
pdftl in.pdf deskew even max_skew=5 output out.pdf
```
> Deskew pages 1 to 3 with a higher analysis resolution of 150 DPI.
```
pdftl in.pdf deskew 1-3 dpi=150 output out.pdf
```
> Prioritize speed over precision by using smaller search footprints.
```
pdftl in.pdf deskew coarse_res=150 fine_res=300 output out.pdf
```
**Tags**: content_modification, geometry
*Source: pdftl.operations.deskew*
*Read online: [https://pdftl.readthedocs.io/en/latest/operations/deskew.html](https://pdftl.readthedocs.io/en/latest/operations/deskew.html)*
*Type: Operation*