Windows
ComPDFKit PDF SDK
Guides

Document Editor

 

ComPDFKit PDF SDK provides a wide range of APIs for document editing operations. These are mostly available through the CPDFDocument and CPDFPage classes.

 

ComPDFKit PDF SDK benefits include:

 

- PDF manipulation

- Split pages

- Merge pages

- Extract pages

 

- Page edit

- Delete pages

- Insert pages (choose from another document, a blank page, or an image)

- Move pages

- Rotate pages

- Exchange pages

- Replace pages

- Crop pages

 

- Access document information

 

- Extract image

 

 

PDF Manipulation

 

Split pages

 

CPDFDocument can extract ranges of pages from one document and put them into another document. If you run this operation multiple times with different page indexes, you can effectively split a PDF into as many documents as you require.

 

To split a PDF document into multiple pages, please use the following method:

 

1. Create a blank PDF document.

CPDFDocument document = CPDFDocument.CreateDocument();

 

2.  Open a PDF document that contains the pages you want to split.

CPDFDocument document1 = CPDFDocument.InitWithFilePath("filePath");

 

3. Extract specific pages from the PDF document that you just opened, and import them into the blank PDF document.

// Pages that need to be split, e.g. 2 to 5 pages
document.ImportPagesAtIndex(document1,"2-5",0);

 

4. Save the document.

// Save path
document.WriteToFilePath("savePath");

 

Merge pages

 

ComPDFKit PDF SDK allows you to instantiate multiple CPDFDocument, and you can use the CPDFDocument API to merge multiple PDF files into a single one.

 

To merge PDF documents into one file, please use the following method:

 

1. Create a blank PDF document.

CPDFDocument document = CPDFDocument.CreateDocument();

 

2. Open the PDF documents that contain the pages you want to merge.

// File path
CPDFDocument document1 = CPDFDocument.InitWithFilePath("filePath");

// File path
CPDFDocument document2 = CPDFDocument.InitWithFilePath("filePath2");

 

3. Merge all the pages from the documents you just opened, and import them into the blank PDF document.

 ```c#
     document.ImportPagesAtIndex(document1,"1-10",document.PageCount);
     document.ImportPagesAtIndex(document2,"1-10",document.PageCount);
     ```

 

4. Save the document.

// Save path
document.WriteToFilePath("savePath");

 

The sample code above allows you to merge all the pages from the two documents. If you’re looking to merge or add specific pages from one document to another, you can use importPages of CPDFDocument::importPages:fromDocument:atIndex: to set specific pages.

 

Extract pages

 

CPDFDocument can extract ranges of pages from one document and put them into a blank document. If you run this operation, you can effectively extract a PDF as you require. Refer to the split pages for more details.