作成日: 2021/12/13 最終更新日: 2023/06/22
文書種別
使用方法
詳細
PageCollectionクラスのClonePageメソッドで既存のページをコピー(複製)できます。
using GrapeCity.Documents.Pdf;
using (var fs = new FileStream("sample.pdf", FileMode.Open))
{
var doc = new GcPdfDocument();
doc.Load(fs);
// 1ページ目をコピー
doc.Pages.ClonePage(0, 0, true, true);
doc.Save("ClonePage.pdf");
}
※ClonePageメソッドは V6J SP1 (6.1.3) で追加された機能です。
それ以前のバージョンでは、MergeWithDocumentメソッドを使用して同一のPDFを結合する方法でページをコピーできます。
using (var fs = new System.IO.FileStream("source.pdf", FileMode.Open))
{
var doc_source = new GcPdfDocument();
var doc_copy = new GcPdfDocument();
doc_source.Load(fs);
doc_copy.Load(fs);
var options = new GrapeCity.Documents.Pdf.MergeDocumentOptions();
// 1ページ目から2ページ目までを
options.PagesRange = new GrapeCity.Documents.Common.OutputRange(1, 2);
// 最終ページの後に追加
options.Index = doc_copy.Pages.Count;
doc_copy.MergeWithDocument(doc_source, options);
doc_copy.Save("pagecopy.pdf");
}