IRONSOFTWAREHOME

異なる方向が混在するPDF、すべてのページが横向きに印刷される

Curtis Chau
Curtis Chau
Updated: 2026年7月3日

IronPrint 2026.1.5 は、縦向きと横向きのページが混在するPDFを印刷する際に、ページごとの向きを保持しません。 すべてのページは、その元の向きに関係なく、横向きでプリンターに送られます。

これは、2026.1.5 の下でWindows 10およびWindows Server 2022で.NET 8に影響します。このバージョンには修正済みのビルドは存在しません。

エンジンは、各ページの寸法を読むのではなく、ドキュメント全体に単一の向きを適用します。 同じ方向のページごとのランにファイルを分割し、各ランを別々に印刷することで、正しい出力を回復します。

解決策

推奨: 単一のジョブとしてではなく、向きが一致するバッチでPDFを印刷してください。

1. 各ページの向きを検出する

PDFを開き、各ページの幅を高さと比較します。 幅が高さより広いページは横向きです; それ以外のものは縦向きです。

2. 連続する同じ向きのページをグループ化する

ページを順番に進め、向きが変わるたびに新しいバッチを開始します。 各バッチは、1つの向きのある連続したページ範囲として終わります。

3. 各バッチをそれ自身のジョブとして印刷する

各範囲を別々に送信することで、プリンターがその範囲の向きを適用でき、文書全体を無理に横向きにすることを防ぎます。

4. 複数のコピーを手動で処理する

文書が複数のジョブに分割されているため、コピーごとに1回ループして、各回でフルバッチシーケンスを印刷します。これにより、各コピー内でページの順序がそのまま保たれます。

完全な実装:

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
}
C#

GetConsecutiveOrientationBatches は連続したランごとに1つのPageOrientationBatch を生成し、 Printer.PrintAsync は各範囲をそれぞれのPaperOrientation で実行します。 ジョブ間のTask.Delay(500) は、スプーラーがそれらを順番にキューに入れるのを助けます。

警告: 各向きの範囲を別々の印刷ジョブとして送信します。 物理プリンターではジョブが連続してキューに入り、Microsoft Print to PDFや同様の仮想プリンターの場合、各バッチで独自の出力ファイルを求められることがあります。)]
Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

...
詳しく読む

準備はできましたか?

Nuget Downloads 46,090バージョン:2026.9リリースされたばかり

あなたの無料30日間の試用キーをすぐに入手。
クレジットカードやアカウントの作成は不要です。
PDF用C# NuGetライブラリ
NuGetでインストール

バージョン: 2026.9

PM > Install-Package IronPrint
nuget.org/packages/IronPrint/
  1. ソリューションエクスプローラーで参照を右クリックし、NuGetパッケージを管理を選択
  2. ブロウズを選択し、「IronPrint」を検索します
  3. パッケージを選択してインストール
C# PDF DLL
DLLをダウンロード

バージョン: 2026.9

  1. IronPrintをダウンロードし、解凍して、ソリューションディレクトリ内の~/Libsなどの場所に配置します。
  2. Visual Studioのソリューションエクスプローラーで参照を右クリックし、ブロウズから「IronPrint.dll」を選択。

$999からのライセンス

Key in blue circle

無料の30日間トライアルキーをすぐに入手してください。

Your trial license will be sent to your email address

制限なし。100% ロック解除済み。クレジットカード不要。

bullet_checkedクレジットカードやアカウントの作成は不要です。制限なし。100% ロック解除済み。クレジットカード不要。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
無料のライブデモを予約する
Booking Badge

世界中の数百万人のエンジニアから信頼されています。

ライセンスはより安く
義務のない相談を受ける
下記のフォームを記入するか、sales@ironsoftware.comにメールしてください。
あなたの詳細は常に守秘されます。
世界中の数百万人のエンジニアから信頼されています。
ライセンスはより安く
あなたの無料30日間の試用キーをすぐに入手。
クレジットカードやアカウントの作成は不要です。