Skip to content

Commit 4b15455

Browse files
Aspose.PDF for Go via C++ 25.2
1 parent b6d9c4b commit 4b15455

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2659
-2
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Aspose.PDF Product Family
3+
Copyright (c) 2025 Aspose Pty Ltd
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

LICENSE_COMMERCIAL.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The shared library (DLL, SO, DYLIB) and its associated files are proprietary
2+
and are not covered under the MIT License. Detailed terms and conditions are
3+
specified in the Aspose EULA.
4+
5+
You may obtain a copy of the Aspose EULA at: https://about.aspose.com/legal/eula

README.md

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
# Aspose.PDF for Go via C++
2+
3+
The package asposepdf is a powerful toolkit that allows developers to manipulate PDF files directly and helps do various tasks for PDF.
4+
Contains unique features for converting PDF to other formats.
5+
6+
## Features
7+
8+
### PDF Processing
9+
10+
- **Core operation:** New, Open, Save, SaveAs, Close, SetLicense, WordCount, CharacterCount
11+
- **Page core operation:** Add, Insert, Delete, Count, WordCount, CharacterCount, IsBlank
12+
- **Organize:** Optimize, OptimizeResource, Grayscale, Rotate, SetBackground, Repair
13+
- **Page organize:** Rotate, SetSize, Grayscale, AddText
14+
- **Others:** Get contents as plain text
15+
16+
### PDF converting and saving
17+
18+
- **Microsoft Office:** DOC, DOCX, XLSX, PPTX
19+
- **Images:** JPEG, PNG, BMP, TIFF
20+
- **Others:** EPUB, DICOM, SVG, XPS, TEX, TXT
21+
22+
## Platforms
23+
24+
Implemented support for Linux x64, macOS x86_64, macOS arm64 and Windows x64 platforms. Used [cgo](https://go.dev/wiki/cgo).
25+
26+
The platform-specific version of the dynamic library from the 'lib'-folder in the package's root directory is required for distributing the resulting application:
27+
- *libAsposePDFforGo_linux_amd64.so* for Linux x64 platform
28+
- *libAsposePDFforGo_darwin_arm64.dylib* for macOS arm64 platform
29+
- *libAsposePDFforGo_darwin_amd64.dylib* for macOS x86_64 platform
30+
- *AsposePDFforGo_windows_amd64.dll* for Windows x64 platform.
31+
32+
Windows x64 platform requires [MinGW-W64](https://www.mingw-w64.org/) installed.
33+
34+
## Installation
35+
36+
This package includes a large file which is stored as a bzip2 archive.
37+
38+
1. Add the asposepdf package to Your Project:
39+
```sh
40+
go get github.com/aspose-pdf/aspose-pdf-go-cpp@latest
41+
```
42+
43+
2. Generate the large file:
44+
45+
- **macOS and linux**
46+
47+
1. Open Terminal
48+
49+
2. List the folders of the github.com/aspose-pdf within the Go module cache:
50+
51+
```sh
52+
ls $(go env GOMODCACHE)/github.com/aspose-pdf/
53+
```
54+
55+
3. Change curent folder to the specific version folder of the package obtained in the previous step:
56+
57+
```sh
58+
cd $(go env GOMODCACHE)/github.com/aspose-pdf/[email protected]
59+
```
60+
Replace `@vx.x.x` with the actual package version.
61+
62+
63+
4. Run go generate with superuser privileges:
64+
65+
```sh
66+
sudo go generate
67+
```
68+
69+
- **Windows**
70+
71+
1. Open Command Prompt
72+
73+
2. List the folders of the github.com/aspose-pdf within the Go module cache:
74+
75+
```cmd
76+
for /f "delims=" %G in ('go env GOMODCACHE') do for /d %a in ("%G\github.com\aspose-pdf\*") do echo %~fa
77+
```
78+
79+
3. Change curent folder to the specific version folder of the package obtained in the previous step:
80+
81+
```cmd
82+
cd <specific version folder of the package>
83+
```
84+
85+
4. Run go generate:
86+
87+
```cmd
88+
go generate
89+
```
90+
91+
5. Add specific version folder of the package to the %PATH% environment variable:
92+
93+
```cmd
94+
setx PATH "%PATH%;<specific version folder of the package>\lib\"
95+
```
96+
Replace `<specific version folder of the package>` with the actual path obtained from step 2.
97+
98+
99+
## Quick Start
100+
All code snippets are contained in the [snippet](https://github.com/aspose-pdf/aspose-pdf-go-cpp).
101+
102+
### Hello World!
103+
104+
```go
105+
package main
106+
107+
import "github.com/aspose-pdf/aspose-pdf-go-cpp"
108+
import "log"
109+
110+
func main() {
111+
// Create new PDF-document
112+
pdf, err := asposepdf.New()
113+
if err != nil {
114+
log.Fatal(err)
115+
}
116+
// Add new page
117+
err = pdf.PageAdd()
118+
if err != nil {
119+
log.Fatal(err)
120+
}
121+
// Set page size A4
122+
err = pdf.PageSetSize(1, asposepdf.PageSizeA4)
123+
if err != nil {
124+
log.Fatal(err)
125+
}
126+
// Add text on first page
127+
err = pdf.PageAddText(1, "Hello World!")
128+
if err != nil {
129+
log.Fatal(err)
130+
}
131+
// Save PDF-document with "hello.pdf" name
132+
err = pdf.SaveAs("hello.pdf")
133+
if err != nil {
134+
log.Fatal(err)
135+
}
136+
// Release allocated resources
137+
defer pdf.Close()
138+
}
139+
```
140+
141+
### Save PDF as Office Formats
142+
143+
One of the most popular features of Aspose.PDF for Go via C++ is to convert PDF documents to other formats without needing to understand the underlying structure of the resultant format.
144+
145+
Give the following snippet a try with your samples:
146+
147+
```go
148+
package main
149+
150+
import "github.com/aspose-pdf/aspose-pdf-go-cpp"
151+
import "log"
152+
153+
func main() {
154+
// Open(filename string) opens a PDF-document with filename
155+
pdf, err := asposepdf.Open("sample.pdf")
156+
if err != nil {
157+
log.Fatal(err)
158+
}
159+
// SaveDocX(filename string) saves previously opened PDF-document as DocX-document with filename
160+
err = pdf.SaveDocX("sample.docx")
161+
if err != nil {
162+
log.Fatal(err)
163+
}
164+
// Close() releases allocated resources for PDF-document
165+
defer pdf.Close()
166+
}
167+
```
168+
### Extract Text From Whole PDF
169+
170+
```go
171+
package main
172+
173+
import "github.com/aspose-pdf/aspose-pdf-go-cpp"
174+
import "log"
175+
import "fmt"
176+
177+
func main() {
178+
// Open(filename string) opens a PDF-document with filename
179+
pdf, err := asposepdf.Open("sample.pdf")
180+
if err != nil {
181+
log.Fatal(err)
182+
183+
}
184+
// ExtractText() returns PDF-document contents as plain text
185+
txt, err := pdf.ExtractText()
186+
if err != nil {
187+
log.Fatal(err)
188+
}
189+
// Print
190+
fmt.Println("Extracted text:\n", txt)
191+
// Close() releases allocated resources for PDF-document
192+
defer pdf.Close()
193+
}
194+
```
195+
196+
## Testing
197+
198+
The test run from the root package folder:
199+
200+
```sh
201+
go test -v
202+
```
203+
204+
## License
205+
206+
- The **Go source code** is licensed under the [MIT License](LICENSE).
207+
- The **shared library (`AsposePDFforGo_windows_amd64.dll`, `libAsposePDFforGo_linux_amd64.so`, `libAsposePDFforGo_darwin_amd64.dylib`, `libAsposePDFforGo_darwin_arm64.dylib`)** is proprietary and requires a commercial license.
208+
To use the full functionality, you must obtain a license.
209+
210+
### Evaluation version
211+
212+
You can use Aspose.PDF for Go via C++ free of cost for evaluation.The evaluation version provides almost all functionality of the product with certain limitations. The same evaluation version becomes licensed when you purchase a license and add a couple of lines of code to apply the license.
213+
214+
>If you want to test Aspose.PDF for Go without the evaluation version limitations, you can also request a 30-day Temporary License. Please refer to [How to get a Temporary License?](https://purchase.aspose.com/temporary-license)
215+
216+
### Limitation of an evaluation version
217+
218+
We want our customers to test our components thoroughly before buying so the evaluation version allows you to use it as you would normally.
219+
220+
- **Documents created with an evaluation watermark.** The evaluation version of Aspose.PDF for Go provides full product functionality, but all pages in the generated files are watermarked with the text "Evaluation Only. Created with Aspose.PDF. Copyright 2002-2025 Aspose Pty Ltd." at the top.
221+
- **Limit the number of pages that can be processed.** In the evaluation version, you can only process the first four pages of a document.
222+
223+
### Use in production
224+
225+
A commercial license key is required in a production environment. Please contact us to <a href="https://purchase.aspose.com/buy">purchase a commercial license</a>.
226+
227+
### Apply license
228+
229+
Applying a license to enable full functionality of the Aspose.PDF for Go using a license file (Aspose.PDF.GoViaCPP.lic).
230+
231+
```go
232+
233+
package main
234+
235+
import "github.com/aspose-pdf/aspose-pdf-go-cpp"
236+
import "log"
237+
238+
func main() {
239+
// Open(filename string) opens a PDF-document with filename
240+
pdf, err := asposepdf.Open("sample.pdf")
241+
if err != nil {
242+
log.Fatal(err)
243+
}
244+
// SetLicense(filename string) licenses with filename
245+
err = pdf.SetLicense("Aspose.PDF.GoViaCPP.lic")
246+
if err != nil {
247+
log.Fatal(err)
248+
}
249+
// Working with PDF-document
250+
// ...
251+
// Close() releases allocated resources for PDF-document
252+
defer pdf.Close()
253+
}
254+
```
255+
256+
[Home](https://www.aspose.com/) | [Product Page](https://products.aspose.com/pdf/go-cpp/) | [Docs](https://docs.aspose.com/pdf/go-cpp/) | [Demos](https://products.aspose.app/pdf/family) | [API Reference](https://reference.aspose.com/pdf/go-cpp/) | [Examples](https://github.com/aspose-pdf/aspose-pdf-go-cpp/) | [Blog](https://blog.aspose.com/category/pdf/) | [Search](https://search.aspose.com/) | [Free Support](https://forum.aspose.com/c/pdf) | [Temporary License](https://purchase.aspose.com/temporary-license)

asposepdf_test.go

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// use:
2+
// go test -v
3+
4+
package asposepdf
5+
6+
import (
7+
"fmt"
8+
"os"
9+
"reflect"
10+
"testing"
11+
)
12+
13+
func assert_check_types(t *testing.T, left any, right any) {
14+
if reflect.TypeOf(left) != reflect.TypeOf(right) {
15+
t.Fatalf("Different types: %v (type %v) and %v (type %v)", left, reflect.TypeOf(left), right, reflect.TypeOf(right))
16+
}
17+
}
18+
19+
func assert_eq(t *testing.T, left any, right any) {
20+
assert_check_types(t, left, right)
21+
if !reflect.DeepEqual(left, right) {
22+
t.Errorf("%v != %v", left, right)
23+
}
24+
}
25+
26+
func assert_ne(t *testing.T, left any, right any) {
27+
assert_check_types(t, left, right)
28+
if reflect.DeepEqual(left, right) {
29+
t.Errorf("%v == %v", left, right)
30+
}
31+
}
32+
33+
func TestNewAndSave(t *testing.T) {
34+
35+
pdf_new_filename := fmt.Sprintf("%s/new.pdf", t.TempDir())
36+
37+
pdf_new, err := New()
38+
if err != nil {
39+
t.Errorf("New(): %v", err)
40+
} else {
41+
err = pdf_new.SaveAs(pdf_new_filename)
42+
if err != nil {
43+
t.Errorf("SaveAs(%s): %v", pdf_new_filename, err)
44+
} else {
45+
pdf_empty, err := Open(pdf_new_filename)
46+
if err != nil {
47+
t.Errorf("Open(%s): %v", pdf_new_filename, err)
48+
} else {
49+
err = pdf_empty.Save()
50+
if err != nil {
51+
t.Errorf("Save(%s): %v", pdf_new_filename, err)
52+
}
53+
}
54+
defer pdf_empty.Close()
55+
}
56+
}
57+
defer pdf_new.Close()
58+
59+
// Check file size != 0
60+
fi, err := os.Stat(pdf_new_filename)
61+
if err != nil {
62+
t.Errorf("Stat(%s): %v", pdf_new_filename, err)
63+
}
64+
assert_ne(t, int64(0), fi.Size())
65+
}
66+
67+
func TestPages(t *testing.T) {
68+
69+
pdf, _ := New()
70+
defer pdf.Close()
71+
72+
// Add page
73+
_ = pdf.PageAdd()
74+
// Set page size
75+
_ = pdf.PageSetSize(1, PageSizeA1)
76+
// Insert page at first position
77+
_ = pdf.PageInsert(1)
78+
// Delete first page
79+
_ = pdf.PageDelete(1)
80+
// Gets number of pages
81+
page_count, _ := pdf.PageCount()
82+
// The number of pages must be equal to 1
83+
assert_eq(t, page_count, int32(1))
84+
}
85+
86+
func TestStats(t *testing.T) {
87+
88+
pdf, _ := New()
89+
defer pdf.Close()
90+
91+
// Text with stamp: "Evaluation Only. Created with Aspose.PDF ..."
92+
93+
// Add page
94+
_ = pdf.PageAdd()
95+
// Save
96+
_ = pdf.SaveAs(fmt.Sprintf("%s/stat.pdf", t.TempDir()))
97+
98+
// Word count
99+
word_count, _ := pdf.WordCount()
100+
// The number of word count must be equal to 12
101+
assert_eq(t, word_count, int32(12))
102+
// Character count
103+
character_count, _ := pdf.CharacterCount()
104+
// The number of character count must be equal to 74
105+
assert_eq(t, character_count, int32(74))
106+
107+
// Word count on first page
108+
page_word_count, _ := pdf.PageWordCount(1)
109+
// The number of word count must be equal to 12
110+
assert_eq(t, page_word_count, int32(12))
111+
// Character count on first page
112+
page_character_count, _ := pdf.PageCharacterCount(1)
113+
// The number of character count must be equal to 74
114+
assert_eq(t, page_character_count, int32(74))
115+
116+
// First page is blank? No. Evaluation stamp
117+
page_is_blank, _ := pdf.PageIsBlank(1)
118+
assert_eq(t, page_is_blank, false)
119+
}

0 commit comments

Comments
 (0)