Why your photo lands sideways in the PDF
The photograph is the right way up on your phone. It is the right way up in the email you sent yourself, and the right way up when you drag it into a browser tab to look at it. You convert it to a PDF and it is lying on its side.
So you try another converter. Same result, or upside down this time. The one that finally comes out upright puts the picture in the middle of a landscape page with three inches of white either side, which is not much better.
Nothing is wrong with the photograph. It has been sideways since the moment you took it, and everything except the PDF has been quietly turning it round for you.
Your camera never rotates the picture
The sensor in a phone is a fixed rectangle soldered to the body. It does not swivel when you turn the phone, so it always reads out its pixels in the same order — for nearly every phone, a landscape grid — whichever way up you were holding it. Rotating those pixels afterwards would mean rewriting several megapixels in the fraction of a second before you press the shutter again, and cameras have declined to do that since the first ones with a tilt sensor in them.
So the phone writes the pixels exactly as the sensor read them and records a note: EXIF tag 0x0112, "Orientation", a single number from 1 to 8, tucked into the JPEG's header beside the exposure and the GPS position.
The number says which way the camera was held, and therefore what has to be done before a person looks at the picture:
- 1 — as stored. Nothing to do. You were holding the phone the way the sensor is wired.
- 3 — a half turn. Phone upside down.
- 6 — a quarter turn clockwise. The common portrait one.
- 8 — a quarter turn anticlockwise. The other portrait one.
- 2, 4, 5, 7 — a mirror, sometimes with a turn on top. Rare, and covered further down.
Every gallery app, every operating system's preview and every current browser reads that number and applies it before drawing. That is why the photo has looked correct everywhere you have ever seen it, and why nobody ever mentions the tag: it does its job invisibly, several times a day, on every photo you own.
PDF has never heard of the tag
A picture inside a PDF is an image XObject: a block of compressed data, a width and a height in pixels, a colour space. There is no orientation entry in that dictionary and nowhere to put one. The page decides where the picture goes with a drawing matrix — six numbers that scale, move and if you like rotate it — written by the tool making the PDF, at the moment it makes it.
So the note has to be read and acted on by the converter, or it is lost. And here is the part that makes this maddening rather than merely annoying: the more careful the converter, the more likely it is to get this wrong.
Putting a JPEG into a PDF byte for byte is the right thing to do. It costs no quality and no size, where decoding and re-encoding the photograph costs both. But those original bytes carry the EXIF block along with them into a format that ignores it, so a tool that hands the JPEG over untouched and does nothing else has kept every pixel and thrown away the only thing that said which way up they went. A sloppier tool that decodes the photo through an image library that happens to auto-rotate gets the right answer by accident.
Then there is the half-correct version, which is where the white bands come from. A converter applies the rotation to the picture but measures the page from the stored width and height — so a portrait photograph is fitted into a landscape page and then turned upright inside it. Right way up, wrong shaped page, wasted paper.
The other way it happens: the note was already gone
Sometimes the tag is not ignored, it is missing, and then no converter can help.
Anything that resizes, re-saves or scrubs a photo can drop the EXIF block — messaging apps, upload forms stripping metadata for privacy, "optimised" copies pulled down from cloud storage. If whatever did that applied the rotation to the pixels first, the photo is genuinely upright now and all is well. If it dropped the tag without rotating anything, the picture is sideways as a matter of fact, and nothing records that it should not be. Which is why the same photo behaves differently depending on how it reached your computer: straight off the phone by cable, tag intact; through a chat app, often not.
What our converter does with it
JPG to PDF reads tag 0x0112 out of the JPEG header itself — it walks to the APP1 marker and reads the one 16-bit integer — and folds the corresponding turn into the drawing matrix. The JPEG still goes into the document byte for byte: the pixels are not decoded or re-encoded, only the instruction saying where to draw them changes.
It also measures the page against the turned dimensions, which is the half that the white-band converters miss. A portrait photograph gets a portrait page on "fit the picture", and on A4 with orientation left on automatic it gets a portrait sheet rather than a landscape one.
If the tag is absent, unreadable or nonsense, it is treated as 1 and the picture is placed as stored. That is deliberate: turning a photograph that was already the right way up is a worse failure than leaving one alone, because at least the second kind is obvious.
- Add the photos in order. Number them
01,02,03first — file pickers put 10 before 2. - Choose the page shape. "Fit the picture" gives each page the photo's own shape and wastes no paper. A4 or Letter is for printing.
- Leave orientation on automatic on A4 or Letter. It looks at each picture after the turn has been worked out, so mixed portrait and landscape shots each get a page matching the photo.
- Check the result. Our PDF inspector reads page sizes and each page's rotation in your browser without uploading the file. On a fitted conversion, portrait photos should have given you pages taller than they are wide.
Straightening a PDF that is already sideways
If the document was made by something else, the photo is not the problem any more — the page is.
Rotate PDF writes the turn into the page's own /Rotate entry rather than spinning
the content with a matrix. Nothing is redrawn, nothing is re-encoded, the file comes back the size it
was, and any text on the page stays selectable and readable aloud. Work out the angle from where the
top of the picture has ended up:
- Top against the left edge of the page: it was turned anticlockwise. Use 90° clockwise.
- Top against the right edge: use 270°.
- Upside down: 180°.
The angle is added to whatever the page already carries, so a page that arrived at 90° and gets
another 90° ends up at 180 rather than back where it started. Name only the pages that are wrong —
2,5,9, or odd — which is what you want when half a batch was shot in portrait.
When the picture is mirrored rather than turned
Orientation values 2, 4, 5 and 7 include a reflection. They are uncommon, but front-facing cameras and a few scanning apps produce them, because the selfie preview is mirrored and some software saves what you were looking at. The tell is text in the photograph reading backwards.
No amount of rotating fixes that: quarter turns cannot produce a mirror image, so Rotate PDF will only give you back-to-front words at a different angle. Flip PDF pages reverses a page, by wrapping the page's existing drawing in a mirror instruction rather than rewriting anything inside it. Comments, links and form fields are not mirrored — irrelevant for a photograph, worth knowing on a real document. Do not reach for it on a merely sideways page.
Fixing the photographs themselves, which is better for a big batch
If you have four hundred pictures, or they are going to be used for more than this one PDF, correct them at the source. All of these are free:
exiftool -Orientation -n *.jpgprints the raw number for every file at once. Anything other than 1 is a photo that depends on the tag. This is also the honest answer to "which of my photos will this happen to".jhead -autorot *.jpgrotates the pixels to match the tag and then resets the tag to 1. It works block by block on the JPEG rather than decoding it, so nothing is re-compressed and no quality is lost.exiftran -ai *.jpgdoes the same job if that is what your package manager has.magick -auto-orient photo.jpg out.pdfconverts with the rotation applied. The flag is the whole point: without-auto-orientImageMagick places the pixels exactly as stored, which is the behaviour this entire post is about. It re-encodes the photograph, so prefer the two steps above for anything you care about.
The trap is doing half of it. Some editors rotate the pixels and leave the tag saying 6, so the
picture is now stored upright and still carries an instruction to turn it. Anything that honours
the tag — a browser, a gallery, our converter — turns it a second time, and you are 180 degrees from
the truth. jhead -autorot resets the tag, which is exactly why it is the safe tool here.
What this will not do
Only JPEG is checked. PNG, GIF and BMP have no orientation tag at all; a screenshot is stored the way you saw it. TIFF does have one, and we do not read it — a TIFF is decoded and placed as its pixels are, so straighten it with Rotate PDF afterwards if it needs it.
HEIC is not accepted. Everything off a recent iPhone is HEIC. Share a copy out of Photos, which hands over a JPEG with the rotation already sorted out, or set the camera to "Most Compatible".
Nothing is written back to your photos. The correction lives in the PDF; the JPEGs on your disk are exactly as they were, tag and all.
A tilt is not an orientation. This fixes quarter turns, which is all the tag can describe. A document photographed at a slight angle needs straightening instead, and that redraws the page as an image.
Before you print or send the batch
Two things usually follow a folder of phone photos, and both go better once the pages are the right way round. N-up PDF comes out ragged when the pages it is handed are not all one shape, and a page left on its side is exactly that; putting four photos on one page explains what it measures and what to set instead. And the PDF will be as large as your photographs are, because nothing was re-encoded, which makes Compress PDF the deliberate second step — for a reason worth reading before you hunt for a quality slider.
Get the orientation right first. Every step after it copies whatever it was handed.