Skip to content

Commit d81dd20

Browse files
Aspose.PDF for Go via C++: Split, SplitAt
1 parent c0de1cb commit d81dd20

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

english/go-cpp/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ type Document struct {
107107
| [AppendPages](./core/appendpages/) | Append selected pages from another PDF-document. |
108108
| [MergeDocuments](./core/mergedocuments/) | Create a new PDF-document by merging the provided PDF-documents. |
109109
| [SplitDocument](./core/splitdocument/) | Create multiple new PDF-documents by extracting pages from the source PDF-document. |
110+
| [Split](./core/split/) | Create multiple new PDF-documents by extracting pages from the current PDF-document. |
110111
| [SplitAtPage](./core/splitatpage/) | Split the PDF-document into two new PDF-documents. |
112+
| [SplitAt](./core/splitat/) | Split the current PDF-document into two new PDF-documents. |
111113
| [Bytes](./core/bytes/) | Return the contents of the PDF-document as a byte slice. |
112114
| [PageAdd](./core/pageadd/) | Add new page in PDF-document. |
113115
| [PageInsert](./core/pageinsert/) | Insert new page at the specified position in PDF-document. |

english/go-cpp/core/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ url: /go-cpp/core/
2323
| [AppendPages](./appendpages/) | Append selected pages from another PDF-document. |
2424
| [MergeDocuments](./mergedocuments/) | Create a new PDF-document by merging the provided PDF-documents. |
2525
| [SplitDocument](./splitdocument/) | Create multiple new PDF-documents by extracting pages from the source PDF-document. |
26+
| [Split](./split/) | Create multiple new PDF-documents by extracting pages from the current PDF-document. |
2627
| [SplitAtPage](./splitatpage/) | Split the PDF-document into two new PDF-documents. |
28+
| [SplitAt](./splitat/) | Split the current PDF-document into two new PDF-documents. |
2729
| [Bytes](./bytes/) | Return the contents of the PDF-document as a byte slice. |
2830
| [PageAdd](./pageadd/) | Add new page in PDF-document. |
2931
| [PageInsert](./pageinsert/) | Insert new page at the specified position in PDF-document. |
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "Split"
3+
second_title: Aspose.PDF for Go via C++
4+
description: "Create multiple new PDF-documents by extracting pages from the current PDF-document."
5+
type: docs
6+
url: /go-cpp/core/split/
7+
---
8+
9+
_Create multiple new PDF-documents by extracting pages from the current PDF-document._
10+
11+
```go
12+
func (document *Document) Split(pagerange string) ([]*Document, error)
13+
```
14+
15+
**Parameters**:
16+
* **pagerange** - string that defines how to split the PDF-document. Each segment, separated by `;`, specifies the page range for a separate output PDF document. The page range syntax supports individual pages, ranges, and open-ended intervals. For example: "1,3,5;7-10", "-3;4-", or "1;2-3;5-"
17+
18+
**Return**:
19+
* **[]\*Document** - slice of new PDF-documents, each containing the pages defined by a corresponding segment of the specified page range
20+
* **error** - contains an error or nil if absent
21+
22+
23+
**Example**:
24+
```go
25+
package main
26+
27+
import (
28+
"fmt"
29+
"github.com/aspose-pdf/aspose-pdf-go-cpp"
30+
"log"
31+
)
32+
33+
func main() {
34+
// Open(filename string) opens a PDF-document with filename
35+
pdf_split, err := asposepdf.Open("sample.pdf")
36+
if err != nil {
37+
log.Fatal(err)
38+
}
39+
// Close() releases allocated resources for PDF-document
40+
defer pdf_split.Close()
41+
42+
// Split(pagerange string) creates multiple new PDF-documents by extracting pages from the current PDF-document
43+
pdfs, err := pdf_split.Split("1-2;3;4-")
44+
if err != nil {
45+
log.Fatal(err)
46+
}
47+
48+
// Save each split PDF-document as a separate file
49+
for i, pdf := range pdfs {
50+
defer pdf.Close()
51+
filename := fmt.Sprintf("sample_Split_part%d.pdf", i+1)
52+
// SaveAs(filename string) saves previously opened PDF-document with new filename
53+
err := pdf.SaveAs(filename)
54+
if err != nil {
55+
log.Fatal(err)
56+
}
57+
}
58+
}
59+
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: "SplitAt"
3+
second_title: Aspose.PDF for Go via C++
4+
description: "Split the current PDF-document into two new PDF-documents."
5+
type: docs
6+
url: /go-cpp/core/splitat/
7+
---
8+
9+
_Split the current PDF-document into two new PDF-documents._
10+
11+
```go
12+
func (document *Document) SplitAt(page int) (*Document, *Document, error)
13+
```
14+
15+
**Parameters**:
16+
* **page** - page number at which to split the PDF-document. Pages up to and including this page go into the first PDF-document
17+
18+
**Return**:
19+
* **\*Document** - new PDF-document containing pages 1 to page (inclusive)
20+
* **\*Document** - new PDF-document containing pages from page + 1 to the end
21+
* **error** - contains an error or nil if absent
22+
23+
24+
**Example**:
25+
```go
26+
package main
27+
28+
import (
29+
"github.com/aspose-pdf/aspose-pdf-go-cpp"
30+
"log"
31+
)
32+
33+
func main() {
34+
// Open(filename string) opens a PDF-document with filename
35+
pdf_split, err := asposepdf.Open("sample.pdf")
36+
if err != nil {
37+
log.Fatal(err)
38+
}
39+
// Close() releases allocated resources for PDF-document
40+
defer pdf_split.Close()
41+
42+
// SplitAt(page int) splits the current PDF-document into two new PDF-documents.
43+
left, right, err := pdf_split.SplitAt(2)
44+
if err != nil {
45+
log.Fatal(err)
46+
}
47+
// Close() releases allocated resources for resulting PDF-documents
48+
defer left.Close()
49+
defer right.Close()
50+
51+
// Save each part as a separate file
52+
err = left.SaveAs("sample_SplitAt_left.pdf")
53+
if err != nil {
54+
log.Fatal(err)
55+
}
56+
err = right.SaveAs("sample_SplitAt_right.pdf")
57+
if err != nil {
58+
log.Fatal(err)
59+
}
60+
}
61+
```

0 commit comments

Comments
 (0)