Mixed-Orientation PDF Prints Every Page as Landscape
IronPrint 2026.1.5 does not preserve per-page orientation when printing a PDF that mixes portrait and landscape pages. Every page reaches the printer in landscape, no matter its original orientation.
This affects 2026.1.5 on Windows 10 and Windows Server 2022 under .NET 8. No corrected build exists for this version.
The engine applies a single orientation to the whole document rather than reading each page's dimensions. Splitting the file into runs of same-orientation pages and printing each run separately restores the correct output.
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 every page's width against its height. A page wider than it is tall is landscape; anything else is portrait.
2. Group consecutive same-orientation pages
Walk the pages in order and start a new batch whenever the orientation flips. Each batch ends up as a contiguous page range with one orientation.
3. Print each batch as its own job
Sending each range separately lets the printer apply that range's orientation, rather than forcing the entire document into landscape.
4. Handle multiple copies manually
Because the document is now split across several jobs, loop once per copy and print the full batch sequence each time. This keeps page order intact 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
}
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
}
Imports IronPrint
Imports IronPdf
Imports System.IO
Await PrintDocumentByOrientationBatchesAsync(documentPath:=documentPath, printerName:=printerName, numberOfCopies:=effectiveCopies)
Private Async Function PrintDocumentByOrientationBatchesAsync(documentPath As String, printerName As String, numberOfCopies As Integer) As Task
Dim tempFolder = Path.Combine(Path.GetTempPath(), "ironprint-orientation-workaround", Guid.NewGuid().ToString("N"))
Directory.CreateDirectory(tempFolder)
Try
Using pdf = PdfDocument.FromFile(documentPath)
Dim batches = GetConsecutiveOrientationBatches(pdf)
' Since the document is printed in multiple jobs, copies are handled manually
' to preserve the full document order per copy.
For copy = 1 To numberOfCopies
For Each batch In batches
Dim batchPath = Path.Combine(tempFolder, $"copy_{copy}_pages_{batch.StartPageNumber}_{batch.EndPageNumber}_{batch.Orientation}.pdf")
Using batchPdf = pdf.CopyPages(batch.StartIndex, batch.EndIndex)
batchPdf.SaveAs(batchPath)
Dim printSettings = New PrintSettings With {
.PrinterName = printerName,
.NumberOfCopies = 1,
.PaperOrientation = If(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)
End Using
Next
Next
End Using
Finally
Try
Directory.Delete(tempFolder, recursive:=True)
Catch
' Ignore cleanup errors in case the print spooler is still accessing the files.
End Try
End Try
End Function
Private Function GetConsecutiveOrientationBatches(pdf As PdfDocument) As List(Of PageOrientationBatch)
Dim batches = New List(Of PageOrientationBatch)()
If pdf.PageCount = 0 Then
Return batches
End If
Dim currentOrientation = GetPageOrientation(pdf.Pages(0).Width, pdf.Pages(0).Height)
Dim batchStartIndex = 0
For pageIndex = 1 To pdf.PageCount - 1
Dim page = pdf.Pages(pageIndex)
Dim pageOrientation = GetPageOrientation(page.Width, page.Height)
If pageOrientation <> currentOrientation Then
batches.Add(New PageOrientationBatch(StartIndex:=batchStartIndex, EndIndex:=pageIndex - 1, Orientation:=currentOrientation))
batchStartIndex = pageIndex
currentOrientation = pageOrientation
End If
Next
batches.Add(New PageOrientationBatch(StartIndex:=batchStartIndex, EndIndex:=pdf.PageCount - 1, Orientation:=currentOrientation))
Return batches
End Function
Private Function GetPageOrientation(width As Double, height As Double) As DetectedPageOrientation
Return If(width > height, DetectedPageOrientation.Landscape, DetectedPageOrientation.Portrait)
End Function
Private NotInheritable Class PageOrientationBatch
Public Property StartIndex As Integer
Public Property EndIndex As Integer
Public Property Orientation As DetectedPageOrientation
Public Sub New(StartIndex As Integer, EndIndex As Integer, Orientation As DetectedPageOrientation)
Me.StartIndex = StartIndex
Me.EndIndex = EndIndex
Me.Orientation = Orientation
End Sub
Public ReadOnly Property StartPageNumber As Integer
Get
Return StartIndex + 1
End Get
End Property
Public ReadOnly Property EndPageNumber As Integer
Get
Return EndIndex + 1
End Get
End Property
End Class
Private Enum DetectedPageOrientation
Portrait
Landscape
End Enum
GetConsecutiveOrientationBatches produces one PageOrientationBatch per contiguous run, and Printer.PrintAsync runs each range with its own PaperOrientation. The Task.Delay(500) between jobs helps the spooler queue them in order.

