From af6a8553f696fad7fe78a2065db77661941bb69b Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Wed, 16 Jul 2025 11:52:13 +0300 Subject: [PATCH 01/13] PDFCLOUD-4966: added snippets for Annotations --- uses_cases/annotations/annotations_helper.go | 133 ++++++++++++++++++ uses_cases/annotations/annotations_launch.go | 17 +++ .../append_free_text_annotation.go | 51 +++++++ .../append_highlight_annotation.go | 49 +++++++ .../append_strikeout_annotation.go | 48 +++++++ .../append_underline_annotation.go | 49 +++++++ uses_cases/annotations/extract_annotation.go | 24 ++++ .../annotations/extract_annotattions.go | 24 ++++ uses_cases/annotations/replace_annotation.go | 24 ++++ 9 files changed, 419 insertions(+) create mode 100644 uses_cases/annotations/annotations_helper.go create mode 100644 uses_cases/annotations/annotations_launch.go create mode 100644 uses_cases/annotations/append_free_text_annotation.go create mode 100644 uses_cases/annotations/append_highlight_annotation.go create mode 100644 uses_cases/annotations/append_strikeout_annotation.go create mode 100644 uses_cases/annotations/append_underline_annotation.go create mode 100644 uses_cases/annotations/extract_annotation.go create mode 100644 uses_cases/annotations/extract_annotattions.go create mode 100644 uses_cases/annotations/replace_annotation.go diff --git a/uses_cases/annotations/annotations_helper.go b/uses_cases/annotations/annotations_helper.go new file mode 100644 index 0000000..64ff119 --- /dev/null +++ b/uses_cases/annotations/annotations_helper.go @@ -0,0 +1,133 @@ +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_HIGHLIGHT = "output_highlight.pdf" + PDF_OUTPUT_STRIKEOUT = "output_strikeout.pdf" + PDF_OUTPUT_FREETEXT = "output_freetext.pdf" + PDF_OUTPUT_UNDERLINE = "output_underline.pdf" + + NEW_HIGHLIGHT_TEXT = "NEW HIGHLIGHT TEXT ANNOTATION" + NEW_HIGHLIGHT_DESCRIPTION = "This is a sample highlight annotation" + NEW_HIGHLIGHT_SUBJECT = "Highlight Text Box Subject" + NEW_HIGHLIGHT_CONTENTS = "Highlight annotation sample contents" + + NEW_STRIKEOUT_TEXT = "NEW STRIKEOUT TEXT ANNOTATION" + NEW_STRIKEOUT_DESCRIPTION = "This is a sample strikeout annotation" + NEW_STRIKEOUT_SUBJECT = "Strikeout Text Box Subject" + NEW_STRIKEOUT_CONTENTS = "Strikeout annotation sample contents" + + NEW_FREETEXT_TEXT = "NEW FREE TEXT ANNOTATION" + NEW_FREETEXT_DESCRIPTION = "This is a sample free text annotation" + NEW_FREETEXT_SUBJECT = "Free Text Box Subject" + NEW_FREETEXT_CONTENTS = "Free text annotation sample contents" + + NEW_UNDERLINE_TEXT = "NEW UNDERLINE TEXT ANNOTATION" + NEW_UNDERLINE_DESCRIPTION = "This is a sample underline annotation" + NEW_UNDERLINE_SUBJECT = "Underline Text Box Subject" + NEW_UNDERLINE_CONTENTS = "Underline annotation sample contents" + + ANNOTATION_ID = "GI5TAOZVG42CYOBRG4WDKOJVFQ4DGOA" + + PAGE_NUMBER = 1 + PAGE_NUMBER_EXTRACT = 2 +) + +var ( + LINK_RECT = asposepdfcloud.Rectangle{LLX: 270, LLY: 510, URX: 380, URY: 530} +) + +func initPdfApi() *asposepdfcloud.PdfApiService { + // Initialize Credentials and create Pdf.Cloud service object + AppSID := "******" // Your Application SID + AppKey := "******" // Your Application Key + + pdfApi := asposepdfcloud.NewPdfApiService(AppSID, AppKey, "") + return pdfApi +} + +// Upload local file to the remote folder with check errors +func uploadFile(pdf_api *asposepdfcloud.PdfApiService, name string) { + args := map[string]interface{}{ + "folder": REMOTE_FOLDER, + } + file, err := os.Open(filepath.Join(LOCAL_FOLDER, name)) + if err != nil { + fmt.Println(err.Error()) + } else { + result, httpResponse, err := pdf_api.UploadFile(path.Join(REMOTE_FOLDER, name), file, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + fmt.Println(result) + } + } +} + +// Download file from remote folder and save it locally with check errors +func downloadFile(pdf_api *asposepdfcloud.PdfApiService, name string, output_name string) { + args := map[string]interface{}{ + "folder": REMOTE_FOLDER, + } + result_data, httpResponse, err := pdf_api.DownloadFile(path.Join(REMOTE_FOLDER, name), args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + fileName := path.Join(LOCAL_FOLDER, output_name) + f, _ := os.Create(fileName) + _, _ = f.Write(result_data) + fmt.Println("File '" + fileName + "'successfully downloaded.") + } +} + +// Show Annotations from array +func showAnnotations(links *[]asposepdfcloud.AnnotationInfo) { + for i := 0; i < len(*links); i++ { + fmt.Print("annotation #") + fmt.Println(i) + fmt.Print("\tId == '") + fmt.Print((*links)[i].Id) + fmt.Println("'") + fmt.Print("\tName == '") + fmt.Print((*links)[i].Name) + fmt.Println("'") + fmt.Print("\tContents == '") + fmt.Print((*links)[i].Contents) + fmt.Println("'") + } +} + +// Show Annotation +func showAnnotation(annotation *asposepdfcloud.TextAnnotation) { + fmt.Print("annotation '") + fmt.Println(annotation.Title) + fmt.Println("'") + fmt.Print("\tId == '") + fmt.Print(annotation.Id) + fmt.Println("'") + fmt.Print("\tName == '") + fmt.Print(annotation.Name) + fmt.Println("'") + fmt.Print("\tContents == '") + fmt.Print(annotation.Contents) + fmt.Println("'") + + fmt.Print("\tIcon == '") + fmt.Print(annotation.Icon) + fmt.Println("'") +} diff --git a/uses_cases/annotations/annotations_launch.go b/uses_cases/annotations/annotations_launch.go new file mode 100644 index 0000000..8538d9c --- /dev/null +++ b/uses_cases/annotations/annotations_launch.go @@ -0,0 +1,17 @@ +package main + +func main() { + pdfApi := initPdfApi() + + appendHighlightAnnotation(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_HIGHLIGHT, PAGE_NUMBER, NEW_HIGHLIGHT_TEXT, NEW_HIGHLIGHT_SUBJECT, NEW_HIGHLIGHT_CONTENTS, NEW_HIGHLIGHT_DESCRIPTION, &LINK_RECT, REMOTE_FOLDER) + + appendStrikeoutAnnotation(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_STRIKEOUT, PAGE_NUMBER, NEW_STRIKEOUT_TEXT, NEW_STRIKEOUT_SUBJECT, NEW_STRIKEOUT_CONTENTS, NEW_STRIKEOUT_DESCRIPTION, &LINK_RECT, REMOTE_FOLDER) + + appendFreeTextAnnotation(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_FREETEXT, PAGE_NUMBER, NEW_FREETEXT_TEXT, NEW_FREETEXT_SUBJECT, NEW_FREETEXT_CONTENTS, NEW_FREETEXT_DESCRIPTION, &LINK_RECT, REMOTE_FOLDER) + + appendUnderlineAnnotation(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_UNDERLINE, PAGE_NUMBER, NEW_UNDERLINE_TEXT, NEW_UNDERLINE_SUBJECT, NEW_UNDERLINE_CONTENTS, NEW_UNDERLINE_DESCRIPTION, &LINK_RECT, REMOTE_FOLDER) + + getAnnotations(pdfApi, PDF_DOCUMENT, PAGE_NUMBER_EXTRACT, REMOTE_FOLDER) + + getAnnotation(pdfApi, PDF_DOCUMENT, ANNOTATION_ID, REMOTE_FOLDER) +} diff --git a/uses_cases/annotations/append_free_text_annotation.go b/uses_cases/annotations/append_free_text_annotation.go new file mode 100644 index 0000000..7217cae --- /dev/null +++ b/uses_cases/annotations/append_free_text_annotation.go @@ -0,0 +1,51 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func appendFreeTextAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, output_document string, page_num int32, text string, subject string, contents string, description string, rect *asposepdfcloud.Rectangle, remote_folder string) { + uploadFile(pdf_api, document) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + text_style := asposepdfcloud.TextStyle{ + FontSize: 20, + Font: "Arial", + ForegroundColor: &asposepdfcloud.Color{A: 0xFF, R: 0x00, G: 0xFF, B: 0x00}, + BackgroundColor: &asposepdfcloud.Color{A: 0xFF, R: 0xFF, G: 0x00, B: 0x00}, + } + + new_annotation := asposepdfcloud.FreeTextAnnotation{ + TextStyle: &text_style, + Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, + HorizontalAlignment: asposepdfcloud.HorizontalAlignmentCenter, + Intent: asposepdfcloud.FreeTextIntentFreeTextTypeWriter, + RichText: text, + Subject: subject, + Contents: contents, + ZIndex: 1, + Title: description, + Justification: asposepdfcloud.JustificationCenter, + Rect: rect, + Name: "Free_Text_Annotation", + Modified: "05/22/2025 11:30:00.000 AM", + } + + result, httpResponse, err := pdf_api.PostPageFreeTextAnnotations( + document, page_num, []asposepdfcloud.FreeTextAnnotation{new_annotation}, args, + ) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + fmt.Println(result) + + downloadFile(pdf_api, document, output_document) + } +} diff --git a/uses_cases/annotations/append_highlight_annotation.go b/uses_cases/annotations/append_highlight_annotation.go new file mode 100644 index 0000000..c51ac33 --- /dev/null +++ b/uses_cases/annotations/append_highlight_annotation.go @@ -0,0 +1,49 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func appendHighlightAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, output_document string, page_num int32, text string, subject string, contents string, description string, rect *asposepdfcloud.Rectangle, remote_folder string) { + uploadFile(pdf_api, document) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + new_annotation := asposepdfcloud.HighlightAnnotation{ + Rect: rect, + Name: "Highlight_Text_Annotation", + Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, + HorizontalAlignment: asposepdfcloud.HorizontalAlignmentLeft, + VerticalAlignment: asposepdfcloud.VerticalAlignmentTop, + RichText: text, + Subject: subject, + Contents: contents, + ZIndex: 1, + Title: description, + Color: &asposepdfcloud.Color{A: 0x00, R: 0x00, G: 0xFF, B: 0x00}, + QuadPoints: []asposepdfcloud.Point{ + {X: 10, Y: 10}, + {X: 20, Y: 10}, + {X: 10, Y: 20}, + {X: 10, Y: 10}, + }, + Modified: "03/27/2025 00:00:00.000 AM", + //Icon: "Conment", + } + result, httpResponse, err := pdf_api.PostPageHighlightAnnotations( + document, page_num, []asposepdfcloud.HighlightAnnotation{new_annotation}, args, + ) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + fmt.Println(result) + + downloadFile(pdf_api, document, output_document) + } +} diff --git a/uses_cases/annotations/append_strikeout_annotation.go b/uses_cases/annotations/append_strikeout_annotation.go new file mode 100644 index 0000000..c7a71bc --- /dev/null +++ b/uses_cases/annotations/append_strikeout_annotation.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func appendStrikeoutAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, output_document string, page_num int32, text string, subject string, contents string, description string, rect *asposepdfcloud.Rectangle, remote_folder string) { + uploadFile(pdf_api, document) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + new_annotation := asposepdfcloud.StrikeOutAnnotation{ + Rect: rect, + Name: "Strikeout_Text_Annotation", + Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, + HorizontalAlignment: asposepdfcloud.HorizontalAlignmentLeft, + VerticalAlignment: asposepdfcloud.VerticalAlignmentTop, + RichText: text, + Subject: subject, + Contents: contents, + ZIndex: 1, + Title: description, + Color: &asposepdfcloud.Color{A: 0x00, R: 0x00, G: 0xFF, B: 0x00}, + QuadPoints: []asposepdfcloud.Point{ + {X: 10, Y: 10}, + {X: 20, Y: 10}, + {X: 10, Y: 20}, + {X: 10, Y: 10}, + }, + Modified: "05/22/2025 11:30:00.000 AM", + } + result, httpResponse, err := pdf_api.PostPageStrikeOutAnnotations( + document, page_num, []asposepdfcloud.StrikeOutAnnotation{new_annotation}, args, + ) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + fmt.Println(result) + + downloadFile(pdf_api, document, output_document) + } +} diff --git a/uses_cases/annotations/append_underline_annotation.go b/uses_cases/annotations/append_underline_annotation.go new file mode 100644 index 0000000..43b8a6c --- /dev/null +++ b/uses_cases/annotations/append_underline_annotation.go @@ -0,0 +1,49 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func appendUnderlineAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, output_document string, page_num int32, text string, subject string, contents string, description string, rect *asposepdfcloud.Rectangle, remote_folder string) { + uploadFile(pdf_api, document) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + new_annotation := asposepdfcloud.UnderlineAnnotation{ + Rect: rect, + Name: "Underline_Text_Annotation", + Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, + HorizontalAlignment: asposepdfcloud.HorizontalAlignmentLeft, + VerticalAlignment: asposepdfcloud.VerticalAlignmentTop, + RichText: text, + Subject: subject, + Contents: contents, + ZIndex: 1, + Title: description, + Color: &asposepdfcloud.Color{A: 0x00, R: 0x00, G: 0xFF, B: 0x00}, + QuadPoints: []asposepdfcloud.Point{ + {X: 10, Y: 10}, + {X: 20, Y: 10}, + {X: 10, Y: 20}, + {X: 10, Y: 10}, + }, + Modified: "05/22/2025 11:30:00.000 AM", + } + + result, httpResponse, err := pdf_api.PostPageUnderlineAnnotations( + document, page_num, []asposepdfcloud.UnderlineAnnotation{new_annotation}, args, + ) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + fmt.Println(result) + + downloadFile(pdf_api, document, output_document) + } +} diff --git a/uses_cases/annotations/extract_annotation.go b/uses_cases/annotations/extract_annotation.go new file mode 100644 index 0000000..9dd16fc --- /dev/null +++ b/uses_cases/annotations/extract_annotation.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func getAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, annotation_id string, remote_folder string) { + uploadFile(pdf_api, document) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + result, httpResponse, err := pdf_api.GetTextAnnotation(document, annotation_id, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + showAnnotation(result.Annotation) + } +} diff --git a/uses_cases/annotations/extract_annotattions.go b/uses_cases/annotations/extract_annotattions.go new file mode 100644 index 0000000..a51ad0c --- /dev/null +++ b/uses_cases/annotations/extract_annotattions.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func getAnnotations(pdf_api *asposepdfcloud.PdfApiService, document string, page_num int32, remote_folder string) { + uploadFile(pdf_api, document) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + result, httpResponse, err := pdf_api.GetPageAnnotations(document, page_num, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + showAnnotations(&result.Annotations.List) + } +} diff --git a/uses_cases/annotations/replace_annotation.go b/uses_cases/annotations/replace_annotation.go new file mode 100644 index 0000000..7f3f4f1 --- /dev/null +++ b/uses_cases/annotations/replace_annotation.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func replaceAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, annotation_id string, remote_folder string) { + uploadFile(pdf_api, document) + + args := map[string]interface{}{ + "folder": remote_folder, + } + + result, httpResponse, err := pdf_api.GetDocumentAnnotations(document, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") + } else { + showAnnotations(&result.Annotations.List) + } +} From 71fdadcf16f42fb48b774fc92f302b51c0840a24 Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Thu, 17 Jul 2025 22:29:04 +0300 Subject: [PATCH 02/13] Update annotations_helper.go --- uses_cases/annotations/annotations_helper.go | 169 +++++++++---------- 1 file changed, 77 insertions(+), 92 deletions(-) diff --git a/uses_cases/annotations/annotations_helper.go b/uses_cases/annotations/annotations_helper.go index 64ff119..0137e3b 100644 --- a/uses_cases/annotations/annotations_helper.go +++ b/uses_cases/annotations/annotations_helper.go @@ -10,124 +10,109 @@ import ( ) const ( - REMOTE_FOLDER = "Your_Temp_Pdf_Cloud" - LOCAL_FOLDER = "c:\\Samples" - PDF_DOCUMENT = "sample.pdf" - PDF_OUTPUT_HIGHLIGHT = "output_highlight.pdf" - PDF_OUTPUT_STRIKEOUT = "output_strikeout.pdf" - PDF_OUTPUT_FREETEXT = "output_freetext.pdf" - PDF_OUTPUT_UNDERLINE = "output_underline.pdf" - - NEW_HIGHLIGHT_TEXT = "NEW HIGHLIGHT TEXT ANNOTATION" - NEW_HIGHLIGHT_DESCRIPTION = "This is a sample highlight annotation" - NEW_HIGHLIGHT_SUBJECT = "Highlight Text Box Subject" - NEW_HIGHLIGHT_CONTENTS = "Highlight annotation sample contents" - - NEW_STRIKEOUT_TEXT = "NEW STRIKEOUT TEXT ANNOTATION" - NEW_STRIKEOUT_DESCRIPTION = "This is a sample strikeout annotation" - NEW_STRIKEOUT_SUBJECT = "Strikeout Text Box Subject" - NEW_STRIKEOUT_CONTENTS = "Strikeout annotation sample contents" - - NEW_FREETEXT_TEXT = "NEW FREE TEXT ANNOTATION" - NEW_FREETEXT_DESCRIPTION = "This is a sample free text annotation" - NEW_FREETEXT_SUBJECT = "Free Text Box Subject" - NEW_FREETEXT_CONTENTS = "Free text annotation sample contents" - - NEW_UNDERLINE_TEXT = "NEW UNDERLINE TEXT ANNOTATION" - NEW_UNDERLINE_DESCRIPTION = "This is a sample underline annotation" - NEW_UNDERLINE_SUBJECT = "Underline Text Box Subject" - NEW_UNDERLINE_CONTENTS = "Underline annotation sample contents" - - ANNOTATION_ID = "GI5TAOZVG42CYOBRG4WDKOJVFQ4DGOA" - - PAGE_NUMBER = 1 - PAGE_NUMBER_EXTRACT = 2 -) - -var ( - LINK_RECT = asposepdfcloud.Rectangle{LLX: 270, LLY: 510, URX: 380, URY: 530} + LOCAL_FOLDER = "C:\\Samples" + REMOTE_FOLDER = "Your_Temp_Pdf_Cloud" + PDF_DOCUMENT_NAME = "sample.pdf" + PDF_OUTPUT = "output_sample.pdf" + PAGE_NUMBER = 1 + + ANNOTATION_ID = "GE5TAOZTHA2CYMRZGUWDIMBZFQZTEMA" + + NEW_HL_ANNOTATION_TEXT = "NEW HIGHLIGHT TEXT ANNOTATION" + NEW_HL_ANNOTATION_DESCRIPTION = "This is a sample highlight annotation" + NEW_HL_ANNOTATION_SUBJECT = "Highlight Text Box Subject" + NEW_HL_ANNOTATION_CONTENTS = "Highlight annotation sample contents" + + NEW_SO_ANNOTATION_TEXT = "NEW STRIKEOUT TEXT ANNOTATION" + NEW_SO_ANNOTATION_DESCRIPTION = "This is a sample strikeout annotation" + NEW_SO_ANNOTATION_SUBJECT = "Strikeout Text Box Subject" + NEW_SO_ANNOTATION_CONTENTS = "Strikeout annotation sample contents" + + NEW_UL_ANNOTATION_TEXT = "NEW UNDERLINE TEXT ANNOTATION" + NEW_UL_ANNOTATION_DESCRIPTION = "This is a sample underline annotation" + NEW_UL_ANNOTATION_SUBJECT = "Underline Text Box Subject" + NEW_UL_ANNOTATION_CONTENTS = "Underline annotation sample contents" + + NEW_FT_ANNOTATION_TEXT = "NEW FREE TEXT ANNOTATION" + NEW_FT_ANNOTATION_DESCRIPTION = "This is a sample annotation" + NEW_FT_ANNOTATION_SUBJECT = "Free Text Box Subject" + NEW_FT_ANNOTATION_CONTENTS = "Free Text annotation sample contents" + + REPLACED_CONTENT = "This is a replaced sample annotation" ) -func initPdfApi() *asposepdfcloud.PdfApiService { +func InitPdfApi() *asposepdfcloud.PdfApiService { // Initialize Credentials and create Pdf.Cloud service object - AppSID := "******" // Your Application SID - AppKey := "******" // Your Application Key + AppSID := "*********" // Your Application SID + AppKey := "*********" // Your Application Key pdfApi := asposepdfcloud.NewPdfApiService(AppSID, AppKey, "") return pdfApi } -// Upload local file to the remote folder with check errors -func uploadFile(pdf_api *asposepdfcloud.PdfApiService, name string) { +func UploadFile(pdf_api *asposepdfcloud.PdfApiService, name string) { + // Upload local file to the Pdf.Cloud folder args := map[string]interface{}{ "folder": REMOTE_FOLDER, } - file, err := os.Open(filepath.Join(LOCAL_FOLDER, name)) + file, _ := os.Open(filepath.Join(LOCAL_FOLDER, name)) + _, httpResponse, err := pdf_api.UploadFile(filepath.Join(REMOTE_FOLDER, name), file, args) if err != nil { fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("Unexpected error!") } else { - result, httpResponse, err := pdf_api.UploadFile(path.Join(REMOTE_FOLDER, name), file, args) - if err != nil { - fmt.Println(err.Error()) - } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { - fmt.Println("Unexpected error!") + fmt.Println("Result file'" + name + "' successfully uploaded!") + } +} + +func SaveByteArrayToFile(local_folder string, file_name string, data []byte) { + // Save byte array data to the local folder + fileName := path.Join(local_folder, file_name) + f, err := os.Create(fileName) + if err != nil { + fmt.Println(err) + } else { + size, err := f.Write(data) + if err != nil || size == 0 { + fmt.Println("Failures in downloading result!") } else { - fmt.Println(result) + fmt.Println("Result file'" + fileName + "' successfully downloaded!") } } } -// Download file from remote folder and save it locally with check errors -func downloadFile(pdf_api *asposepdfcloud.PdfApiService, name string, output_name string) { +func DownloadFile(pdf_api *asposepdfcloud.PdfApiService, name string, output_name string, prefix string) { + // Download modified Pdf document to local folder from the Pdf.Cloud folder args := map[string]interface{}{ "folder": REMOTE_FOLDER, } - result_data, httpResponse, err := pdf_api.DownloadFile(path.Join(REMOTE_FOLDER, name), args) + result_data, _, _ := pdf_api.DownloadFile(path.Join(REMOTE_FOLDER, name), args) + SaveByteArrayToFile(LOCAL_FOLDER, prefix+output_name, result_data) +} + +func DeletePopupAnnotations(pdf_api *asposepdfcloud.PdfApiService, document_name string, parent_annotation string) { + // Delete popup annotations for typed parent annotation in the page in the PDF document. + args := map[string]interface{}{ + "folder": REMOTE_FOLDER, + } + result, httpResponse, err := pdf_api.GetDocumentPopupAnnotations(document_name, args) if err != nil { fmt.Println(err.Error()) } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { fmt.Println("Unexpected error!") } else { - fileName := path.Join(LOCAL_FOLDER, output_name) - f, _ := os.Create(fileName) - _, _ = f.Write(result_data) - fmt.Println("File '" + fileName + "'successfully downloaded.") - } -} - -// Show Annotations from array -func showAnnotations(links *[]asposepdfcloud.AnnotationInfo) { - for i := 0; i < len(*links); i++ { - fmt.Print("annotation #") - fmt.Println(i) - fmt.Print("\tId == '") - fmt.Print((*links)[i].Id) - fmt.Println("'") - fmt.Print("\tName == '") - fmt.Print((*links)[i].Name) - fmt.Println("'") - fmt.Print("\tContents == '") - fmt.Print((*links)[i].Contents) - fmt.Println("'") + for _, annotation := range result.Annotations.List { + if annotation.Parent.Id == parent_annotation { + _, response, err2 := pdf_api.DeleteAnnotation(document_name, annotation.Id, args) + if err2 != nil { + fmt.Println(err2) + } else if response.StatusCode < 200 || response.StatusCode > 299 { + fmt.Println("delete_popup_annotations(): Failed to delete popup annotation in the document.") + } else { + fmt.Println("delete_popup_annotations(): popup annotation id = '" + annotation.Id + "' for '" + annotation.Contents + "' deleted in the document '" + PDF_DOCUMENT_NAME + "'.") + } + } + } } } - -// Show Annotation -func showAnnotation(annotation *asposepdfcloud.TextAnnotation) { - fmt.Print("annotation '") - fmt.Println(annotation.Title) - fmt.Println("'") - fmt.Print("\tId == '") - fmt.Print(annotation.Id) - fmt.Println("'") - fmt.Print("\tName == '") - fmt.Print(annotation.Name) - fmt.Println("'") - fmt.Print("\tContents == '") - fmt.Print(annotation.Contents) - fmt.Println("'") - - fmt.Print("\tIcon == '") - fmt.Print(annotation.Icon) - fmt.Println("'") -} From 12448bde5a1a96118e51442331a81b6888691332 Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Thu, 17 Jul 2025 22:30:03 +0300 Subject: [PATCH 03/13] Update annotations_launch.go --- uses_cases/annotations/annotations_launch.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/uses_cases/annotations/annotations_launch.go b/uses_cases/annotations/annotations_launch.go index 8538d9c..8030a18 100644 --- a/uses_cases/annotations/annotations_launch.go +++ b/uses_cases/annotations/annotations_launch.go @@ -1,17 +1,22 @@ package main func main() { - pdfApi := initPdfApi() + pdfApi := InitPdfApi() - appendHighlightAnnotation(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_HIGHLIGHT, PAGE_NUMBER, NEW_HIGHLIGHT_TEXT, NEW_HIGHLIGHT_SUBJECT, NEW_HIGHLIGHT_CONTENTS, NEW_HIGHLIGHT_DESCRIPTION, &LINK_RECT, REMOTE_FOLDER) + AppendHighlightAnnotation(pdfApi, PDF_DOCUMENT_NAME, PAGE_NUMBER, PDF_OUTPUT, "add_highlight_annotation_", REMOTE_FOLDER) - appendStrikeoutAnnotation(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_STRIKEOUT, PAGE_NUMBER, NEW_STRIKEOUT_TEXT, NEW_STRIKEOUT_SUBJECT, NEW_STRIKEOUT_CONTENTS, NEW_STRIKEOUT_DESCRIPTION, &LINK_RECT, REMOTE_FOLDER) + AppendStrikeoutAnnotation(pdfApi, PDF_DOCUMENT_NAME, PAGE_NUMBER, PDF_OUTPUT, "add_strikeout_annotation_", REMOTE_FOLDER) - appendFreeTextAnnotation(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_FREETEXT, PAGE_NUMBER, NEW_FREETEXT_TEXT, NEW_FREETEXT_SUBJECT, NEW_FREETEXT_CONTENTS, NEW_FREETEXT_DESCRIPTION, &LINK_RECT, REMOTE_FOLDER) + AppendTextAnnotation(pdfApi, PDF_DOCUMENT_NAME, PAGE_NUMBER, PDF_OUTPUT, "add_freetext_annotation_", REMOTE_FOLDER) - appendUnderlineAnnotation(pdfApi, PDF_DOCUMENT, PDF_OUTPUT_UNDERLINE, PAGE_NUMBER, NEW_UNDERLINE_TEXT, NEW_UNDERLINE_SUBJECT, NEW_UNDERLINE_CONTENTS, NEW_UNDERLINE_DESCRIPTION, &LINK_RECT, REMOTE_FOLDER) + AppendUnderlineAnnotation(pdfApi, PDF_DOCUMENT_NAME, PAGE_NUMBER, PDF_OUTPUT, "add_underline_annotation_", REMOTE_FOLDER) - getAnnotations(pdfApi, PDF_DOCUMENT, PAGE_NUMBER_EXTRACT, REMOTE_FOLDER) + annotation_id := RequestAnnotations(pdfApi, PDF_DOCUMENT_NAME, PAGE_NUMBER, REMOTE_FOLDER) + RequestAnnotationById(pdfApi, PDF_DOCUMENT_NAME, annotation_id, REMOTE_FOLDER) - getAnnotation(pdfApi, PDF_DOCUMENT, ANNOTATION_ID, REMOTE_FOLDER) + DeleteAnnotation(pdfApi, PDF_DOCUMENT_NAME, ANNOTATION_ID, PDF_OUTPUT) + + DeletePageAnnotations(pdfApi, PDF_DOCUMENT_NAME, PAGE_NUMBER, PDF_OUTPUT) + + ModifyAnnotation(pdfApi, PDF_DOCUMENT_NAME, PDF_OUTPUT, ANNOTATION_ID, REMOTE_FOLDER) } From ca0de19f7eebc00facafcb4346118fc2d56bc1a1 Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Thu, 17 Jul 2025 22:30:26 +0300 Subject: [PATCH 04/13] Delete uses_cases/annotations/append_free_text_annotation.go --- .../append_free_text_annotation.go | 51 ------------------- 1 file changed, 51 deletions(-) delete mode 100644 uses_cases/annotations/append_free_text_annotation.go diff --git a/uses_cases/annotations/append_free_text_annotation.go b/uses_cases/annotations/append_free_text_annotation.go deleted file mode 100644 index 7217cae..0000000 --- a/uses_cases/annotations/append_free_text_annotation.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "fmt" - - asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" -) - -func appendFreeTextAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, output_document string, page_num int32, text string, subject string, contents string, description string, rect *asposepdfcloud.Rectangle, remote_folder string) { - uploadFile(pdf_api, document) - - args := map[string]interface{}{ - "folder": remote_folder, - } - - text_style := asposepdfcloud.TextStyle{ - FontSize: 20, - Font: "Arial", - ForegroundColor: &asposepdfcloud.Color{A: 0xFF, R: 0x00, G: 0xFF, B: 0x00}, - BackgroundColor: &asposepdfcloud.Color{A: 0xFF, R: 0xFF, G: 0x00, B: 0x00}, - } - - new_annotation := asposepdfcloud.FreeTextAnnotation{ - TextStyle: &text_style, - Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, - HorizontalAlignment: asposepdfcloud.HorizontalAlignmentCenter, - Intent: asposepdfcloud.FreeTextIntentFreeTextTypeWriter, - RichText: text, - Subject: subject, - Contents: contents, - ZIndex: 1, - Title: description, - Justification: asposepdfcloud.JustificationCenter, - Rect: rect, - Name: "Free_Text_Annotation", - Modified: "05/22/2025 11:30:00.000 AM", - } - - result, httpResponse, err := pdf_api.PostPageFreeTextAnnotations( - document, page_num, []asposepdfcloud.FreeTextAnnotation{new_annotation}, args, - ) - if err != nil { - fmt.Println(err.Error()) - } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { - fmt.Println("Unexpected error!") - } else { - fmt.Println(result) - - downloadFile(pdf_api, document, output_document) - } -} From eddbd7c735ebc3aeb9409701ca917c7e84202e7f Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Thu, 17 Jul 2025 22:30:42 +0300 Subject: [PATCH 05/13] Delete uses_cases/annotations/append_highlight_annotation.go --- .../append_highlight_annotation.go | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 uses_cases/annotations/append_highlight_annotation.go diff --git a/uses_cases/annotations/append_highlight_annotation.go b/uses_cases/annotations/append_highlight_annotation.go deleted file mode 100644 index c51ac33..0000000 --- a/uses_cases/annotations/append_highlight_annotation.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "fmt" - - asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" -) - -func appendHighlightAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, output_document string, page_num int32, text string, subject string, contents string, description string, rect *asposepdfcloud.Rectangle, remote_folder string) { - uploadFile(pdf_api, document) - - args := map[string]interface{}{ - "folder": remote_folder, - } - - new_annotation := asposepdfcloud.HighlightAnnotation{ - Rect: rect, - Name: "Highlight_Text_Annotation", - Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, - HorizontalAlignment: asposepdfcloud.HorizontalAlignmentLeft, - VerticalAlignment: asposepdfcloud.VerticalAlignmentTop, - RichText: text, - Subject: subject, - Contents: contents, - ZIndex: 1, - Title: description, - Color: &asposepdfcloud.Color{A: 0x00, R: 0x00, G: 0xFF, B: 0x00}, - QuadPoints: []asposepdfcloud.Point{ - {X: 10, Y: 10}, - {X: 20, Y: 10}, - {X: 10, Y: 20}, - {X: 10, Y: 10}, - }, - Modified: "03/27/2025 00:00:00.000 AM", - //Icon: "Conment", - } - result, httpResponse, err := pdf_api.PostPageHighlightAnnotations( - document, page_num, []asposepdfcloud.HighlightAnnotation{new_annotation}, args, - ) - if err != nil { - fmt.Println(err.Error()) - } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { - fmt.Println("Unexpected error!") - } else { - fmt.Println(result) - - downloadFile(pdf_api, document, output_document) - } -} From ebaaf712197b42871cd46748d657d0fc373d5886 Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Thu, 17 Jul 2025 22:30:56 +0300 Subject: [PATCH 06/13] Delete uses_cases/annotations/append_strikeout_annotation.go --- .../append_strikeout_annotation.go | 48 ------------------- 1 file changed, 48 deletions(-) delete mode 100644 uses_cases/annotations/append_strikeout_annotation.go diff --git a/uses_cases/annotations/append_strikeout_annotation.go b/uses_cases/annotations/append_strikeout_annotation.go deleted file mode 100644 index c7a71bc..0000000 --- a/uses_cases/annotations/append_strikeout_annotation.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "fmt" - - asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" -) - -func appendStrikeoutAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, output_document string, page_num int32, text string, subject string, contents string, description string, rect *asposepdfcloud.Rectangle, remote_folder string) { - uploadFile(pdf_api, document) - - args := map[string]interface{}{ - "folder": remote_folder, - } - - new_annotation := asposepdfcloud.StrikeOutAnnotation{ - Rect: rect, - Name: "Strikeout_Text_Annotation", - Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, - HorizontalAlignment: asposepdfcloud.HorizontalAlignmentLeft, - VerticalAlignment: asposepdfcloud.VerticalAlignmentTop, - RichText: text, - Subject: subject, - Contents: contents, - ZIndex: 1, - Title: description, - Color: &asposepdfcloud.Color{A: 0x00, R: 0x00, G: 0xFF, B: 0x00}, - QuadPoints: []asposepdfcloud.Point{ - {X: 10, Y: 10}, - {X: 20, Y: 10}, - {X: 10, Y: 20}, - {X: 10, Y: 10}, - }, - Modified: "05/22/2025 11:30:00.000 AM", - } - result, httpResponse, err := pdf_api.PostPageStrikeOutAnnotations( - document, page_num, []asposepdfcloud.StrikeOutAnnotation{new_annotation}, args, - ) - if err != nil { - fmt.Println(err.Error()) - } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { - fmt.Println("Unexpected error!") - } else { - fmt.Println(result) - - downloadFile(pdf_api, document, output_document) - } -} From 747c59f2887b7c27de34029f1162afef230b2c3b Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Thu, 17 Jul 2025 22:31:12 +0300 Subject: [PATCH 07/13] Delete uses_cases/annotations/append_underline_annotation.go --- .../append_underline_annotation.go | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 uses_cases/annotations/append_underline_annotation.go diff --git a/uses_cases/annotations/append_underline_annotation.go b/uses_cases/annotations/append_underline_annotation.go deleted file mode 100644 index 43b8a6c..0000000 --- a/uses_cases/annotations/append_underline_annotation.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "fmt" - - asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" -) - -func appendUnderlineAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, output_document string, page_num int32, text string, subject string, contents string, description string, rect *asposepdfcloud.Rectangle, remote_folder string) { - uploadFile(pdf_api, document) - - args := map[string]interface{}{ - "folder": remote_folder, - } - - new_annotation := asposepdfcloud.UnderlineAnnotation{ - Rect: rect, - Name: "Underline_Text_Annotation", - Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, - HorizontalAlignment: asposepdfcloud.HorizontalAlignmentLeft, - VerticalAlignment: asposepdfcloud.VerticalAlignmentTop, - RichText: text, - Subject: subject, - Contents: contents, - ZIndex: 1, - Title: description, - Color: &asposepdfcloud.Color{A: 0x00, R: 0x00, G: 0xFF, B: 0x00}, - QuadPoints: []asposepdfcloud.Point{ - {X: 10, Y: 10}, - {X: 20, Y: 10}, - {X: 10, Y: 20}, - {X: 10, Y: 10}, - }, - Modified: "05/22/2025 11:30:00.000 AM", - } - - result, httpResponse, err := pdf_api.PostPageUnderlineAnnotations( - document, page_num, []asposepdfcloud.UnderlineAnnotation{new_annotation}, args, - ) - if err != nil { - fmt.Println(err.Error()) - } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { - fmt.Println("Unexpected error!") - } else { - fmt.Println(result) - - downloadFile(pdf_api, document, output_document) - } -} From bdd1bfa93e42f29316835e622e414a5bcfbf8d35 Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Thu, 17 Jul 2025 22:31:27 +0300 Subject: [PATCH 08/13] Delete uses_cases/annotations/extract_annotation.go --- uses_cases/annotations/extract_annotation.go | 24 -------------------- 1 file changed, 24 deletions(-) delete mode 100644 uses_cases/annotations/extract_annotation.go diff --git a/uses_cases/annotations/extract_annotation.go b/uses_cases/annotations/extract_annotation.go deleted file mode 100644 index 9dd16fc..0000000 --- a/uses_cases/annotations/extract_annotation.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "fmt" - - asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" -) - -func getAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, annotation_id string, remote_folder string) { - uploadFile(pdf_api, document) - - args := map[string]interface{}{ - "folder": remote_folder, - } - - result, httpResponse, err := pdf_api.GetTextAnnotation(document, annotation_id, args) - if err != nil { - fmt.Println(err.Error()) - } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { - fmt.Println("Unexpected error!") - } else { - showAnnotation(result.Annotation) - } -} From 69bacc9d918e5d63bc2fd9eb1d759488d63a25d3 Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Thu, 17 Jul 2025 22:31:42 +0300 Subject: [PATCH 09/13] Delete uses_cases/annotations/extract_annotattions.go --- .../annotations/extract_annotattions.go | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 uses_cases/annotations/extract_annotattions.go diff --git a/uses_cases/annotations/extract_annotattions.go b/uses_cases/annotations/extract_annotattions.go deleted file mode 100644 index a51ad0c..0000000 --- a/uses_cases/annotations/extract_annotattions.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "fmt" - - asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" -) - -func getAnnotations(pdf_api *asposepdfcloud.PdfApiService, document string, page_num int32, remote_folder string) { - uploadFile(pdf_api, document) - - args := map[string]interface{}{ - "folder": remote_folder, - } - - result, httpResponse, err := pdf_api.GetPageAnnotations(document, page_num, args) - if err != nil { - fmt.Println(err.Error()) - } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { - fmt.Println("Unexpected error!") - } else { - showAnnotations(&result.Annotations.List) - } -} From af7f49b4af122b0ac021349939c23656b26cc57b Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Thu, 17 Jul 2025 22:32:25 +0300 Subject: [PATCH 10/13] Update replace_annotation.go --- uses_cases/annotations/replace_annotation.go | 32 +++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/uses_cases/annotations/replace_annotation.go b/uses_cases/annotations/replace_annotation.go index 7f3f4f1..3251ca2 100644 --- a/uses_cases/annotations/replace_annotation.go +++ b/uses_cases/annotations/replace_annotation.go @@ -6,19 +6,41 @@ import ( asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" ) -func replaceAnnotation(pdf_api *asposepdfcloud.PdfApiService, document string, annotation_id string, remote_folder string) { - uploadFile(pdf_api, document) +func getAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, annotation_id string, remote_folder string) *asposepdfcloud.TextAnnotation { + // Get annotation from the page in the PDF document. + args := map[string]interface{}{ + "folder": remote_folder, + } + result, httpResponse, err := pdf_api.GetTextAnnotation(document_name, annotation_id, args) + if err != nil { + fmt.Println(err.Error()) + return nil + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("getAnnotation(): Failed to get annotation in the document.") + return nil + } else { + fmt.Println("getAnnotation(): nnotation '" + annotation_id + "' successfully found '" + result.Annotation.Contents + "' in the document '" + document_name + "'.") + return result.Annotation + } +} +func ModifyAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, output_document string, annotation_id string, remote_folder string) { + // Change annotation on the page in the PDF document. + UploadFile(pdf_api, document_name) args := map[string]interface{}{ "folder": remote_folder, } + annotation := getAnnotation(pdf_api, document_name, annotation_id, remote_folder) + annotation.Contents = REPLACED_CONTENT + annotation.Icon = asposepdfcloud.TextIconStar - result, httpResponse, err := pdf_api.GetDocumentAnnotations(document, args) + _, httpResponse, err := pdf_api.PutTextAnnotation(document_name, annotation_id, *annotation, args) if err != nil { fmt.Println(err.Error()) } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { - fmt.Println("Unexpected error!") + fmt.Println("ModifyAnnotation(): Failed to modify annotation in the document.") } else { - showAnnotations(&result.Annotations.List) + fmt.Println("ModifyAnnotation(): annotation '" + annotation.Id + "' successfully modified in the document '" + document_name + "'.") + DownloadFile(pdf_api, document_name, output_document, "replaced_annotatiom_") } } From d17936727809811b47102905d93f5fd16686a782 Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Thu, 17 Jul 2025 22:34:33 +0300 Subject: [PATCH 11/13] Add files via upload --- .../annotations/delete_page_annotations.go | 25 ++++++++++ .../annotations/delete_text_annotation.go | 26 ++++++++++ .../annotations/get_annotation_by_id.go | 23 +++++++++ uses_cases/annotations/get_annotations.go | 32 +++++++++++++ .../annotations/new_highlight_annotation.go | 44 +++++++++++++++++ .../annotations/new_strikeout_annotation.go | 46 ++++++++++++++++++ uses_cases/annotations/new_text_annotation.go | 47 +++++++++++++++++++ .../annotations/new_underline_annotation.go | 45 ++++++++++++++++++ 8 files changed, 288 insertions(+) create mode 100644 uses_cases/annotations/delete_page_annotations.go create mode 100644 uses_cases/annotations/delete_text_annotation.go create mode 100644 uses_cases/annotations/get_annotation_by_id.go create mode 100644 uses_cases/annotations/get_annotations.go create mode 100644 uses_cases/annotations/new_highlight_annotation.go create mode 100644 uses_cases/annotations/new_strikeout_annotation.go create mode 100644 uses_cases/annotations/new_text_annotation.go create mode 100644 uses_cases/annotations/new_underline_annotation.go diff --git a/uses_cases/annotations/delete_page_annotations.go b/uses_cases/annotations/delete_page_annotations.go new file mode 100644 index 0000000..e9add56 --- /dev/null +++ b/uses_cases/annotations/delete_page_annotations.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func DeletePageAnnotations(pdf_api *asposepdfcloud.PdfApiService, document_name string, page_num int32, output_name string) { + // Delete annotation from the PDF document. + UploadFile(pdf_api, document_name) + args := map[string]interface{}{ + "folder": REMOTE_FOLDER, + } + + _, httpResponse, err := pdf_api.DeletePageAnnotations(document_name, page_num, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("DeletePageAnnotations(): Failed to delete annotation from the document.") + } else { + fmt.Println("DeletePageAnnotations(): annotations on page '", page_num, "' deleted from the document '"+document_name+"'.") + DownloadFile(pdf_api, document_name, output_name, "del_page_annotations_") + } +} diff --git a/uses_cases/annotations/delete_text_annotation.go b/uses_cases/annotations/delete_text_annotation.go new file mode 100644 index 0000000..b2b839e --- /dev/null +++ b/uses_cases/annotations/delete_text_annotation.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func DeleteAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, annotation_id string, output_name string) { + // Delete annotation from the PDF document. + UploadFile(pdf_api, document_name) + args := map[string]interface{}{ + "folder": REMOTE_FOLDER, + } + + _, httpResponse, err := pdf_api.DeleteAnnotation(document_name, annotation_id, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("DeleteAnnotation(): Failed to delete annotation from the document page.") + } else { + DeletePopupAnnotations(pdf_api, document_name, annotation_id) + fmt.Println("DdeleteAnnotation(): annotation '" + annotation_id + "' deleted from the document '" + document_name + "'.") + DownloadFile(pdf_api, document_name, output_name, "del_annotation_") + } +} diff --git a/uses_cases/annotations/get_annotation_by_id.go b/uses_cases/annotations/get_annotation_by_id.go new file mode 100644 index 0000000..4a9ee35 --- /dev/null +++ b/uses_cases/annotations/get_annotation_by_id.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func RequestAnnotationById(pdf_api *asposepdfcloud.PdfApiService, document_name string, annotation_id string, remote_folder string) { + // Get annotation from the page in the PDF document. + UploadFile(pdf_api, document_name) + args := map[string]interface{}{ + "folder": remote_folder, + } + result, httpResponse, err := pdf_api.GetTextAnnotation(document_name, annotation_id, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("RequestAnnotationById(): Failed to delete annotation from the document page.") + } else { + fmt.Println("RequestAnnotationById(): annotation '" + annotation_id + "' successfully found '" + result.Annotation.Contents + "' in the document '" + document_name + "'.") + } +} diff --git a/uses_cases/annotations/get_annotations.go b/uses_cases/annotations/get_annotations.go new file mode 100644 index 0000000..fee03e3 --- /dev/null +++ b/uses_cases/annotations/get_annotations.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func RequestAnnotations(pdf_api *asposepdfcloud.PdfApiService, document_name string, page_num int32, remote_folder string) string { + // Get annotations from the page in the PDF document. + UploadFile(pdf_api, document_name) + args := map[string]interface{}{ + "folder": remote_folder, + } + annotation_result := "" + result, httpResponse, err := pdf_api.GetPageAnnotations(document_name, page_num, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("RequestAnnotations(): Failed to delete annotation from the document page.") + } else { + for _, annotation := range result.Annotations.List { + if annotation.AnnotationType == asposepdfcloud.AnnotationTypeText { + fmt.Println("RequestAnnotations(): annotation id=", annotation.Id, " with '"+annotation.Contents+"' content get from the document '"+document_name+"' on ", annotation.PageIndex, " page.") + annotation_result := annotation.Id + return annotation_result + } + } + } + fmt.Println("RequestAnnotations(): Failed to get annotation in the document.") + return annotation_result +} diff --git a/uses_cases/annotations/new_highlight_annotation.go b/uses_cases/annotations/new_highlight_annotation.go new file mode 100644 index 0000000..c686bd2 --- /dev/null +++ b/uses_cases/annotations/new_highlight_annotation.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func AppendHighlightAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, page_num int32, output_document string, prefix string, remote_folder string) { + // Append a new highlight text annotation to the PDF document. + UploadFile(pdf_api, document_name) + args := map[string]interface{}{ + "folder": remote_folder, + } + new_annotation := asposepdfcloud.HighlightAnnotation{ + Name: "Highlight_Text_Annotation", + Rect: &asposepdfcloud.Rectangle{LLX: 100, LLY: 350, URX: 450, URY: 400}, + Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, + HorizontalAlignment: asposepdfcloud.HorizontalAlignmentLeft, + VerticalAlignment: asposepdfcloud.VerticalAlignmentTop, + RichText: NEW_HL_ANNOTATION_TEXT, + Subject: NEW_HL_ANNOTATION_SUBJECT, + Contents: NEW_HL_ANNOTATION_CONTENTS, + Title: NEW_HL_ANNOTATION_DESCRIPTION, + ZIndex: 1, + Color: &asposepdfcloud.Color{A: 0xFF, R: 0x00, G: 0xFF, B: 0x00}, + QuadPoints: []asposepdfcloud.Point{ + {X: 10, Y: 10}, + {X: 20, Y: 10}, + {X: 10, Y: 20}, + {X: 10, Y: 10}, + }, + Modified: "03/27/2025 00:00:00.000 AM", + } + _, httpResponse, err := pdf_api.PostPageHighlightAnnotations(document_name, page_num, []asposepdfcloud.HighlightAnnotation{new_annotation}, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("AppendHighlightAnnotation(): Failed to append annotation to the document page.") + } else { + fmt.Println("AppendHighlightAnnotation(): annotation '" + NEW_HL_ANNOTATION_TEXT + "' added to the document '" + document_name + "'.") + DownloadFile(pdf_api, document_name, output_document, prefix) + } +} diff --git a/uses_cases/annotations/new_strikeout_annotation.go b/uses_cases/annotations/new_strikeout_annotation.go new file mode 100644 index 0000000..dbd5186 --- /dev/null +++ b/uses_cases/annotations/new_strikeout_annotation.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func AppendStrikeoutAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, page_num int32, output_document string, prefix string, remote_folder string) { + // Append a new strikeout text annotation to the PDF document. + UploadFile(pdf_api, document_name) + args := map[string]interface{}{ + "folder": remote_folder, + } + + new_annotation := asposepdfcloud.StrikeOutAnnotation{ + Name: "Highlight_Text_Annotation", + Rect: &asposepdfcloud.Rectangle{LLX: 100, LLY: 350, URX: 450, URY: 400}, + Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, + HorizontalAlignment: asposepdfcloud.HorizontalAlignmentLeft, + VerticalAlignment: asposepdfcloud.VerticalAlignmentTop, + RichText: NEW_SO_ANNOTATION_TEXT, + Subject: NEW_SO_ANNOTATION_SUBJECT, + Contents: NEW_SO_ANNOTATION_CONTENTS, + Title: NEW_SO_ANNOTATION_DESCRIPTION, + ZIndex: 1, + Color: &asposepdfcloud.Color{A: 0xFF, R: 0x00, G: 0xFF, B: 0x00}, + QuadPoints: []asposepdfcloud.Point{ + {X: 10, Y: 10}, + {X: 20, Y: 10}, + {X: 10, Y: 20}, + {X: 10, Y: 10}, + }, + Modified: "03/27/2025 00:00:00.000 AM", + } + + _, httpResponse, err := pdf_api.PostPageStrikeOutAnnotations(document_name, page_num, []asposepdfcloud.StrikeOutAnnotation{new_annotation}, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("AppendStrikeoutAnnotation(): Failed to append annotation to the document page.") + } else { + fmt.Println("AppendStrikeoutAnnotation(): annotation '" + NEW_SO_ANNOTATION_TEXT + "' added to the document '" + document_name + "'.") + DownloadFile(pdf_api, document_name, output_document, prefix) + } +} diff --git a/uses_cases/annotations/new_text_annotation.go b/uses_cases/annotations/new_text_annotation.go new file mode 100644 index 0000000..481a0ad --- /dev/null +++ b/uses_cases/annotations/new_text_annotation.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func AppendTextAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, page_num int32, output_document string, prefix string, remote_folder string) { + // Append a new free text annotation to the PDF document. + UploadFile(pdf_api, document_name) + args := map[string]interface{}{ + "folder": remote_folder, + } + + text_style := asposepdfcloud.TextStyle{ + FontSize: 20, + Font: "Arial", + ForegroundColor: &asposepdfcloud.Color{A: 0xFF, R: 0x00, G: 0xFF, B: 0x00}, + BackgroundColor: &asposepdfcloud.Color{A: 0xFF, R: 0xFF, G: 0x00, B: 0x00}, + } + + new_annotation := asposepdfcloud.FreeTextAnnotation{ + Rect: &asposepdfcloud.Rectangle{LLX: 100, LLY: 350, URX: 450, URY: 400}, + TextStyle: &text_style, + Name: "Free Text Annotation", + Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, + HorizontalAlignment: asposepdfcloud.HorizontalAlignmentCenter, + Intent: asposepdfcloud.FreeTextIntentFreeTextTypeWriter, + RichText: NEW_FT_ANNOTATION_TEXT, + Subject: NEW_FT_ANNOTATION_SUBJECT, + Contents: NEW_FT_ANNOTATION_CONTENTS, + Title: NEW_FT_ANNOTATION_DESCRIPTION, + ZIndex: 1, + Justification: asposepdfcloud.JustificationCenter, + } + + _, httpResponse, err := pdf_api.PostPageFreeTextAnnotations(document_name, page_num, []asposepdfcloud.FreeTextAnnotation{new_annotation}, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("AppendTextAnnotation(): Failed to append annotation to the document page.") + } else { + fmt.Println("AppendTextAnnotation(): annotation '" + NEW_FT_ANNOTATION_TEXT + "' added to the document '" + document_name + "'.") + DownloadFile(pdf_api, document_name, output_document, prefix) + } +} diff --git a/uses_cases/annotations/new_underline_annotation.go b/uses_cases/annotations/new_underline_annotation.go new file mode 100644 index 0000000..c23e4d6 --- /dev/null +++ b/uses_cases/annotations/new_underline_annotation.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" +) + +func AppendUnderlineAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, page_num int32, output_document string, prefix string, remote_folder string) { + // Append a new underline text annotation to the PDF document. + UploadFile(pdf_api, document_name) + args := map[string]interface{}{ + "folder": remote_folder, + } + + new_annotation := asposepdfcloud.UnderlineAnnotation{ + Rect: &asposepdfcloud.Rectangle{LLX: 100, LLY: 350, URX: 450, URY: 400}, + Name: "Underline Text Annotation", + Flags: []asposepdfcloud.AnnotationFlags{asposepdfcloud.AnnotationFlagsDefault}, + HorizontalAlignment: asposepdfcloud.HorizontalAlignmentLeft, + VerticalAlignment: asposepdfcloud.VerticalAlignmentTop, + RichText: NEW_UL_ANNOTATION_TEXT, + Subject: NEW_UL_ANNOTATION_SUBJECT, + Title: NEW_UL_ANNOTATION_DESCRIPTION, + Contents: NEW_UL_ANNOTATION_CONTENTS, + ZIndex: 1, + Color: &asposepdfcloud.Color{A: 0xFF, R: 0x00, G: 0xFF, B: 0x00}, + QuadPoints: []asposepdfcloud.Point{ + {X: 10, Y: 10}, + {X: 20, Y: 10}, + {X: 10, Y: 20}, + {X: 10, Y: 10}, + }, + Modified: "03/27/2025 00:00:00.000 AM", + } + _, httpResponse, err := pdf_api.PostPageUnderlineAnnotations(document_name, page_num, []asposepdfcloud.UnderlineAnnotation{new_annotation}, args) + if err != nil { + fmt.Println(err.Error()) + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { + fmt.Println("AppendUnderlineAnnotation(): Failed to append annotation to the document page.") + } else { + fmt.Println("AppendUnderlineAnnotation(): annotation '" + NEW_UL_ANNOTATION_TEXT + "' added to the document '" + document_name + "'.") + DownloadFile(pdf_api, document_name, output_document, prefix) + } +} From 15c4822ec682986a7f916536add29aaef4a7d900 Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Fri, 18 Jul 2025 01:08:06 +0300 Subject: [PATCH 12/13] Update get_annotation_by_id.go --- uses_cases/annotations/get_annotation_by_id.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uses_cases/annotations/get_annotation_by_id.go b/uses_cases/annotations/get_annotation_by_id.go index 4a9ee35..f097076 100644 --- a/uses_cases/annotations/get_annotation_by_id.go +++ b/uses_cases/annotations/get_annotation_by_id.go @@ -7,7 +7,7 @@ import ( ) func RequestAnnotationById(pdf_api *asposepdfcloud.PdfApiService, document_name string, annotation_id string, remote_folder string) { - // Get annotation from the page in the PDF document. + // Get annotation by Id in the PDF document. UploadFile(pdf_api, document_name) args := map[string]interface{}{ "folder": remote_folder, @@ -16,7 +16,7 @@ func RequestAnnotationById(pdf_api *asposepdfcloud.PdfApiService, document_name if err != nil { fmt.Println(err.Error()) } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { - fmt.Println("RequestAnnotationById(): Failed to delete annotation from the document page.") + fmt.Println("RequestAnnotationById(): Failed to request text annotation from the document page.") } else { fmt.Println("RequestAnnotationById(): annotation '" + annotation_id + "' successfully found '" + result.Annotation.Contents + "' in the document '" + document_name + "'.") } From 0a53f694041bc537690f0c2e5b423b9343c2c070 Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Fri, 18 Jul 2025 01:09:59 +0300 Subject: [PATCH 13/13] Update replace_annotation.go --- uses_cases/annotations/replace_annotation.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uses_cases/annotations/replace_annotation.go b/uses_cases/annotations/replace_annotation.go index 3251ca2..1adc21e 100644 --- a/uses_cases/annotations/replace_annotation.go +++ b/uses_cases/annotations/replace_annotation.go @@ -7,7 +7,7 @@ import ( ) func getAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, annotation_id string, remote_folder string) *asposepdfcloud.TextAnnotation { - // Get annotation from the page in the PDF document. + // Get annotation by Id in the PDF document. args := map[string]interface{}{ "folder": remote_folder, } @@ -25,7 +25,7 @@ func getAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, } func ModifyAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, output_document string, annotation_id string, remote_folder string) { - // Change annotation on the page in the PDF document. + // Change annotation by Id in the PDF document. UploadFile(pdf_api, document_name) args := map[string]interface{}{ "folder": remote_folder,