C# 向け PDF ライブラリ

  • PDFの作成、結合、編集
  • 高機能な組み込み用スタンドアロンPDFビューア
  • Linux、Windows、macOS、Dockerに対応
  • Ahead-of-Time (AOT) の完全サポート
PM>Install-Package Pdfium.Net.SDK NuGet v5.1.3 Downloads 1.8M Published 2026-09-03

.NET向けのエンタープライズ級PDFワークフロー

Pdfium.Net SDKは、基本的なビューイングエンジンを本格的なドキュメントプロセッサへと拡張します。その堅牢なC# / VB.NET APIにより、高度なコンテンツ編集、インタラクティブなフォーム入力、準拠したPDF/A作成、そして想像できる事実上あらゆる機能を実現します。

構造化されたXMLメタデータをパイプラインに直接組み込むことで、電子請求書(Factur-X / ZUGFeRD)の自動化を容易にします。あらゆるドキュメントの課題を解決し、数ヶ月ではなく、わずか数日で本番環境に対応したワークフローを導入できます。

主な機能

  • PDFの生成、結合、分割、編集
  • 組み込み型PDFビューアコンポーネント
  • AcroFormsの完全サポート、インタラクティブフィールド、JavaScript
  • 注釈とコメントの管理
  • 高度なテキストツール:検索、単語/文字の抽出、ウェブリンクの解析
  • しおり、移動先、添付ファイル、ラベル
  • ドキュメントのセキュリティ:パスワード保護と権限フラグ
  • ページジオメトリ(Media/Crop/Bleedボックス)とPDFレイヤー制御
  • PDFカラースペースの完全サポート:RGB、CMYK、ICC、Patternなど
  • 低レベルのページオブジェクト制御(テキスト、パス、シェーディング、画像)
  • PDF/A、ZUGFeRD、Factur-X に完全対応

プラットフォームとインフラストラクチャ

  • GoogleのPDFiumプロジェクトをベースにした圧倒的な処理速度
  • .NET Framework 2.0 から .NET 10 までをサポート
  • クラウドおよびDockerコンテナに対応(Azure、AWSを含む)
  • Ahead-of-Time (AOT) の完全サポート
  • Windowsの対応範囲:x64およびレガシーx86アーキテクチャ
  • Linuxの対応範囲:GLIBC 2.17(x64、x86、ARM、ARM64)、最小OS Ubuntu 16.04+ / Debian 9+
  • Linux Muslの対応範囲:ネイティブなAlpine Linux(x64、x86、ARM、ARM64)Dockerベース
  • macOSの対応範囲:Apple Silicon (arm64) および Intel (x86_64) をサポートする Universal Binary dylib
  • Androidの対応範囲:arm64-v8a、armeabi-v7a、x86_64、x86用の Bionic NDK ターゲット
  • iOSの対応範囲:arm64デバイスおよびシミュレータ(arm64/x86_64)用の独立したスライスを持つ XCFramework

Production-Ready Code Examples

Explore clean, copy-pasteable C# examples for common PDF manipulation tasks. See how easily the SDK integrates into your application pipeline with minimal configuration.

C# を始める:

プログラムで PDF ドキュメントを作成する方法

プログラムで一連の画像から PDF を生成する方法

PDF ファイルを印刷する方法

PDF ファイルを開いてそこからテキストを抽出する方法

PDF ファイル内のテキストを検索する方法

テキストを非同期的に検索する方法

PDFから抽出されたテキストの座標を取得する方法

PDF ドキュメントから画像を抽出する方法

PDF ドキュメントを別々のドキュメントに分割する方法

複数の PDF のページを 1 つのドキュメントに結合する方法

PDF ドキュメントの各ページを画像に変換する方法

