Blog · PDF tips

Rotate and organize scanned PDFs into a clean packet

The scan came from a front-desk copier that someone had loaded sideways for the last third of the stack, plus two pages upside down because the duplex flipped them, plus a blank where the feeder grabbed twice. Ninety-four pages. The partner wanted it “readable before lunch.” Rotation and page order fixed it. Nothing in that hour made the crooked lines straight.

Rotation is a flag, not a redraw

Rotate PDF uses pdf-lib. You pick 90, 180, or 270 degrees. You can limit the change with a page list, or leave the list empty and hit every page. The script updates rotation on those pages and saves. It does not paint a canvas. Text that was selectable stays selectable. A vector stamp stays a vector stamp. This is the cheap, correct fix for phone photos and feeder mistakes that are wrong by a right angle.

It will not deskew a page that is 7 degrees off because the phone was tilted. The letters stay tilted, only the page box turns. If you need straight lines, you need a scan tool that warps the image. I say that before someone rotates four times and decides the tool is broken. Four times 90 degrees is the identity. You are back where you started, still crooked.

pages 1-60     already upright, leave them
pages 61-92    90° clockwise in the viewer, so rotate 270° (or 90° the other way — check one page)
pages 70, 71   180°, handle them in a second pass

I do not rotate 61–92 including 70–71 and then “fix” 70–71 by rotating the whole range again. Second pass, explicit list 70,71, 180 degrees from their new orientation, or 90 from the original if I have not saved yet. I rotate once from the original with a plan, because stacked rotations make me count on my fingers and I have been wrong.

What you seeToolText layer
Page turned 90° or 180°RotateKept
Page slightly crookedNot this one—
Right-side up, wrong sequence, blank sheetsOrganizeKept. You are copying pages into a new order
Several sideways files that must become one packetRotate each, then mergeKept, if you do not compress after

The lunch-hour sequence on those 94 pages

I rotated 61–92 by 270 and 70–71 by an additional 180 after I looked at them, which I could have planned better. Then I opened Organize. Organize is a different page: thumbnails, move up or down, delete, export a new PDF. The original file stays on disk. I removed three blanks and moved a cover sheet from page 12 to page 1, where the feeder had placed it after a misfeed. I did not “delete blanks” as a religion. One of the white pages was the back of a photo ID, intentional, and I left it because the instructions said duplex.

Export. Count pages: 94 minus 3 blanks is 91. The viewer count matched. I jumped to old problem spots by remembering they were near the end, found them upright, and checked that a sentence still highlighted. It did. That was the lunch. The partner could read it. The scan was still gray and slightly soft, because nobody had asked for a rescan.

Viewers that keep showing the old direction

Preview caches. A chat app caches. I have argued with a thumbnail that was generated before the rotation and refused to update. The downloaded file, opened in a second reader, was upright. Trust the file you just wrote, not the bubble in the messenger. If both readers are sideways, the rotation did not apply to that page. The page list was wrong. One off-by-one in the list and page 61 stays wrong while 62–92 look fixed, which is a very confusing success.

Landscape tables that were landscape on purpose must not be “fixed.” I look for a wide table before I rotate a range. A range of “everything after page 60” once included a landscape schedule that the author had rotated correctly. I turned it portrait and the columns fell off the screen. Undo was the original file, which I still had. Export is a new file. It is not a version history. If you overwrite the source, your undo is gone.

OCR wants upright text. I rotate, then I OCR, never the reverse. A model can sometimes read sideways text and will also invent corrections to justify the angle. Give it an upright page. Organize before OCR too, so you are not paying attention to blank sheets and a cover that appears on page 12.

Mixed sizes: rotation does not change the media box into A4. A phone photo page stays a phone photo page, now upright. Print shops will still complain. That complaint is about size, and it belongs to a different afternoon.

If a page looks upside down only on paper and correct on screen, check the printer’s duplex and “auto rotate” settings before you touch the PDF. I have edited files to compensate for a driver and then printed them correctly on a second printer, which made them wrong again. Confirm the device before you bake a workaround into the document.

The ID page I almost deleted

It looked blank in the thumbnail because the scan was very light. Zoomed, it was the back of an ID, pale blue, with a number the partner needed. Thumbnail emptiness is not a blank page. I now open anything I am about to delete if the file size of that page, in a split test, is more than a few dozen kilobytes. A true blank is tiny. A faint scan is not. Organize will happily drop either. The judgment is the zoom, not the white square in the grid.

After rotation, a signature that was “on the left” may be on the right, because you turned the page and the left was never the binding edge. I do not “correct” that by rotating back. I check whether the line of text is upright. Upright text with a signature on the unexpected side is the scan. Upside-down text is the bug. Binding-edge aesthetics can wait. Lunch was about readable sentences.

I export organize and rotate as separate files when both happen: rotated.pdf, then rotated-ordered.pdf. If the order export is wrong I do not re-rotate. I go back one step. Stacking both edits in my head and redoing them from the original is safer when I have already confused myself, and slower when I have not. The intermediate file is cheap. I keep it until the partner says the packet matches the paper stack. Then I can delete the intermediate. Not before. “Looks fine” from me is not the same statement as “matches the stack they handed me.”

Wide tables that were correctly landscape stay out of the rotate list even if the pages around them are sideways scans. I write the list down, including the exclusions, before I click. The exclusion is the part I forget when I am hungry. Page 64 was the schedule. It is still landscape. The scans around it are upright. That combination looks inconsistent in a thumbnail grid and it is correct on paper. Do not “tidy” it into one orientation to soothe the grid.