Blog

Turn a Phone Photo of a Document into a Scan-Like PDF

A photo of a quote or receipt taken on a desk comes out skewed and grayed by shadows. I tested, entirely in the browser, how to find the paper’s four corners in the photo, straighten it as if shot from directly above, even out the shadows to white, and combine the result into a PDF. I also cover how to fix corners that were detected wrongly on a white desk, how a red seal stamp changes across the four finishes, and the measured file sizes.

The English version of the document photo scanner. On the left, a quote placed at an angle on a brown desk with its four corners outlined in green; on the right, the corrected quote as a white rectangle.
Left: the loaded photo and the automatically detected corners. Right: the corrected page.
Contents

You need to submit images of receipts for an expense claim, send a copy of a signed application form, or file a quote from a supplier in a shared folder at work. Without a scanner nearby, a smartphone photo has to do. But when you shoot a sheet lying on a desk while standing, the paper turns into a trapezoid, your hand or phone casts a shadow, and the white paper comes out a yellowish gray. Send it as is, and the recipient has to rotate and zoom the image just to read it.

Some apps correct the image while you shoot, such as “Scan Documents” in the iPhone Notes app or the scan feature in Google Drive. They are no help, however, when you need to fix a photo you already took, one someone sent you, or one already copied to your computer. I ran two documents, a sample quote and a receipt, through the Document Photo Scanner, which finds the paper’s four corners in such a photo, straightens it as if shot from directly above, evens out the shadows to white, and combines the pages into a PDF. Photos are processed only inside the browser and are not uploaded. On the quote, the corners lined up automatically and the shadow and yellow tint disappeared. On the receipt lying on a white desk, the tool reported that it had found the four corners while drawing its outline around the bright part of the desk as well.

Skew and shadows are fixed by two separate steps

Before getting into the steps, it helps to know what the tool is correcting. It makes it easier to see what to check on the corner screen and what changes when you pick a finish.

The first is skew. A rectangular sheet shot at an angle becomes a trapezoid in the photo (strictly speaking, a general quadrilateral). Once you know where the paper’s four corners are in the photo, you can compute a transformation that maps those four points onto the four corners of a rectangle (a projective transformation) and get back the shape as if shot from directly above. This is what is usually called keystone or perspective correction. The tool first searches the photo for the paper’s corners automatically, and you then check and adjust them.

The second is color. Shadows and uneven lighting come from the paper being brighter in some places than others. The tool divides the paper into small blocks, treats the brightest part of each block as “the paper’s base color at that spot”, and divides each pixel’s color by it, so shaded and bright areas end up the same white. Text and ink are darker than the base color, so they remain after the division.

The two steps are independent. If the corners are right, the shape is fixed, and changing the finish changes only how color is handled. Conversely, if the corners are wrong, you get a misshapen page even when the color processing works fine. The receipt example later shows exactly this.

Going from loading to saving with the sample quote

From here on I use the English version of the tool. The first thing you see is the “Load photos of documents” box with three buttons: “Choose photos (multiple)” to pick photos, “Take a photo” to shoot one on the spot with a smartphone, and “Try a sample photo” to load a sample. You can also drop photos onto the box or paste them with Ctrl+V (⌘+V on a Mac).

The first screen of the English version. Under the heading Load photos of documents are instructions for dropping or pasting photos and three buttons: Choose photos (multiple), Take a photo, and Try a sample photo.
The first screen. If you have no photo at hand, try the sample with “Try a sample photo”.

Start by pressing “Try a sample photo”. A sample photo that looks like a Japanese quote shot from above at an angle on a brown desk is loaded, and the “Match the four corners of the paper” screen opens below it.

The Match the four corners of the paper screen. Round handles sit on the four corners of a quote placed at an angle on a brown desk, outlined in green. Above it is the message Found the four corners of the paper, and below are the buttons Detect corners, Use whole photo, Rotate left, and Rotate right.
In the sample photo, the paper’s four corners were found automatically and outlined in green.

At the top of the photo it says “Found the four corners of the paper.”, and round handles sit on the corners of the quote. What you check on this screen is whether the green lines follow the edges of the paper. In the sample, each of the four handles is on a corner of the paper, so you can move on. If a handle is off, drag it onto the corner of the paper (I do this with the receipt later). The buttons below are “Detect corners” to search for the corners again, “Use whole photo” to use the entire photo as the area, and “Rotate left” and “Rotate right” to turn the corrected page in 90-degree steps.

Further down, under “Result and saving”, the corrected page is already shown.

The Result and saving screen. Finish is Color (white background), Paper aspect ratio is Estimate from photo, and Quality is Standard (long side 2,000 px). Below is a preview of the quote as a white rectangle, Output 1,244 × 1,683 px, A4 as the PDF paper size, and the buttons Save as PDF (all pages), Save this page as JPEG, and Save as PNG.
The result with the default settings (Color, Estimate from photo, Standard). The shadow at the bottom right and the yellowing of the paper are gone.

