For testing the callas PDF toolbox SDK, I want to convert a sample PDF to a PNG. The callas license is activated. In my main() function, I successfully initialize the SDK. After that, I call the create method.
Here is my main() method:
func main() {
log.SetOutput(os.Stdout)
log.Println("Starting program")
// Set up library path before initializing SDK
setupLibraryPath()
log.Println("Initializing SDK...")
sdk, err := callas.NewCallasSDKWrapper()
if err != nil {
log.Printf("Failed to initialize SDK: %v\n", err)
os.Exit(1)
}
defer func() {
log.Println("Closing SDK...")
if err := sdk.Close(); err != nil {
log.Printf("Error closing SDK: %v", err)
}
}()
// Verify that sample.pdf exists
_, err = os.Stat("sample.pdf")
if err != nil {
log.Printf("Error: sample.pdf not found: %v", err)
log.Println("Current directory contents:")
files, _ := os.ReadDir(".")
for _, file := range files {
log.Printf(" %s", file.Name())
}
os.Exit(3)
}
log.Println("SDK initialized, creating thumbnail...")
err = sdk.CreateThumbnail("sample.pdf", "sample.png", 80)
if err != nil {
log.Printf("Failed to create thumbnail: %v\n", err)
os.Exit(2)
}
log.Println("Thumbnail created successfully")
}
Here are the logs:
2025/05/22 10:42:22 Creating thumbnail: converting 'sample.pdf' to 'sample.png' at resolution 80
2025/05/22 10:42:22 Calling PTB_SaveAsImage...
2025/05/22 10:42:22 Failed to create thumbnail: error code 8195
2025/05/22 10:42:22 Failed to create thumbnail: Failed to create thumbnail: error code 8195
Error code 8195 means: PTB_eerrFileDestFolderExist = 8195 / 0x2003 /
This is my create method:
// createThumbnail is a Go-friendly wrapper for creating a thumbnail.
func createThumbnail(pdfPath string, pngPath string, resolution int) error {
log.Printf("Creating thumbnail: converting '%s' to '%s' at resolution %d", pdfPath, pngPath, resolution)
cPdfPath := C.CString(pdfPath)
defer C.free(unsafe.Pointer(cPdfPath))
cPngPath := C.CString(pngPath)
defer C.free(unsafe.Pointer(cPngPath))
cResolution := C.uint(resolution)
// Call the PTB_SaveAsImage function from the C API
log.Println("Calling PTB_SaveAsImage...")
result := C.PTB_SaveAsImage(
(*C.PTB_Path_t)(unsafe.Pointer(cPdfPath)),
C.PTB_ePNG, // Image format
(*C.PTB_sys_char_t)(unsafe.Pointer(&cResolution)),
C.PTB_eBaseline_Standard, // JPEG format (not applicable for PNG)
C.PTB_eJPEG_low, // Compression (not applicable for PNG)
0, // First page
0, // Last page (0 for all pages)
(*C.PTB_Path_t)(unsafe.Pointer(cPngPath)),
nil, // Callback function (optional)
nil, // Callback user data
nil, // Progress callback (optional)
nil, // Progress callback user data
)
if result != C.PTB_eerrNone {
errorMsg := fmt.Sprintf("Failed to create thumbnail: error code %d", result)
log.Println(errorMsg)
return fmt.Errorf(errorMsg)
}
log.Println("Thumbnail created successfully")
return nil
}
The PTB_SaveAsImage function is comming from the C API of the callas SDK C-Libary.
Why do I get PTB_eerrFileDestFolderExist even though the output file path seems valid?
PTB_SaveAsImagereturnsPTB_eerrFileDestFolderExist = 8195 / 0x2003 /. Just a guess based on the name: Does the error code mean that the destination file already exists?