Skip to content
English
  • There are no suggestions because the search field is empty.

IronPrint - Mixed-Orientation PDF Prints Every Page as Landscape

Overview

IronPrint 2026.1.5 does not preserve per-page orientation when printing a PDF that mixes portrait and landscape pages. Every page is sent to the printer in landscape, regardless of its original orientation. No corrected build is available for this version; the workaround is to split the document into batches of consecutive same-orientation pages and send each batch to the printer as a separate print job.

Environment

  • OS: Windows 10; Windows Server 2022
  • Affected Versions: 2026.1.5
  • Language/Runtime: .NET 8

Version Metadata

  • Version Found: 2026.1.5

  • Version Resolved: N/A

Solution

Recommended: Print the PDF in orientation-consistent batches instead of as a single job.

  1. Detect each page's orientation. Open the PDF and compare each page's width and height. Width greater than height is landscape; otherwise it is portrait.
  2. Group consecutive same-orientation pages into batches. Walk the pages in order and start a new batch whenever the orientation changes, so each batch is a contiguous page range with a single orientation.
  3. Print each batch as a separate print job. Sending each range on its own lets the printer apply the correct orientation to that range, instead of forcing the whole document into landscape.
  4. Handle multiple copies manually. Because the document is split across several print jobs, loop once per copy and print the full batch sequence each time, so page order is preserved within every copy.

Full implementation:

using IronPrint;
using IronPdf;

await PrintDocumentByOrientationBatchesAsync(
    documentPath: documentPath,
    printerName: printerName,
    numberOfCopies: effectiveCopies);

async Task PrintDocumentByOrientationBatchesAsync(
    string documentPath,
    string printerName,
    int numberOfCopies)
{
    var tempFolder = Path.Combine(
        Path.GetTempPath(),
        "ironprint-orientation-workaround",
        Guid.NewGuid().ToString("N"));

    Directory.CreateDirectory(tempFolder);

    try
    {
        using var pdf = PdfDocument.FromFile(documentPath);

        var batches = GetConsecutiveOrientationBatches(pdf);

        // Since the document is printed in multiple jobs, copies are handled manually
        // to preserve the full document order per copy.
        for (var copy = 1; copy <= numberOfCopies; copy++)
        {
            foreach (var batch in batches)
            {
                var batchPath = Path.Combine(
                    tempFolder,
                    $"copy_{copy}_pages_{batch.StartPageNumber}_{batch.EndPageNumber}_{batch.Orientation}.pdf");

                using var batchPdf = pdf.CopyPages(batch.StartIndex, batch.EndIndex);
                batchPdf.SaveAs(batchPath);

                var printSettings = new PrintSettings
                {
                    PrinterName = printerName,
                    NumberOfCopies = 1,
                    PaperOrientation = batch.Orientation == DetectedPageOrientation.Landscape
                        ? PaperOrientation.Landscape
                        : PaperOrientation.Portrait,
                    PaperSize = PaperSize.PrinterDefault
                };

                await Printer.PrintAsync(batchPath, printSettings);

                // Optional delay to help ensure print jobs are queued in order.
                await Task.Delay(500);
            }
        }
    }
    finally
    {
        try
        {
            Directory.Delete(tempFolder, recursive: true);
        }
        catch
        {
            // Ignore cleanup errors in case the print spooler is still accessing the files.
        }
    }
}

List<PageOrientationBatch> GetConsecutiveOrientationBatches(PdfDocument pdf)
{
    var batches = new List<PageOrientationBatch>();

    if (pdf.PageCount == 0)
    {
        return batches;
    }

    var currentOrientation = GetPageOrientation(pdf.Pages[0].Width, pdf.Pages[0].Height);
    var batchStartIndex = 0;

    for (var pageIndex = 1; pageIndex < pdf.PageCount; pageIndex++)
    {
        var page = pdf.Pages[pageIndex];
        var pageOrientation = GetPageOrientation(page.Width, page.Height);

        if (pageOrientation != currentOrientation)
        {
            batches.Add(new PageOrientationBatch(
                StartIndex: batchStartIndex,
                EndIndex: pageIndex - 1,
                Orientation: currentOrientation));

            batchStartIndex = pageIndex;
            currentOrientation = pageOrientation;
        }
    }

    batches.Add(new PageOrientationBatch(
        StartIndex: batchStartIndex,
        EndIndex: pdf.PageCount - 1,
        Orientation: currentOrientation));

    return batches;
}

DetectedPageOrientation GetPageOrientation(double width, double height)
{
    return width > height
        ? DetectedPageOrientation.Landscape
        : DetectedPageOrientation.Portrait;
}

record PageOrientationBatch(
    int StartIndex,
    int EndIndex,
    DetectedPageOrientation Orientation)
{
    public int StartPageNumber => StartIndex + 1;
    public int EndPageNumber => EndIndex + 1;
}

enum DetectedPageOrientation
{
    Portrait,
    Landscape
}

Note: This workaround sends each orientation range as a separate print job. On a physical printer, queue the jobs consecutively. With Microsoft Print to PDF or a similar virtual printer, each batch may prompt for its own output file.