Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The reliable fix is to normalize each photo before Puppeteer renders it. Read the JPEG, apply its EXIF Orientation transform with Sharp’s autoOrient(), re-encode the result, and use that normalized file or buffer in your HTML. Sharp rotates and mirrors the pixels and removes the consumed Orientation tag, so Chromium and the PDF stage receive an ordinary, upright image.

CSS image-orientation: from-image can be a useful diagnostic, but server-side PDF output is more reproducible when the pixels are physically normalized first.

Why an iPhone photo turns sideways in a PDF

Many cameras save the sensor’s pixels in one raster order and record the intended viewing direction in the EXIF Orientation tag. A portrait can therefore contain landscape-shaped pixels plus metadata saying “rotate 90 degrees.” Photo viewers commonly honor that metadata. A PDF pipeline may decode the pixels without applying it, or an intermediate step may strip the metadata before Chromium rasterizes the image.

The result is not a Puppeteer rotation setting that is missing; it is an image whose orientation instruction was never applied at the stage that produced the PDF. EXIF also has mirrored states, not only 90°, 180°, and 270° rotations, so a fix that handles rotation alone is incomplete.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

The robust pipeline: normalize before HTML rendering

  1. Read the original image bytes.
  2. Run Sharp autoOrient(), which applies the EXIF rotation or mirror transform.
  3. Encode a canonical JPEG or PNG. Sharp removes the EXIF Orientation tag from the oriented output.
  4. Make that output reachable from the page as a data URL, file URL, or authenticated HTTP URL.
  5. Wait until the image has decoded, then call page.pdf().

Sharp documents the operation as: “Auto-orient based on the EXIF Orientation tag, then remove the tag.” Its constructor option likewise rotates or flips an image to match EXIF Orientation when present. Only that EXIF tag is considered; XMP tiff:Orientation and other metadata are a separate responsibility.

Install the dependencies

npm install puppeteer sharp

Sharp includes native image-processing components for common Node.js platforms. In a production build, install it for the same operating system and architecture that runs your Puppeteer worker.

Complete Node.js example using a normalized buffer

import puppeteer from 'puppeteer';
import sharp from 'sharp';
import { readFile } from 'node:fs/promises';

const inputPath = './photo.jpg';
const outputPath = './oriented-report.pdf';

const input = await readFile(inputPath);
const normalized = await sharp(input)
  .autoOrient()              // applies rotations and mirror states
  .jpeg({ quality: 90 })     // use .png() when lossless PNG output is required
  .toBuffer();

const imageData = `data:image/jpeg;base64,${normalized.toString('base64')}`;
const browser = await puppeteer.launch({ headless: true });
try {
  const page = await browser.newPage();
  await page.setContent(`
    <!doctype html>
    <html>
      <head>
        <style>
          @page { size: A4; margin: 18mm; }
          body { font-family: sans-serif; margin: 0; }
          img { display: block; max-width: 100%; height: auto; }
        </style>
      </head>
      <body>
        <h1>Photo report</h1>
        <img src="${imageData}" alt="Normalized camera photo">
      </body>
    </html>`, { waitUntil: 'load' });

  await page.evaluate(async () => {
    const images = [...document.images];
    await Promise.all(images.map(async image => {
      if (!image.complete) {
        await new Promise((resolve, reject) => {
          image.addEventListener('load', resolve, { once: true });
          image.addEventListener('error', reject, { once: true });
        });
      }
      if (image.decode) await image.decode();
    }));
  });

  await page.pdf({
    path: outputPath,
    format: 'A4',
    printBackground: true,
    waitForFonts: true
  });
} finally {
  await browser.close();
}

The data URL avoids another network request and is convenient for a single image. For many or very large images, write normalized files to a controlled temporary directory or serve them from an endpoint instead of inflating the HTML string.

File-based variant

await sharp('photo.jpg')
  .autoOrient()
  .toFile('photo-normalized.jpg');

await page.setContent(`
  <img src="file:///absolute/path/photo-normalized.jpg"
       style="max-width:100%;height:auto">
`);
await page.pdf({ path: 'output.pdf', printBackground: true });

Use an absolute file URL and ensure the Chromium process is allowed to read it. An HTTP endpoint is usually easier to secure and observe in containerized deployments.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

CSS image-orientation: useful fallback, not the deterministic fix

img {
  image-orientation: from-image;
}

With from-image, the browser is asked to use EXIF information to orient the image. The property is intended for camera and scanner orientation; use transform: rotate(...) for a deliberate design rotation. This can quickly show whether EXIF is the cause, but print behavior depends on the Chromium version and on which decoder receives the image. A later service that strips metadata will lose the correction.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

If you use the fallback, put the rule in print CSS or explicitly select the media type:

await page.emulateMediaType('screen'); // only if the document is authored for screen styles
await page.pdf({ path: 'output.pdf' });

By default, page.pdf() generates a PDF using the print CSS media type. Do not apply both Sharp’s transform and a manual CSS rotation for the same camera orientation; that double-rotates the image.

Make Puppeteer wait for the real image