プログラムで PDF フィールドからデータを取り込み、抽出する方法

 
/// <summary>
/// Create PDF Document on The Fly in C# using Pdfium.Net SDK Library
/// </summary>
public void CreatePdf()
{
    // The PDF coordinate system origin is at the bottom left corner of the page. 
    // The X-axis is pointing to the right. The Y-axis is pointing in upward direction.
    // The sizes and coordinates in this method are given in the inches.

    // Step 1: Initialize PDF library and create empty document
    // Return value: PdfDocument main class
    PdfCommon.Initialize();
    var doc = PdfDocument.CreateNew();  // Create a PDF document

    // Step 2: Add new page
    // Arguments: page width: 8.27", page height: 11.69", Unit of measure: inches
    //  The PDF unit of measure is point. There are 72 points in one inch.
    var page = doc.Pages.InsertPageAt(doc.Pages.Count, 8.27f * 72, 11.69f * 72);

    // Step 3: Add graphics and text contents to the page
    // Insert image from file using standard System.Drawing.Bitmap class
    using (PdfBitmap logo = PdfBitmap.FromFile(@"c:\examples\logo_square.png"))
    {
        PdfImageObject imageObject = PdfImageObject.Create(doc, logo, 0, 0);
        //image resolution is 300 DPI and location is 1.69 x 10.0 inches.
        imageObject.Matrix = new FS_MATRIX(logo.Width * 72 / 300, 0, 0, logo.Height * 72 / 300, 1.69 * 72, 10.0 * 72);
        page.PageObjects.Add(imageObject);
    }

    // Create fonts used for text objects
    PdfFont calibryBold = PdfFont.CreateFont(doc, "CalibriBold");
    // Insert text objects at 7.69"; 11.02" and font size is 25
    PdfTextObject textObject = PdfTextObject.Create("Sample text", 1.69f * 72, 11.02f * 72, calibryBold, 25);
    textObject.FillColor = FS_COLOR.Black;
    page.PageObjects.Add(textObject);

    // Step 5: Generate page content and save pdf file
    // argument: PDF file name
    page.GenerateContent();
    doc.Save(@"c:\examples\sample_document.pdf", SaveFlags.NoIncremental);
}

C# Pdfium.Net SDK ライブラリを使用すると、開発者は PDF ドキュメントを簡単に作成できます。 この例は、ページ オブジェクトを使用してそのようなドキュメントを作成する方法を示しています。

さまざまなタイプ (テキスト、画像、アウトライン、図形など) のページ オブジェクトを作成して、ページ上の任意の場所に配置できます。

