作成日: 2019/07/04 最終更新日: 2019/07/04
文書種別
使用方法
詳細
「新規に作成したPDF」に「既存のPDFの一部」を結合して保存する処理を繰り返すことで、結果的に分割することができます。
1ページずつ分割する場合、以下のような処理になります。
◆サンプルコード(VB.NET)
◆サンプルコード(C#)
1ページずつ分割する場合、以下のような処理になります。
◆サンプルコード(VB.NET)
Using fs As New FileStream("FileName.pdf", FileMode.Open, FileAccess.Read)
' 読み込み
Dim doc As New GcPdfDocument()
doc.Load(fs)
' 結合オプション
Dim options As New MergeDocumentOptions()
' 1ページずつ分割する
For i As Integer = 1 To doc.Pages.Count
options.PagesRange = New GrapeCity.Documents.Common.OutputRange(i, i)
Dim separateDoc As New GcPdfDocument()
separateDoc.MergeWithDocument(doc, options)
separateDoc.Save(String.Format("Page{0}.pdf", i))
Next
End Using
' 読み込み
Dim doc As New GcPdfDocument()
doc.Load(fs)
' 結合オプション
Dim options As New MergeDocumentOptions()
' 1ページずつ分割する
For i As Integer = 1 To doc.Pages.Count
options.PagesRange = New GrapeCity.Documents.Common.OutputRange(i, i)
Dim separateDoc As New GcPdfDocument()
separateDoc.MergeWithDocument(doc, options)
separateDoc.Save(String.Format("Page{0}.pdf", i))
Next
End Using
◆サンプルコード(C#)
using (var fs = new FileStream("FileName.pdf", FileMode.Open, FileAccess.Read))
{
// 読み込み
var doc = new GcPdfDocument();
doc.Load(fs);
// 結合オプション
var options = new MergeDocumentOptions();
// 1ページずつ分割する
for (int i = 1; i <= doc.Pages.Count; i++)
{
options.PagesRange = new GrapeCity.Documents.Common.OutputRange(i, i);
var separateDoc = new GcPdfDocument();
separateDoc.MergeWithDocument(doc, options);
separateDoc.Save(String.Format("Page{0}.pdf", i));
}
}
{
// 読み込み
var doc = new GcPdfDocument();
doc.Load(fs);
// 結合オプション
var options = new MergeDocumentOptions();
// 1ページずつ分割する
for (int i = 1; i <= doc.Pages.Count; i++)
{
options.PagesRange = new GrapeCity.Documents.Common.OutputRange(i, i);
var separateDoc = new GcPdfDocument();
separateDoc.MergeWithDocument(doc, options);
separateDoc.Save(String.Format("Page{0}.pdf", i));
}
}
関連情報
旧文書番号
84211