Straighten Document Photos and Save as PDF
A photo taken at an angle turns the page into a trapezoid, and the lines of text run downhill. Drag the four green dots onto the corners of the document and the page is squared up, cleaned to black and white, and saved as a PDF or JPEG.
Published: / Published by the HakoTools team
Drop a photo of your document here, or
JPEG, PNG and WebP work. Most browsers cannot open HEIC, the iPhone default, so export or convert that photo to JPEG first. Photos never leave your device.
How it works
What does this do to a photo of a document?
It squares the page up. You mark the four corners of the document in your photo, and the tool maps that quadrilateral onto a rectangle, so a page shot from an angle comes out looking like it was photographed from directly above, with the lines of text running level.
It then cleans the result up — black and white, greyscale or the original colour — and saves it as a PDF or a JPEG. Several photos can go into one PDF. Everything happens in this browser tab: no app, no account, and the photo is never uploaded, which matters when the document is a contract, a payslip or an ID card.
How to use it
- Drop the photo onto the box above, or press Choose a photo
- Drag the four green dots onto the corners of the document, clockwise from the top left. A magnifier appears while you drag, so you can put a corner within a pixel or two. Without a mouse, pick a corner with the 1-4 keys and move it with the arrow keys, holding Shift for 10px steps
- Choose a finish (black and white, greyscale or colour) and set the contrast
- Press Straighten the document and check the preview
- Save it with Download PDF or Download JPEG. For a multi-page PDF, press Keep this page and add another document and load the next photo
How does the perspective correction work?
The four corners you place are enough to solve a 3×3 projective transform, also called a homography. It maps the plane of the paper in your photo onto the plane of a rectangle, which is exactly the distortion a camera introduces when the page is not parallel to the sensor.
A point (x, y) in the photo lands at (X, Y) in the output:
- X = (h11x + h12y + h13) / (h31x + h32y + 1)
- Y = (h21x + h22y + h23) / (h31x + h32y + 1)
The divisor is what makes it different from the rotate-and-stretch transforms in a photo editor: it lets the far edge of the page be smaller than the near edge. There are eight unknowns, h11 through h32, and each corner gives two equations, so four corners pin the answer down exactly. It is solved with Gaussian elimination and partial pivoting. If three or more of your corners fall on a straight line the equations have no unique answer, and the tool stops rather than producing a smear.
How is the output size decided?
From the lengths of the sides you marked. The longer of the top and bottom edges becomes the width, the longer of the left and right edges becomes the height, and the whole thing is scaled down if needed so the long side is at most 2000 px. Taking the longer edge rather than the average means the near part of the page, which is the sharper part, is not squeezed.
With corners at (100, 120), (900, 60), (960, 700) and (60, 760), the output comes out at 902 × 643 px, and the matrix solves to h11=1.176, h12=0.073, h13=-126.37, h21=0.087, h22=1.165, h23=-148.58, h31=0.000028, h32=0.000201. The last two being non-zero is the perspective: if you had photographed the page square on, they would both be zero.
The scan itself runs the transform backwards. It walks the output pixel by pixel and asks where each one came from in the photo, because going the other way leaves gaps wherever the image is stretched. In the example above, the output pixel at (451, 321) comes from (502.4, 390.9) in the photo — not a whole number, so the four surrounding pixels are blended by bilinear interpolation to keep thin strokes from turning jagged.
In the PDF the page is laid out on A4 (210 × 297 mm, 8.27 × 11.69 in), portrait or landscape depending on the shape of your result. Filling the long side of an A4 sheet with 2000 px works out at roughly 171 dpi, which is comfortably readable and prints cleanly, but is below the 300 dpi that archival scanning asks for.
Black and white, greyscale or colour?
Black and white for anything that is just text — it is the sharpest and by far the smallest file. Greyscale when shading carries meaning, such as a stamp or pencil. Colour when the colour itself is the information.
| Finish | Good for | What it does |
|---|---|---|
| Black & white | Contracts, forms, receipts, lecture notes | Converts to brightness, picks a threshold with Otsu's method, and snaps every pixel to black or white |
| Greyscale | Signed and stamped pages, pencil, photos in a report | Keeps the brightness of every pixel, drops the colour |
| Colour | Highlighted pages, colour charts, business cards | Keeps RGB and only applies the contrast setting |
Brightness uses the ITU-R BT.601 weighting, Y = 0.299R + 0.587G + 0.114B. Green weighs most because the eye is most sensitive to it, so pure red (255, 0, 0) reads as 76.2 and pure green (0, 255, 0) as 149.7. The black and white threshold is not a fixed number: Otsu's method builds a 256-level histogram of the corrected page and picks the split that maximises the variance between the two groups. On a photo with a shadow across it, the threshold moves to wherever that particular page separates paper from ink.
If letters come out broken, raise the contrast before blaming the threshold. Contrast multiplies the distance from mid-grey 128 by 259 × (c + 255) ÷ (255 × (259 − c)). At c = 50 that factor is about 1.48, so paper sitting at brightness 160 is pushed up to 175 while ink at 90 drops to 72. The gap Otsu's method has to find widens from 70 to 103 levels, which is what makes the threshold land in the right place.
Can I put several pages in one PDF?
Yes. After each correction, press Keep this page and add another document, load the next photo and repeat; the page counter on the download button shows how many are held. The pages go into the PDF in the order you added them, and each one keeps its own corner placement and finish, so a stapled contract shot page by page comes out as one file.
Every page is held in this tab only. Reloading the page loses them, and nothing is saved between visits.
When is this the wrong tool?
When the paper is not flat. A projective transform assumes a plane, so it can undo any angle you shot a flat page from, but it cannot flatten a curled receipt, a creased fold or the curve near the spine of an open book. Those need a different kind of model, and the text near the bend will stay distorted.
It is also the wrong tool if you need the words rather than the picture. There is no OCR here, so the output is an image in a PDF wrapper. And if the page is already square on — a screenshot, or something from a flatbed scanner — there is nothing to correct, and re-encoding it here only costs you quality.
Notes
- JPEG, PNG and WebP are accepted. HEIC, the iPhone default, cannot be opened by most browsers, so export the photo as JPEG first
- Photos are scaled down to 3000px on the long side before scanning, and the corrected page to 2000 px, to keep the browser responsive
- Anything outside the four corners is cropped away. Leave room if you want a stapled edge or a margin note in the result
- No OCR: the text in the PDF cannot be selected, copied or searched
- The work runs on your own CPU, so a high-resolution photo can take a few seconds
- Nothing is uploaded, stored or logged. Close the tab and the photos are gone
Frequently asked questions
- Do I have to install a scanner app?
- No. The page you are on does the work: the correction, the black and white conversion and the PDF are all built by JavaScript running in this browser tab. There is no app to install, no account to create and no upload, so it also works on a borrowed or locked-down computer where you cannot install anything.
- Does it find the edges of the document by itself?
- No, you place the four corners yourself. Automatic edge detection goes wrong exactly when it matters most: a wood-grain desk, a lined notepad, a white page on a white table, or a receipt with a torn edge. Dragging four dots takes about ten seconds, a magnifier follows your finger, and you decide where the page ends.
- Can I search the text in the PDF afterwards?
- No. There is no OCR, so the PDF holds the corrected picture of your page rather than the words on it. You can read it and print it, but you cannot select, copy or search the text. If you need that, run the finished PDF through an OCR tool afterwards.
- Is my photo uploaded anywhere?
- No. The photo is decoded into a canvas in this tab and never sent to a server, which is why the tool keeps working with the network switched off after the page has loaded. Contracts, payslips, ID cards and medical letters stay on your device.
Related tools
Files
Bulk Image Resizer (Exact px, Batch Zip Download)
Resize JPEG, PNG, or WebP images to an exact width or percent, batch several into one zip, and convert format. Runs in your browser, nothing is uploaded.
Files
PDF Page Extractor: Split, Reorder and Merge by Range
Pull pages out of a PDF by typing a range like 1-3,5, reorder them by typing them out of order, or join files. Nothing is uploaded; it runs in the browser.
Files
Poster Tiler: Split an Image Across A4 Sheets
Split one image into a print-ready PDF of A4 tiles with an overlap flap for gluing. 2, 4, 6 or 9 sheets. Runs in your browser; nothing is uploaded.
Finance
Household Budget Percentage Calculator
Split take-home pay into 8 budget categories with presets for single, couple, and family households.