Correct pixels can still produce a missing or blank image if printing starts before a remote resource has loaded. For remote images, verify that the URL is reachable from the browser process, permits the required authentication, and is not blocked by an access-control policy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Use page.goto(url, {waitUntil: 'networkidle0'}) when navigation is the page-loading step.
  • After setContent(), wait for each image’s load event and call decode() where available.
  • For lazy-loaded images, scroll or trigger the site’s lazy-load mechanism before collecting image elements.
  • Only call page.pdf() after fonts and images needed for layout are ready.

PDF settings that affect the result

Puppeteer’s PDF options control page geometry and readiness, not an unhandled EXIF transform.

Option What it changes What it cannot fix
format Standard paper size such as A4 or Letter. Sideways source pixels.
landscape Page orientation. Photo orientation inside the page.
preferCSSPageSize Whether CSS @page dimensions take precedence. EXIF interpretation.
printBackground Printing background colors and images. Image metadata.
scale Overall print scaling. Rotation or mirroring.
waitForFonts Whether PDF generation waits for fonts. Image decoding unless you wait separately.

Choose page size and scaling after the image is upright. A landscape PDF page is not a substitute for orienting a portrait photograph.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Edge cases you should handle

Mirrored orientations

EXIF defines mirrored variants as well as rotations. Sharp’s autoOrient() handles both, whereas a hand-written “rotate 90 degrees” rule may leave a selfie mirrored.

Metadata beyond EXIF Orientation

Sharp’s documented operation considers the EXIF Orientation tag. If your asset carries XMP tiff:Orientation or a vendor-specific instruction, inspect and normalize that metadata separately.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PNG output

If downstream consumers require PNG, replace .jpeg({ quality: 90 }) with .png(). The essential operation is .autoOrient(); the output format is independent.

Repeated processing

Normalize once at ingestion and keep the canonical derivative. Running a second orientation transform after the tag has been removed should not rotate it again, but combining normalization with a CSS transform can.

Large photos and memory

Data URLs duplicate the encoded image inside the HTML and can increase peak memory. Prefer a temporary file or streamed/authenticated URL for multi-megapixel uploads, and delete temporary files after the PDF job. Re-encoding at a suitable quality reduces PDF size; do not reduce dimensions below the print resolution your document needs.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Verification recipe

  1. Create or select a fixture JPEG with a nontrivial EXIF Orientation value, such as a portrait whose stored raster is landscape.
  2. Generate one PDF from the original and one from the autoOrient() output using identical HTML and PDF options.
  3. Inspect the rendered pages, or rasterize both PDFs for a pixel-level comparison.
  4. Confirm that the normalized PDF is upright and remains upright after EXIF metadata is stripped from the derivative.

This test distinguishes an orientation problem from unrelated layout, clipping, or resource-loading failures.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

The photo is still sideways

  • Check that the HTML references the normalized buffer or file, not the original upload.
  • Inspect the source metadata; the orientation may be in XMP rather than EXIF.
  • Remove any CSS rotate() applied to the same image.
  • Confirm the PDF worker is running the Sharp version and code path you expect.

The image is missing or blank

  • Wait for load and decode() before printing.
  • Check file URL permissions, authentication, DNS, TLS, and response status from inside the browser environment.
  • For lazy images, trigger loading before the readiness check.

Orientation works in the browser but not in the PDF

  • Remember that PDF generation uses print media by default; put the CSS rule in print styles or call emulateMediaType().
  • Prefer pixel normalization so the result does not depend on Chromium’s print-time metadata handling.

Output quality or file size changed

Re-encoding is expected. Adjust JPEG quality or use PNG when lossless output is required, then verify that the resulting dimensions and visual quality meet your print requirements.

The process times out

Separate image processing time from page navigation time in logs. Resize or normalize oversized uploads before launching the browser, increase the navigation timeout only for known-slow endpoints, and close the browser in a finally block so failed jobs do not leak processes.

Performance, reliability, and cost choices

  • Normalize at upload: pays the Sharp cost once and makes every later renderer deterministic.
  • Normalize per PDF: avoids storing derivatives but repeats CPU work and can increase latency under load.
  • Data URL: simplest isolation for one image, with higher HTML memory use.
  • File or HTTP URL: better for many images, but requires access control and explicit readiness checks.
  • CSS only: smallest code change, but dependent on the browser and print path honoring metadata.

Measure your own workload rather than assuming a fixed processing time: image dimensions, compression, concurrent jobs, storage, and browser startup all affect latency and resource use.

Or skip the browser setup

ScreenshotNeo provides a website screenshot API and MCP server when you need a rendered page rather than a hand-managed Puppeteer worker. Its cleaning steps accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. AI agents can use its MCP tools—take_screenshot, get_page_info, and capture_pdf.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a one-call capture, see the ScreenshotNeo documentation:

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. If you want to try it, sign up for the free 1,000-shot plan.

FAQ

Does removing EXIF metadata alone rotate the photo?

No. Removing the tag only prevents a later decoder from seeing the instruction. The pixels must first be rotated or mirrored into their canonical order.

Can I fix an already-generated PDF?

Usually you must transform the embedded image and regenerate the PDF. Rotating the PDF page changes page geometry, not necessarily the image’s orientation within its content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should I preserve the original upload?

Yes. Keep the original for audit or future processing, and store a separate normalized derivative for rendering.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.