Skip to content

Commit ac288da

Browse files
Aspose.PDF for Go via C++ 25.6
1 parent cedceaf commit ac288da

10 files changed

+75
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Contains unique features for converting PDF to other formats.
88
### PDF Processing
99

1010
- **Main core operation:** New, Open, Save, SaveAs, Close, SetLicense, Append, AppendPages, MergeDocuments, SplitDocument, SplitAtPage
11-
- **Other core operation:** WordCount, CharacterCount
11+
- **Other core operation:** WordCount, CharacterCount, Bytes
1212
- **Page main core operation:** Add, Insert, Delete, Count
1313
- **Page other core operation:** WordCount, CharacterCount, IsBlank
1414
- **Organize:** Optimize, OptimizeResource, Grayscale, Rotate, SetBackground, Repair, Flatten

asposepdf_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,20 @@ func TestRepair(t *testing.T) {
544544
t.Errorf("Repair(): %v", err)
545545
}
546546
}
547+
548+
func TestBytes(t *testing.T) {
549+
550+
pdf, err := New()
551+
if err != nil {
552+
t.Fatalf("New(): %v", err)
553+
}
554+
defer pdf.Close()
555+
556+
data, err := pdf.Bytes()
557+
if err != nil {
558+
t.Fatalf("Bytes(): %v", err)
559+
}
560+
561+
// Assert that the byte slice is not empty
562+
assert_ne(t, int64(0), int64(len(data)))
563+
}

document.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,28 @@ func (document *Document) AppendPages(anotherdocument *Document, pagerange strin
927927
}
928928
}
929929

930+
// Bytes returns the contents of the PDF-document as a byte slice.
931+
//
932+
// Example:
933+
//
934+
// bytes, err := pdf.Bytes()
935+
func (document *Document) Bytes() ([]byte, error) {
936+
var err *C.char
937+
var buf *C.uchar
938+
var size C.int
939+
940+
C.PDFDocument_Save_Memory(document.pdf, &buf, &size, &err)
941+
defer C.c_free_string(err)
942+
943+
err_str := C.GoString(err)
944+
if err_str != "" || buf == nil || size == 0 {
945+
return nil, fmt.Errorf("failed to get PDF bytes: %s", err_str)
946+
}
947+
948+
defer C.c_free_buffer(unsafe.Pointer(buf))
949+
return C.GoBytes(unsafe.Pointer(buf), size), nil
950+
}
951+
930952
// PageCount returns page count in PDF-document.
931953
//
932954
// Example:

extern_c.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extern "C" {
5858
ASPOSE_PDF_RUST_SHARED_API void PDFDocument_Export_Xml(void* pdfdocumentclass, const char* filename, const char** error);
5959
ASPOSE_PDF_RUST_SHARED_API void PDFDocument_Append(void* pdfdocumentclass, const void* otherpdfdocumentclass, const char** error);
6060
ASPOSE_PDF_RUST_SHARED_API void PDFDocument_AppendPages(void* pdfdocumentclass, const void* otherpdfdocumentclass, const char* pagerange, const char** error);
61+
ASPOSE_PDF_RUST_SHARED_API void PDFDocument_Save_Memory(void* pdfdocumentclass, unsigned char** bufferOut, int* sizeOut, const char** error);
6162
ASPOSE_PDF_RUST_SHARED_API int PDFDocument_Page_get_Count(void* pdfdocumentclass, const char** error);
6263
ASPOSE_PDF_RUST_SHARED_API void PDFDocument_Page_Add(void* pdfdocumentclass, const char** error);
6364
ASPOSE_PDF_RUST_SHARED_API void PDFDocument_Page_Insert(void* pdfdocumentclass, int num, const char** error);
@@ -92,6 +93,7 @@ extern "C" {
9293
extern "C" {
9394
#endif
9495
ASPOSE_PDF_RUST_SHARED_API void c_free_string(char* str);
96+
ASPOSE_PDF_RUST_SHARED_API void c_free_buffer(void* buffer);
9597
#ifdef __cplusplus
9698
}
9799
#endif
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
42219401e34d82bb50d801370031a24ed3857cce605f9d7078b8dd5d0c8c205f
1+
7c54e5ffd13c5cb9eccf19b435f7a3b47080059a9c4c4b9ac1b54759751d662d
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
af8a3be7eca97cbe670a57e43893526964da442f467683362064f6390380cffa
1+
6fca0ecc07fc16e91b9b134abc450cc8b04e42228749062330557934cfe718d7
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0b4261eedd1256bd3ce39e9df8768b10108de5b151291aab00f21196f8b3f44b
1+
2f3caff246c92ed6f485bf2fd8f2af029ae276f0e6da2d984a74de60eb660bfc
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d3e1beb1c4d385de66d636557d63cacd2d2ad8544d18674a46d4a181dc2f793f
1+
7d1ec8af8ef74c4bcaeed560187f574b79ceb35901b4f62645a6663b6833dbd4

snippets/Bytes.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"github.com/aspose-pdf/aspose-pdf-go-cpp"
5+
"log"
6+
"os"
7+
)
8+
9+
func main() {
10+
// New creates a new PDF-document
11+
pdf, err := asposepdf.New()
12+
if err != nil {
13+
log.Fatal(err)
14+
}
15+
defer pdf.Close()
16+
17+
// Bytes returns the contents of the PDF-document as a byte slice
18+
bytes, err := pdf.Bytes()
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
// Save the byte slice to a file.
24+
err = os.WriteFile("sample_Bytes.pdf", bytes, 0644)
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
}

unzip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"strings"
2121
)
2222

23-
const verLibsTag = "v1.25.5"
23+
const verLibsTag = "v1.25.6"
2424
const repoLibsURL = "https://raw.githubusercontent.com/aspose-pdf/aspose-pdf-go-cpp-libs/"
2525
const repoLibsDir = "libs/"
2626

0 commit comments

Comments
 (0)