Method Extract
- Namespace
- BitMiracle.Docotic.Pdf
- Assembly
- BitMiracle.Docotic.Pdf.dll
Extract(int[])
Extracts the pages with the specified indexes into a new PdfDocument.
public PdfDocument Extract(int[] indexes)
Parameters
indexesint[]The zero-based indexes of the pages to extract.
Returns
- PdfDocument
A new PdfDocument containing the extracted pages.
Remarks
You become the owner of the returned PdfDocument and must dispose of it when finished working with it.
The new document is created using the default PdfConfigurationOptions. Use the Extract(int[], PdfConfigurationOptions) overload to specify custom configuration options.
The extracted pages are removed from the current PdfDocument.
This method cannot be used on a document that contains only one page. A PdfException is thrown when attempting to extract pages from a single-page document.
Consider calling RemoveUnusedResources() on the new document. This method can reduce file size when the extracted pages reference unused resources such as fonts, images, or patterns.
This method can be used to split PDF documents. See the Split PDF documents in C# and VB.NET article for examples.
Use Copy or CopyRange to copy pages without removing them from the current PdfDocument.
Exceptions
- ArgumentNullException
Thrown when
indexesisnull.- ArgumentException
Thrown when
indexesis empty.- ArgumentOutOfRangeException
Thrown when an index in the
indexesarray is outside the bounds of the collection.- PdfException
Thrown when the document contains only one page.
Extract(int[], PdfConfigurationOptions)
Extracts the pages with the specified indexes into a new PdfDocument using the provided PdfConfigurationOptions.
public PdfDocument Extract(int[] indexes, PdfConfigurationOptions options)
Parameters
indexesint[]The zero-based indexes of the pages to extract.
optionsPdfConfigurationOptionsThe configuration options for the new document.
Returns
- PdfDocument
A new PdfDocument containing the extracted pages.
Remarks
You become the owner of the returned PdfDocument and must dispose of it when finished working with it.
The new document is created using the specified options.
The extracted pages are removed from the current PdfDocument.
This method cannot be used on a document that contains only one page. A PdfException is thrown when attempting to extract pages from a single-page document.
Consider calling RemoveUnusedResources() on the new document. This method can reduce file size when the extracted pages reference unused resources such as fonts, images, or patterns.
This method can be used to split PDF documents. See the Split PDF documents in C# and VB.NET article for examples.
Use Copy or CopyRange to copy pages without removing them from the current PdfDocument.
Exceptions
- ArgumentNullException
Thrown when
indexesoroptionsisnull.- ArgumentException
Thrown when
indexesis empty.- ArgumentOutOfRangeException
Thrown when an index in the
indexesarray is outside the bounds of the collection.- PdfException
Thrown when the document contains only one page.