|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "path" |
| 7 | + "path/filepath" |
| 8 | + |
| 9 | + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" |
| 10 | +) |
| 11 | + |
| 12 | +const ( |
| 13 | + REMOTE_FOLDER = "Your_Temp_Pdf_Cloud" |
| 14 | + LOCAL_FOLDER = "c:\\Samples" |
| 15 | + PDF_DOCUMENT = "sample.pdf" |
| 16 | + PDF_OUTPUT = "output_sample_add_link.pdf" |
| 17 | + PDF_OUTPUT_REMOVE = "output_sample_rem_link.pdf" |
| 18 | + PDF_OUTPUT_REPLACE = "output_sample_rep_link.pdf" |
| 19 | + NEW_LINK_ACTION = "https://reference.aspose.cloud/pdf/" |
| 20 | + PAGE_NUMBER = 2 |
| 21 | + LINK_ID = "GI5UO32UN5KVESKBMN2GS33OHMYTINBMGQ4DQLBRHA2SYNBZHE" |
| 22 | +) |
| 23 | + |
| 24 | +var ( |
| 25 | + LINK_RECT = asposepdfcloud.Rectangle{LLX: 238, LLY: 488.622, URX: 305, URY: 498.588} |
| 26 | +) |
| 27 | + |
| 28 | +func initPdfApi() *asposepdfcloud.PdfApiService { |
| 29 | + AppSID := "******" |
| 30 | + AppKey := "******" |
| 31 | + |
| 32 | + pdfApi := asposepdfcloud.NewPdfApiService(AppSID, AppKey, "") |
| 33 | + return pdfApi |
| 34 | +} |
| 35 | + |
| 36 | +// Upload local file to the remote folder with check errors |
| 37 | +func uploadFile(pdf_api *asposepdfcloud.PdfApiService, name string) { |
| 38 | + args := map[string]interface{}{ |
| 39 | + "folder": REMOTE_FOLDER, |
| 40 | + } |
| 41 | + file, err := os.Open(filepath.Join(LOCAL_FOLDER, name)) |
| 42 | + if err != nil { |
| 43 | + fmt.Println(err.Error()) |
| 44 | + } else { |
| 45 | + result, httpResponse, err := pdf_api.UploadFile(path.Join(REMOTE_FOLDER, name), file, args) |
| 46 | + if err != nil { |
| 47 | + fmt.Println(err.Error()) |
| 48 | + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { |
| 49 | + fmt.Println("Unexpected error!") |
| 50 | + } else { |
| 51 | + fmt.Println(result) |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +// Download file from remote folder and save it locally with check errors |
| 57 | +func downloadFile(pdf_api *asposepdfcloud.PdfApiService, name string, output_name string) { |
| 58 | + args := map[string]interface{}{ |
| 59 | + "folder": REMOTE_FOLDER, |
| 60 | + } |
| 61 | + result_data, httpResponse, err := pdf_api.DownloadFile(path.Join(REMOTE_FOLDER, name), args) |
| 62 | + if err != nil { |
| 63 | + fmt.Println(err.Error()) |
| 64 | + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { |
| 65 | + fmt.Println("Unexpected error!") |
| 66 | + } else { |
| 67 | + fileName := path.Join(LOCAL_FOLDER, output_name) |
| 68 | + f, _ := os.Create(fileName) |
| 69 | + _, _ = f.Write(result_data) |
| 70 | + fmt.Println("File '" + fileName + "'successfully downloaded.") |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +func showLinks(links *[]asposepdfcloud.LinkAnnotation) { |
| 75 | + for i := 0; i < len(*links); i++ { |
| 76 | + fmt.Print("Link #") |
| 77 | + fmt.Println(i) |
| 78 | + fmt.Print("\tId == '") |
| 79 | + fmt.Print((*links)[i].Id) |
| 80 | + fmt.Println("'") |
| 81 | + fmt.Print("\tActionType == '") |
| 82 | + fmt.Print((*links)[i].ActionType) |
| 83 | + fmt.Println("'") |
| 84 | + fmt.Print("\tAction == '") |
| 85 | + fmt.Print((*links)[i].Action) |
| 86 | + fmt.Println("'") |
| 87 | + } |
| 88 | +} |
0 commit comments