From 1a61f798764a1029ffae03bf703b4c7e4a892575 Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Wed, 15 Oct 2025 10:37:58 +0300 Subject: [PATCH] PDFCLOUD-5186: added snippets for acroforms --- uses_cases/acroforms/acroforms_aad.go | 35 ++++++++++++++++ uses_cases/acroforms/acroforms_get.go | 26 ++++++++++++ uses_cases/acroforms/acroforms_helper.go | 50 +++++++++++++++++++++++ uses_cases/acroforms/acroforms_launch.go | 15 +++++++ uses_cases/acroforms/acroforms_remove..go | 24 +++++++++++ uses_cases/acroforms/acroforms_set.go | 30 ++++++++++++++ uses_cases/acroforms/acroforms_update.go | 34 +++++++++++++++ 7 files changed, 214 insertions(+) create mode 100644 uses_cases/acroforms/acroforms_aad.go create mode 100644 uses_cases/acroforms/acroforms_get.go create mode 100644 uses_cases/acroforms/acroforms_helper.go create mode 100644 uses_cases/acroforms/acroforms_launch.go create mode 100644 uses_cases/acroforms/acroforms_remove..go create mode 100644 uses_cases/acroforms/acroforms_set.go create mode 100644 uses_cases/acroforms/acroforms_update.go diff --git a/uses_cases/acroforms/acroforms_aad.go b/uses_cases/acroforms/acroforms_aad.go new file mode 100644 index 0000000..53ced3d --- /dev/null +++ b/uses_cases/acroforms/acroforms_aad.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func appendFormFiled(pdf_api *asposepdfcloud.PdfApiService, document_name string, output_name string, remote_folder string) { + uploadFile(pdf_api, document_name) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + textBox := asposepdfcloud.TextBoxField{ + PageIndex: 1, + PartialName: "EMail", + Rect: &asposepdfcloud.Rectangle{LLX: 100, LLY: 100, URX: 180, URY: 120}, + Value: "aspose-pdf-cloud@example.com", + Border: &asposepdfcloud.Border{ + Width: 5, + Dash: &asposepdfcloud.Dash{On: 1, Off: 1}, + }, + } + + _, httpResponse, err := pdf_api.PutTextBoxField(document_name, "EMail", textBox, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + downloadFile(pdf_api, document_name, output_name, "add_form_") + } +} diff --git a/uses_cases/acroforms/acroforms_get.go b/uses_cases/acroforms/acroforms_get.go new file mode 100644 index 0000000..ea8f43d --- /dev/null +++ b/uses_cases/acroforms/acroforms_get.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func getFormFiled(pdf_api *asposepdfcloud.PdfApiService, document_name string, remote_folder string) { + uploadFile(pdf_api, document_name) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + result, httpResponse, err := pdf_api.GetFields(document_name, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + for i, f := range result.Fields.List { + fmt.Println("field > ", i, ": type: '"+string(f.Type_)+"', name: '"+f.Name+",' values: '"+f.Values[0]+"'") + } + } +} diff --git a/uses_cases/acroforms/acroforms_helper.go b/uses_cases/acroforms/acroforms_helper.go new file mode 100644 index 0000000..ba62147 --- /dev/null +++ b/uses_cases/acroforms/acroforms_helper.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "os" + "path" + "path/filepath" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +const ( + REMOTE_FOLDER = "Your_Temp_Pdf_Cloud" + LOCAL_FOLDER = "c:\\Samples" + PDF_DOCUMENT = "sample.pdf" + PDF_OUTPUT_NAME = "output_sample.pdf" + FIELD_NAME = "Signature_1" +) + +func initPdfApi() *asposepdfcloud.PdfApiService { + // Initialize Credentials and create Pdf.Cloud service object + AppSID := "YOUR_APP_SID" // Your Application SID + AppKey := "YOUR_APP_KEY" // Your Application Key + + pdfApi := asposepdfcloud.NewPdfApiService(AppSID, AppKey, "") + return pdfApi +} + +func uploadFile(pdf_api *asposepdfcloud.PdfApiService, name string) { + // Upload local file to the Pdf.Cloud folder + args := map[string]interface{}{ + "folder": REMOTE_FOLDER, + } + file, _ := os.Open(filepath.Join(LOCAL_FOLDER, name)) + fmt.Println("Download file'" + name + "' starting...") + + _, _, _ = pdf_api.UploadFile(filepath.Join(REMOTE_FOLDER, name), file, args) + fmt.Println("File '" + name + "' successfully uploaded!") +} + +func downloadFile(pdf_api *asposepdfcloud.PdfApiService, name string, output_name string, output_prefix string) { + args := map[string]interface{}{ + "folder": REMOTE_FOLDER, + } + result_data, _, _ := pdf_api.DownloadFile(path.Join(REMOTE_FOLDER, name), args) + fileName := path.Join(LOCAL_FOLDER, output_prefix+output_name) + f, _ := os.Create(fileName) + _, _ = f.Write(result_data) + fmt.Println("Result file'" + fileName + "' successfully downloaded!") +} diff --git a/uses_cases/acroforms/acroforms_launch.go b/uses_cases/acroforms/acroforms_launch.go new file mode 100644 index 0000000..62ecfd8 --- /dev/null +++ b/uses_cases/acroforms/acroforms_launch.go @@ -0,0 +1,15 @@ +package main + +func main() { + pdfApi := initPdfApi() + + appendFormFiled(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_NAME, REMOTE_FOLDER) + + getFormFiled(pdfApi, PDF_DOCUMENT, REMOTE_FOLDER) + + deleteFormFiled(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_NAME, FIELD_NAME, REMOTE_FOLDER) + + setFormFiled(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_NAME, FIELD_NAME, REMOTE_FOLDER) + + updateFormFiled(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_NAME, FIELD_NAME, REMOTE_FOLDER) +} diff --git a/uses_cases/acroforms/acroforms_remove..go b/uses_cases/acroforms/acroforms_remove..go new file mode 100644 index 0000000..a3b056d --- /dev/null +++ b/uses_cases/acroforms/acroforms_remove..go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func deleteFormFiled(pdf_api *asposepdfcloud.PdfApiService, document_name string, output_name string, field_name string, remote_folder string) { + uploadFile(pdf_api, document_name) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + _, httpResponse, err := pdf_api.DeleteField(document_name, field_name, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + downloadFile(pdf_api, document_name, output_name, "del_form_") + } +} diff --git a/uses_cases/acroforms/acroforms_set.go b/uses_cases/acroforms/acroforms_set.go new file mode 100644 index 0000000..dcda64d --- /dev/null +++ b/uses_cases/acroforms/acroforms_set.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func setFormFiled(pdf_api *asposepdfcloud.PdfApiService, document_name string, output_name string, field_name string, remote_folder string) { + uploadFile(pdf_api, document_name) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + field := asposepdfcloud.Field{ + Name: "EMail", + Type_: asposepdfcloud.FieldTypeText, + Values: []string{"aspose-pdf-cloud@example.com"}, + } + + _, httpResponse, err := pdf_api.PutUpdateField(document_name, field_name, field, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + downloadFile(pdf_api, document_name, output_name, "upd_form_") + } +} diff --git a/uses_cases/acroforms/acroforms_update.go b/uses_cases/acroforms/acroforms_update.go new file mode 100644 index 0000000..1dac619 --- /dev/null +++ b/uses_cases/acroforms/acroforms_update.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func updateFormFiled(pdf_api *asposepdfcloud.PdfApiService, document_name string, output_name string, field_name string, remote_folder string) { + uploadFile(pdf_api, document_name) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + field := asposepdfcloud.Field{ + Name: field_name, + Type_: asposepdfcloud.FieldTypeText, + Values: []string{"aspose-pdf-cloud@example.com"}, + Rect: &asposepdfcloud.Rectangle{ LLX:125, LLY: 735, URX: 200, URY: 752}, + } + + fields := asposepdfcloud.Fields{}; + fields.List = []asposepdfcloud.Field{ field } + + _, httpResponse, err := pdf_api.PutUpdateFields(document_name, fields, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + downloadFile(pdf_api, document_name, output_name, "upd_form_") + } +}