혼합 방향 PDF가 모든 페이지를 가로 방향으로 인쇄

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPrint 2026.1.5는 세로 및 가로 페이지가 혼합된 PDF를 인쇄할 때 각 페이지의 방향을 유지하지 않습니다. 모든 페이지가 원본 방향에 상관없이 가로 방향으로 프린터에 도달합니다.

이 문제는 Windows 10 및 Windows Server 2022에서 .NET 8 하의 2026.1.5에 영향을 미치며, 해당 버전에 대한 수정된 빌드는 존재하지 않습니다.

엔진은 각 페이지의 크기를 읽는 대신 문서 전체에 하나의 방향을 적용합니다. 파일을 동일한 방향의 페이지 묶음으로 나누고 각 묶음을 개별적으로 인쇄하면 올바른 출력이 복원됩니다.

해결책

권장 사항: PDF를 단일 작업으로 인쇄하는 대신 방향이 일치하는 묶음으로 인쇄하십시오.

1. 각 페이지의 방향 감지

PDF를 열고 각 페이지의 너비를 높이와 비교합니다. 가로가 세로보다 넓은 페이지는 가로 방향입니다; 그 외에는 세로 방향입니다.

2. 연속적인 동일한 방향의 페이지 그룹화

페이지를 순서대로 진행하며 방향이 바뀔 때마다 새 배치를 시작합니다. 각 배치는 하나의 방향으로 연속적인 페이지 범위가 됩니다.

3. 각 배치를 자체 작업으로 인쇄

각 범위를 개별적으로 보내면 프린터가 해당 범위의 방향을 적용할 수 있으며, 문서 전체를 가로로 강제하지 않습니다.

4. 여러 복사본 수동 처리

문서가 여러 작업으로 나뉘었기 때문에 복사본마다 한 번씩 루프하고 매번 전체 배치 순서를 인쇄합니다. 이는 각 복사본 안에서 페이지 순서를 유지합니다.

전체 구현:

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
$vbLabelText   $csharpLabel

GetConsecutiveOrientationBatches는 하나의 PageOrientationBatch를 연결된 실행마다 생성하고, Printer.PrintAsync 각 범위를 자체 PaperOrientation로 실행합니다. 작업 간의 Task.Delay(500)는 스풀러가 순서대로 큐에 넣는 데 도움이 됩니다.

경고각 방향 범위는 별도의 인쇄 작업으로 전송됩니다. 실제 프린터에서는 작업이 연속적으로 큐에 들어가지만, Microsoft Print to PDF나 유사한 가상 프린터를 사용할 경우 각 배치가 자체 출력 파일을 요구할 수 있습니다.

Curtis Chau
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.

시작할 준비 되셨나요?
Nuget 다운로드 44,923 | 버전: 2026.7 방금 출시
Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요? PM > Install-Package IronPrint
샘플을 실행하세요 문서가 프린터로 전송되는 것을 지켜보세요.