PDFでページを追加、コピー、削除する方法

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

によって ジョルディ・バルディア

PDFにページを追加することは、ドキュメントに新しいコンテンツ(テキスト、画像、既存のPDFページなど)を挿入することを意味します。 PDFでページをコピーするとは、同じドキュメント内または別のPDFファイルから一つ以上のページを複製することを意味します。 PDFからページを削除することは、ドキュメントから不要なページを取り除くことを意味します。

ページを追加したり、コピーしたり、PDFドキュメントから削除したりすることができ、IronPDFはこれを簡単かつ迅速に行うために必要なすべてのツールを提供します。

PDF 用 C# NuGet ライブラリ

でインストール NuGet

Install-Package IronPdf
または
Java PDF JAR(ジャバPDF JAR)

ダウンロード DLL (ディーエルエル)

DLLをダウンロード

プロジェクトに手動でインストールする

PDF 用 C# NuGet ライブラリ

でインストール NuGet

Install-Package IronPdf
または
Java PDF JAR(ジャバPDF JAR)

ダウンロード DLL (ディーエルエル)

DLLをダウンロード

プロジェクトに手動でインストールする

今日からプロジェクトでIronPDFを使い始めましょう。無料のトライアルをお試しください。

最初のステップ:
green arrow pointer

チェックアウト IronPDF オン Nuget 迅速なインストールと展開のために。8百万以上のダウンロード数により、PDFをC#で変革しています。

PDF 用 C# NuGet ライブラリ nuget.org/packages/IronPdf/
Install-Package IronPdf

インストールを検討してください IronPDF DLL 直接。ダウンロードして、プロジェクトまたはGACの形式で手動でインストールしてください。 IronPdf.zip

プロジェクトに手動でインストールする

DLLをダウンロード

PDFにページを追加

PDFにページを追加するには、1行のコードで実行できます。 この例では、レポートのPDFが生成され、その冒頭にカバーページが追加されます。 両方のPDFを結合するには、『Merge メソッド』を使用します。 この2つのPDFドキュメントを例に取ってみましょう: カバーページ.pdf そして contentPage.pdf.

:path=/static-assets/pdf/content-code-examples/how-to/add-copy-delete-pages-pdf-add.cs
using IronPdf;

// Import cover page
PdfDocument coverPage = PdfDocument.FromFile("coverPage.pdf");

// Import content document
PdfDocument contentPage = PdfDocument.FromFile("contentPage.pdf");

// Merge the two documents
PdfDocument finalPdf = PdfDocument.Merge(coverPage, contentPage);

finalPdf.SaveAs("pdfWithCover.pdf");
Imports IronPdf

' Import cover page
Private coverPage As PdfDocument = PdfDocument.FromFile("coverPage.pdf")

' Import content document
Private contentPage As PdfDocument = PdfDocument.FromFile("contentPage.pdf")

' Merge the two documents
Private finalPdf As PdfDocument = PdfDocument.Merge(coverPage, contentPage)

finalPdf.SaveAs("pdfWithCover.pdf")
VB   C#

次のコードを実行すると、表紙が前面にある1つのPDFファイルが出力されます:

InsertPdf メソッドを使用して、PDFの任意のインデックスにページを追加することもできます。 この例では、「contentPage.pdf」の冒頭に「coverPage.pdf」を挿入することで、上記の効果を達成しています。

:path=/static-assets/pdf/content-code-examples/how-to/add-copy-delete-pages-pdf-insert.cs
using IronPdf;

// Import cover page
PdfDocument coverPage = PdfDocument.FromFile("coverPage.pdf");

// Import content document
PdfDocument contentPage = PdfDocument.FromFile("contentPage.pdf");

// Insert PDF
contentPage.InsertPdf(coverPage, 0);
Imports IronPdf

' Import cover page
Private coverPage As PdfDocument = PdfDocument.FromFile("coverPage.pdf")

' Import content document
Private contentPage As PdfDocument = PdfDocument.FromFile("contentPage.pdf")

' Insert PDF
contentPage.InsertPdf(coverPage, 0)
VB   C#

PDFからページをコピー

PDFからページをコピーするには、単にCopyPageまたはCopyPagesメソッドを呼び出します。 これらはそれぞれ、単一ページおよび複数ページをコピーするために使用されます。 メソッドは、指定されたページを含む PdfDocument オブジェクトを返します。

:path=/static-assets/pdf/content-code-examples/how-to/add-copy-delete-pages-pdf-copy.cs
using IronPdf;
using System.Collections.Generic;

// Copy a single page into a new PDF object
PdfDocument myReport = PdfDocument.FromFile("report_final.pdf");
PdfDocument copyOfPageOne = myReport.CopyPage(0);

// Copy multiple pages into a new PDF object
PdfDocument copyOfFirstThreePages = myReport.CopyPages(new List<int> { 0, 1, 2 });
Imports IronPdf
Imports System.Collections.Generic

' Copy a single page into a new PDF object
Private myReport As PdfDocument = PdfDocument.FromFile("report_final.pdf")
Private copyOfPageOne As PdfDocument = myReport.CopyPage(0)

' Copy multiple pages into a new PDF object
Private copyOfFirstThreePages As PdfDocument = myReport.CopyPages(New List(Of Integer) From {0, 1, 2})
VB   C#

PDFのページを削除する

PDF からページを削除するには、RemovePage または RemovePages メソッドを呼び出すことができます。 これらは、それぞれ単一ページおよび複数ページのコピーを削除するために使用されます。

:path=/static-assets/pdf/content-code-examples/how-to/add-copy-delete-pages-pdf-delete.cs
using IronPdf;
using System.Collections.Generic;

PdfDocument pdf = PdfDocument.FromFile("full_report.pdf");

// Remove a single page
pdf.RemovePage(0);

// Remove multiple pages
pdf.RemovePages(new List<int> { 2, 3 });
Imports IronPdf
Imports System.Collections.Generic

Private pdf As PdfDocument = PdfDocument.FromFile("full_report.pdf")

' Remove a single page
pdf.RemovePage(0)

' Remove multiple pages
pdf.RemovePages(New List(Of Integer) From {2, 3})
VB   C#

ジョルディ・バルディア

ソフトウェアエンジニア

ジョルディは、Iron Softwareでのスキルを活かしていないときには、ゲームプログラミングをしており、Python、C#、C++に最も堪能です。彼は製品テスト、製品開発、研究の責任を共有しており、継続的な製品改善に大きな価値をもたらしています。この多様な経験は彼を常に挑戦的で魅力的に保ち、彼はIron Softwareで働く一番好きな側面の一つだと言っています。ジョルディはフロリダ州マイアミで育ち、フロリダ大学でコンピューターサイエンスと統計学を学びました。