/// <summary>
/// Generate PDF document From Multiple Images in C# using PDF Library
/// </summary>
public void GeneratePdf()
{
    //Initialize C# PDF Library
    PdfCommon.Initialize();
    //Create a PDF document
    using (var doc = PdfDocument.CreateNew())
    {
        //Read images
        var files = System.IO.Directory.GetFiles(@"c:\Examples\Images\", "*.*", System.IO.SearchOption.AllDirectories);
        foreach (var file in files)
        {
            //Create empty PdfBitmap
            using (PdfBitmap pdfBitmap = PdfBitmap.FromFile(file))
            {
                //Create Image object
                var imageObject = PdfImageObject.Create(doc, pdfBitmap, 0, 0);
                //Calculate size of image in PDF points
                var size = CalculateSize(pdfBitmap.Width, pdfBitmap.Height);
                //Add empty page to PDF document
                var page = doc.Pages.InsertPageAt(doc.Pages.Count, size);
                //Insert image to newly created page
                page.PageObjects.Add(imageObject);
                //set image matrix
                imageObject.Matrix = new FS_MATRIX(size.Width, 0, 0, size.Height, 0, 0);
                //Generate PDF page content to content stream
                page.GenerateContent();
            }
        }
        // Save  PDF document as "saved.pdf" in no incremental mode
        doc.Save(@"c:\Examples\test.pdf", SaveFlags.NoIncremental);
    }
}
/// <summary>
/// The function takes width and height of the bitmap in pixels as well as 
/// horizontal and vertical DPI and calculates the size of the PDF page. 
/// To understand the conversion you should know the following:
///     One inch contains exactly 72 PDF points;
///     DPI of the scanned image may vary and depends on scanning resolution
/// </summary>
private FS_SIZEF CalculateSize(int width, int height, float dpiX = 300, float dpiY = 300)
{
    return new FS_SIZEF()
    {
        Width = width * 72 / dpiX,
        Height = height * 72 / dpiY
    };
}

この例では、単純な C# コードと PDF ライブラリを使用して、スキャンした一連の画像から PDF ドキュメントを作成する方法を示します。

/// <summary>
/// Printing PDF Files in C# using PDF Library
/// </summary>
public void PrintPdf()
{
    var doc = PdfDocument.Load(@"c:\Examples\test.pdf");  // Read PDF file
    var printDoc = new PdfPrintDocument(doc);
    printDoc.Print();
}

上記のコードは、デフォルトのプリンターで PDF ドキュメントを印刷します。 また、印刷の進行状況を示す標準の印刷ダイアログも表示されます。 進行状況ウィンドウを非表示にする場合は、次のようにコードを変更します。

public void PrintPdf()
{
    var doc = PdfDocument.Load(@"c:\Examples\test.pdf");
    var printDoc = new PdfPrintDocument(doc);
    PrintController printController = new StandardPrintController();
    printDoc.PrintController = printController;
    printDoc.Print(); // C# Print PDF document
}

PdfPrintDocument は標準の PrintDocument クラスから派生しているため、ユーザー入力に従って PrintDocument を設定する .Net Framework 印刷ダイアログ (PrinterDialog) を使用できます。

public void OnPrintClick()
{
    if (PdfViewer.Document.FormFill != null)
        PdfViewer.Document.FormFill.ForceToKillFocus();

    //create an instance of PrintDocument class
    var printDoc = new PdfPrintDocument(PdfViewer.Document); // create an instance of Print document class that is used for printing PDF document.

    //Create a standard print dialog box
    var dlg = new PrintDialog();
    dlg.AllowCurrentPage = true;
    dlg.AllowSomePages = true;
    dlg.UseEXDialog = true;
    //sets the PrintDocument used to obtain PrinterSettings.
    dlg.Document = printDoc;
    //show PrinterDialog and print pdf document
    if (dlg.ShowDialog() == DialogResult.OK)
        printDoc.Print();   // C# Print PDF
}
 
/// <summary>
/// Read PDF File and Extract Text From it in C#
/// </summary>
public void ExtractText()
{
    //Initialize the SDK library
    //You have to call this function before you can call any PDF processing functions.
    PdfCommon.Initialize();

    //Open and load a PDF document from a file.
    using (var doc = PdfDocument.Load(@"c:\Examples\test.pdf")) // C# Read PDF File
    {
        foreach (var page in doc.Pages)
        {
            //Gets number of characters in a page or -1 for error.
            //Generated characters, like additional space characters, new line characters, are also counted.
            int totalCharCount = page.Text.CountChars;

            //Extract text from page to the string
            string text = page.Text.GetText(0, totalCharCount);

            page.Dispose();
        }
    }
}

Pdfium.Net SDK を使用すると、開発者はほぼすべての PDF ファイルから全文を簡単に抽出できます。

/// <summary>
/// Search for a Text in a PDF File in C# With Pdfium.Net SDK Library
/// </summary>
public void Search()
{
    // Read PDF document and enumerate pages
    using (var doc = PdfDocument.Load(@"c:\Examples\test.pdf")) 
    {
        //Enumerate pages
        foreach (var page in doc.Pages)
        {
            var found = page.Text.Find("text for search", FindFlags.MatchWholeWord, 0);
            if (found == null)
                return; //nothing found
            do
            {
                var textInfo = found.FoundText;
                foreach (var rect in textInfo.Rects)
                {
                    float x = rect.left;
                    float y = rect.top;
                    //...
                }
            } while (found.FindNext());

            page.Dispose();
        }
    }
}

この例では、単純な C# コードと PDF ライブラリを使用してドキュメント内のテキストを検索する方法を示します。

この例では、C# PDF ライブラリを使用してテキストを非同期的に検索する方法を示します。

/// <summary>
/// Extract Text Coordinates from Pdf in C# using PDF Library
/// </summary>
public void ExtractTextInfo()
{
    //Initialize the SDK library
    //You have to call this function before you can call any PDF processing functions.
    PdfCommon.Initialize();

    //Open and load a PDF document from a file.
    using (var doc = PdfDocument.Load(@"c:\Examples\test.pdf")) // C# Read PDF File
    {
        //Get second page from document
        using (var page = doc.Pages[1])
        {
            //Extract text information structure from the page
            // 10 - Index for the start characters
            // 25 - Number of characters to be extracted
            var textInfo = page.Text.GetTextInfo(10, 25);

            //Gets text from textInfo structure
            string text = textInfo.Text;

            //Gets a collection of rectangular areas bounding specified text.
            var rects = textInfo.Rects;
        }
    }
}

Pdfium.Net SDK を使用すると、開発者は任意の PDF ファイルからテキスト座標を簡単に抽出することもできます。

/// <summary>
/// Extracting Images from Pdf File With .Net C# and PDF Library
/// </summary>
private int _writtenImageIndex = 0;

public void ExtractAllImages()
{
    //Initialize the SDK library
    //You have to call this function before you can call any PDF processing functions.
    PdfCommon.Initialize();

    //Open and load a PDF document from a file.
    using (var doc = PdfDocument.Load(@"c:\Examples\test.pdf")) // C# Read PDF File
    {
        //Enumerate all pages sequentially in a given document
        foreach (var page in doc.Pages)
        {
            //Extract and save images
            ExtractImagesFromPage(page);

            //dipose page object to unload it from memory
            page.Dispose();
        }
    }
}

private void ExtractImagesFromPage(PdfPage page)
{
    //Enumerate all objects on a page
    foreach (var obj in page.PageObjects)
    {
        var imageObject = obj as PdfImageObject;
        if (imageObject == null)
            continue; //if not an image object then nothing do

        //Save image to disk
        var path = string.Format(@"c:\Images\image_{0}.png", ++_writtenImageIndex);
        imageObject.Bitmap.Image.Save(path, ImageFormat.Png);
    }
}

この例では、PDF ファイルからさまざまな形式の画像を抽出してディスクに保存する方法を示します。

/// <summary>
/// Split PDF in C# using PDF Library
/// </summary>
public void SplitDocument()
{
    //Initialize the SDK library
    //You have to call this function before you can call any PDF processing functions.
    PdfCommon.Initialize();

    //Open and load a PDF document from a file.
    using (var sourceDoc = PdfDocument.Load(@"c:\Examples\test.pdf")) // C# Read PDF File
    {
        //Create one PDF document for pages 1-5.
        using (var doc = PdfDocument.CreateNew())
        {
            //Import pages from source document
            doc.Pages.ImportPages(sourceDoc, "1-5", 0);
            //And save it to doc1.pdf
            doc.Save(@"c:\Examples\doc1.pdf", SaveFlags.Incremental);
        }

        //Create another PDF document for pages 5-10.
        using (var doc = PdfDocument.CreateNew())
        {
            //Also import pages
            doc.Pages.ImportPages(sourceDoc, "5-10", 0);
            //And save them too
            doc.Save(@"c:\Examples\doc2.pdf", SaveFlags.Incremental);
        }
    }
}

次のコード例は、PDF ライブラリを使用してドキュメントを個別のページに分割する方法を示しています。

/// <summary>
/// Merge PDFs in C# using PDF Library
/// </summary>
public void MergePdf()
{
    //Initialize the SDK library
    //You have to call this function before you can call any PDF processing functions.
    PdfCommon.Initialize();

    //Open and load a PDF document in which will be merged other files
    using (var mainDoc = PdfDocument.Load(@"c:\Examples\test.pdf")) // C# Read source PDF File #1
    {
        //Open one PDF document.
        using (var doc = PdfDocument.Load(@"c:\Examples\doc1.pdf")) //Read PDF File #2
        {
            //Import all pages from document
            mainDoc.Pages.ImportPages(
                doc,
                string.Format("1-{0}", doc.Pages.Count),
                mainDoc.Pages.Count
                );
        }

        //Open another PDF document.
        using (var doc = PdfDocument.Load(@"c:\Examples\doc2.pdf"))
        {
            //Import all pages from document
            mainDoc.Pages.ImportPages(
                doc,
                string.Format("1-{0}", doc.Pages.Count),
                mainDoc.Pages.Count
                );
        }

        mainDoc.Save(@"c:\Examples\ResultDocument.pdf", SaveFlags.NoIncremental);
    }
}

C# PDF ライブラリを使用すると、ソース ファイルから特定のページを選択し、それらを 1 つの PDF ドキュメントにマージできます。

この例は、ImportPages 操作を使用してこれを行う方法を示しています。

/// <summary>
/// Render whole PDF document using C# PDF Library
/// </summary>
public void RenderPages()
{
    using (var doc = PdfDocument.Load(@"c:\Examples\test.pdf")) // C# Read PDF Document
    {
        int idx = 0;
        foreach (var page in doc.Pages)
        {
            int width = (int)(page.Width / 72.0 * 96);
            int height = (int)(page.Height / 72.0 * 96);
            using (var bitmap = new PdfBitmap(width, height, true))
            {
                bitmap.FillRect(0, 0, width, height, FS_COLOR.White);
                page.Render(bitmap, 0, 0, width, height, PageRotate.Normal, RenderFlags.FPDF_LCD_TEXT);
                bitmap.Image.Save($"c:\\Examples\\page_{idx++}", ImageFormat.Png);
            }
        }
    }
}

In this example we create a bitmap of each page, so we calculate the required width and height of the bitmap in pixels converted from the dimensions of the PDF page in Points. Each Point is 1/72 of an inch, so we basically take the vertical or horizontal DPI of the image (96 in our example), multiply it to corresponding dimension and divide by 72.

Next we create a new PdfBitmap using the dimensions we just computed. The last parameter of the constructor tells to use the true color mode.

Then we fill the entire bitmap with white and render the page to it. That's all!

/// <summary>
/// Filling Editable PDF Fields and Extracting Data From Them using .Net PDF Library
/// </summary>
public void FillFields()
{
    var doc = PdfDocument.Load(@"c:\Examples\test.pdf", new PdfForms()); // C# Read PDF Document

    int i = 0;
    foreach (var field in doc.FormFill.InterForm.Fields)
    {
        if (field.FieldType == Patagames.Pdf.Enums.FormFieldTypes.FPDF_FORMFIELD_TEXTFIELD)
        {
            field.Value = "This is a field #" + (++i);
        }
    }
}

この例では、.Net PDF ライブラリを使用して、PDF ドキュメントの編集可能なフォームにプログラムで入力する方法を示します。

 

利用可能な開発者サポート

製品ライセンスを購入すると、優れたライブラリ以上のものを手に入れることができます。 それを最大限に活用するために、開発チームから直接 12 か月間の無料テクニカル サポートと 1 年間の無料アップデートも利用できます。

あなたの最新リリースを試してみましたが、完璧に動作します ― 私の両方の問題を解決します! リクエストに応えていただきありがとうございます ―大変感謝しています。 [他の製品] を一部のレガシー プロジェクトで使用していますが、すべての新しいプロジェクトで使用を中止しています。 [他の製品] ライブラリ自体は優れていますが、サポートが貧弱であることがわかりました ― 間違いなく、Pdfium.NET サポートは、速度と品質の両方ではるかに優れていることが証明されています!
繰り返しますが、最高のサービスと優れた製品に感謝します。 -Terry
The link is hidden due to ethical concerns.

シンプルさに重点を置いているため、アプリケーションに集中できます

Pdfium.Net SDK を開発する主な目標は、開発者にとって物事をシンプルかつ直感的に保つことです。 クラス ライブラリは、基礎となる pdfium ライブラリの使用に関するすべての詳細を抽象化し、ワールド オブジェクトおよびその他の直感的なクラスに基づくインターフェイスを提供します。

また、Pdfium.Net SDK は十分に文書化されています! 初心者と経験豊富なユーザーに Pdfium.Net SDK で可能なことの概要を提供することを目的とした広範なドキュメントを提供します。

 

エンタープライズおよびクラウド サービス向けに最適化

One of our targets is to provide developers with high quality tool for dynamic PDF creation on any server system like Microsoft Azure.

お客様の SDK が Azure にデプロイされたときに機能することを確認しました (私がテストしたいくつかの製品は機能しませんでした。宣伝してください)。 購入しました。
またよろしくお願いします! -Cyberg
https://forum.patagames.com/posts/m1105-Workability-in-various-environments#post1105

PDF ビューアの埋め込みコンポーネント

.Net アプリケーションでの PDF ドキュメントの表示

.Net アプリケーションで PDF ファイルを表示する機能を実装してください! 複数のビュー モード、微調整、および完全なフォーム サポートにより、PDF ビューアーはアプリケーションにシームレスに適合し、デザインに適応します。

  • 完全にカスタマイズ可能なインターフェース
  • インタラクティブフォームのサポート
  • 柔軟な事件処理
  • 簡単なインテグレーション
  • オープンソースコードー
WPF Viewer Winforms Viewer
C# PDF Viewer
PdfViewer の外見の詳細については、 ドキュメントを参照してください。

Pdfium.Net SDK

ダウンロードー

NuGet パッケージは、nuget.org の公式リポジトリで入手できます。

PM> Install-Package Pdfium.Net.SDK
NuGet v5.1.3 Downloads 1.8M Published 2026-09-03

作成されたのは

Microsoft .Net Framework 2.0+ Microsoft .Net Standard 2.0+ Microsoft Visual Studio NuGet Microsoft Azure