In the original photo, the phone’s shadow fell across the bottom right and the whole sheet looked yellow. In the preview the paper is a white rectangle and the table rules are straight. The red round seal (a hanko, the stamp Japanese companies use in place of a signature) stays red. Press “Save as PDF (all pages)” here and a PDF named sample_scan.pdf is saved. If you want a single page as an image, use “Save this page as JPEG” or “Save as PNG”.

Choose the finish by the colors you need to keep

“Finish” has four options. Here is the lower half of the sample quote (the second half of the table and the red seal) in each of the four finishes.

A comparison of the lower half of the same quote in four finishes. No enhancement keeps the shadow and yellowing, Color has a white background with the seal still red, Grayscale turns the seal gray, and Black & white makes the text bold and the seal black.
From top left: No enhancement, Color, Grayscale, Black & white. In black and white, the red seal also turns black.

“No enhancement (fix the shape only)” fixes the shape and keeps the colors as the photo captured them. Shadows and yellowing remain, so it suits flyers and handouts with pictures more than documents. “Color (white background)” removes shadows and yellowing to make the background white while keeping the red of the seal and the colors of pens. “Grayscale” does the same processing and then drops the color. “Black & white (crisp text)” reduces everything to two colors; text becomes crisp, but the red seal also turns into a black circle.

For documents where a seal or corrections in red ink matter (contracts, stamped application forms, manuscripts marked up in red), Color is the safe choice. In black and white you can still tell that a seal is there, but it becomes hard to see where the seal ends and the text begins. On the other hand, receipts and text-only documents are easiest to read in black and white.

I measured the file sizes too. Saving the sample quote (1,244 × 1,683 px after correction) as an A4 PDF gave about 170 KB in Color, about 170 KB in Grayscale, and about 47 KB in Black & white. Grayscale is barely smaller than Color because color and grayscale pages go into the PDF as JPEG, and a white background with the shadows removed carries little color information to begin with. Only black-and-white pages go in as PNG, so the edges of the text do not blur and the file is less than a third the size. When saving as an image, black and white was also smaller as PNG (about 120 KB) than as JPEG (about 240 KB).

The “Whitening strength / text weight” slider whitens fainter smudges and shadows the further right you move it in Color and Grayscale, and keeps fainter text black the further right you move it in Black & white. If pencil notes or a faint stamp disappear in black and white, move the slider to the right.

Reset the “Estimate from photo” aspect ratio for standard paper sizes

With the default “Estimate from photo”, the aspect ratio of the corrected page is estimated from the photo. Paper shot at an angle looks shorter at the far end, so the tool works backward from the corner positions to the camera’s tilt and recovers the original ratio. For the sample quote the output was 1,244 × 1,683 px, a ratio of 1.35. That is close to A4 (1:√2 = 1.41), but not exact.

For documents of a known paper size, choosing the paper under “Paper aspect ratio” removes any horizontal or vertical stretching of the text. The choices are “A4, A5, B5 (1:√2)”, “Letter (8.5 × 11 in)”, “ID card / driver’s license (85.6 × 54 mm)”, and “Japanese business card (91 × 55 mm)”. Choosing “A4, A5, B5” for the sample changed the output to 1,190 × 1,683 px (1.41). For paper with no fixed length, such as receipts, leave it on the estimate.

“Quality” sets the number of pixels on the long side, but the tool does not upscale much beyond the size of the paper in the photo. For the sample photo, the long side stopped at 1,683 px whether I chose “Standard (long side 2,000 px)” or “High (long side 3,000 px)”, and only “Light (long side 1,400 px)” brought it down to 1,400 px. If you want to keep fine print, getting closer so the paper fills most of the frame does more than any quality setting.

On a white desk, the receipt’s corners were detected wrongly

Next I tried a condition automatic detection struggles with. I made a test image that recreates a receipt lying on a whitish desk with a hand’s shadow falling from the left (a 2,133 px tall photo with a receipt of width-to-length ratio 1:2.60 composited in as if seen at an angle) and loaded it with “Choose photos (multiple)”. Here is what happened.

A test image recreating a receipt on a whitish desk. The message says Found the four corners of the paper, but the green lines enclose not the receipt but a large, almost pentagonal area that includes the upper half of the desk.
The message says “Found”, but the green lines enclose the bright part of the desk rather than the receipt.

The message is the same “Found the four corners of the paper.” as with the sample, but the green lines do not enclose the receipt. They connect the two top corners of the photo, a point partway down the left edge, and the bottom right corner. Because the tool looks for corners on the premise that “paper is brighter than the background”, on a white desk as bright as the paper it treats the unshaded part of the desk as part of the paper too. When it cannot find the corners at all, a different message appears (Could not find the four corners of the paper automatically.), but as here, it can also claim to have found them and get them wrong. Judge by the green lines, not by the message.

