1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C#を使ってPDFのページを回転させる

Posted at

私たちの毎日の仕事では、我々は時々、PDF文書内のページの方向がドキュメントを読むことは非常に不便になり、逆になっていることがわかります。このケースでは、PDFファイルのページの向きを調整する必要があります。

この記事では、C#と無料PDFライブラリ – Free Spire.PDF for .NETを使用してPDFファイル内のページを回転させる方法を共有します。

無料の.NET PDF APIをインストールする

Free Spire.PDFは、PDFファイルを生成、処理、変換、印刷するための無料の.NET PDFライブラリです。

それをインストールするには、それをダウンロードし、参照として手動でSpire.PDF.dllを追加することができます。または、Nuget経由で直接インストールすることもできます。

C#でPDFのページを回転させる方法

ステップ:

  1. PdfDocument インスタンスを作成します。
  2. PDF文書を読み込みます。
  3. 回転するページを取得します。
  4. ページの現在の回転角度を取得します。
  5. 現在の回転角度(0/90/180/270度)に基づいてページを回転させます。
  6. 結果文書を保存する。

C#コード:

using Spire.Pdf;

namespace RotatePdfPage
{
    class Program
    {
        static void Main(string[] args)
        {
            //PDF文書を読み込む
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("input.pdf");

            //最初のページを見る
            PdfPageBase page = pdf.Pages[0];

            //ページの元の回転角度を取得する
            int rotation = (int)page.Rotation;

            //元の回転角度に基づき、ページを時計回りに90度回転させる。
            rotation += (int)PdfPageRotateAngle.RotateAngle90;
            page.Rotation = (PdfPageRotateAngle)rotation;

            //結果文書を保存する
            pdf.SaveToFile("RotatePDF.pdf");
        }
    }
}

入力 & 出力:
RotatePDF.png


C# におけるさらなる PDF 処理機能については、以下を参照してください:

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?