The fix is to drag the round handles one at a time onto the corners of the receipt. While you drag, a round window magnifying the area around the handle appears in the corner away from your finger, which makes it easy to put the crosshair on the corner.

The screen while dragging the bottom-right handle. A round, magnifier-like window at the top left shows the handle position with a crosshair. The top two handles are already on the corners of the receipt.
While you drag a handle, a magnified view of the area around the corner appears in the corner away from your finger.

Here is the result after placing all four handles on the receipt’s corners and setting the finish to “Black & white (crisp text)”.

The corrected receipt with Finish set to Black & white (crisp text). Black text on a white background, with the store name, the word receipt, the date and time, items and prices, and a total of 1,758 yen in straight lines. Output 784 × 1,947 px.
The receipt with corners placed by hand, in black and white. The hand’s shadow is gone and the item and price lines are level.

The hand’s shadow on the left is gone, and the item and price lines that had been slanted are now level. The prices (in Japanese yen) can be read digit by digit. The aspect ratio estimated from the photo was 784 × 1,947 px (1:2.48), about 5% wider than the receipt used for the composite (1:2.60), but not enough to make the letterforms look off.

If you often shoot on a white desk, changing how you shoot saves more time than placing corners by hand. Put the receipt on a dark notebook, a clear file folder, or a wooden desk, and the edge of the paper stands out so the corners are found automatically more easily. For images that are already cropped or that came from a scanner, where you only want to correct the color, press “Use whole photo” to use the entire photo as the area.

Combining several pages into one PDF

When you have several photos, like the quote and the receipt, select them together with “Choose photos (multiple)” or load them one after another. Loaded photos appear below the buttons as a list of pages.

Below Load photos of documents, thumbnails of the receipt as Page 1 and the quote as Page 2, each with the buttons Earlier, Later, and Remove.
Pages follow the order in which they were loaded. Change the order with “Earlier” and “Later”.

Press a thumbnail in the list to switch to that page’s corner screen and result. Corners are set per page, but the same “Finish” is applied to all pages. Here I loaded the receipt after the quote, so the quote ended up in black and white too. If you want to keep the quote’s red seal in color and leave the receipt in black and white, it is better to make separate PDFs. Reorder pages with each page’s “Earlier” and “Later”, and drop unwanted ones with “Remove”.

When everything is ready, pick a paper size under “PDF paper size” and press “Save as PDF (all pages)”. With A4, a long, narrow page like the receipt is scaled to fit without cropping and centered on the A4 page. The two-page black-and-white PDF (scan.pdf) was about 85 KB. To make each page the size of its image, set the paper to “Same as image size”.

If you want to do a little more before sending

What you do after making the PDF depends on the goal, and other tools fit better. To redo page order, rotation, or remove blank pages all at once, use Reorder, Rotate and Delete PDF Pages. To combine several PDFs into one, use the PDF merge tool (how to use it: Combine several PDFs into one without uploading them). To add page numbers, see Add page numbers to a PDF.

When you send a photo of a driver’s license or an ID card for identity verification, correct it with the “ID card / driver’s license” ratio and then overlay the recipient and date with the ID document watermark tool. That makes it harder for the image to be reused for another purpose (how to overlay the recipient and date before sending the image). If your photos or screenshots are already straight and you just want to line them up in a PDF, no correction is needed, and Image to PDF is enough.

Finally, here is what this tool cannot fix. If the paper is folded or curled, the lines near the middle stay curved, because the correction assumes the paper is a flat quadrilateral. Text washed out white by glare on glossy paper cannot be recovered by color processing either. For such photos, the quickest route is to hold the paper flat and reshoot without the light directly overhead.

Frequently asked questions

Can I fix a photo of a document I already took so it looks scanned?

Yes. As long as all four corners of the paper are in the photo, you can find them, correct the perspective, even out shadows and yellowing to white, and save the result as a PDF or JPEG. A browser-based tool can also process photos someone sent to your computer.

How do I remove shadows from a photo of a document and make the background white?

Use a process that estimates the brightness of the paper in each area and divides it out. In the tool in this article, choosing the Color (white background) or Grayscale finish turns hand and phone shadows and uneven lighting almost completely white. Text washed out by glare on glossy paper cannot be recovered, though.

Why are the corners detected wrongly when I shoot on a white desk?

The tool looks for the corners on the assumption that the paper is brighter than the background. On a white desk it cannot see the edge between paper and desk, so it treats the bright parts of the desk as paper too. Drag the round handles onto the corners of the paper, or reshoot on a darker surface.