|
| 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_pages.pdf" |
| 17 | + XML_OUTPUT_FILE = "output_sample.xml" |
| 18 | + FDF_OUTPUT_FILE = "output_sample.fdf" |
| 19 | + PAGE_NUMBER = 1 |
| 20 | + |
| 21 | + AppSID = "**********" // Your Application SID |
| 22 | + AppKey = "**********" // Your Application Key |
| 23 | +) |
| 24 | + |
| 25 | +func initPdfApi() *asposepdfcloud.PdfApiService { |
| 26 | + pdfApi := asposepdfcloud.NewPdfApiService(AppSID, AppKey, "") |
| 27 | + return pdfApi |
| 28 | +} |
| 29 | + |
| 30 | +// Upload local file to the remote folder with check errors |
| 31 | +func uploadFile(pdf_api *asposepdfcloud.PdfApiService, name string) { |
| 32 | + args := map[string]interface{}{ |
| 33 | + "folder": REMOTE_FOLDER, |
| 34 | + } |
| 35 | + file, err := os.Open(filepath.Join(LOCAL_FOLDER, name)) |
| 36 | + if err != nil { |
| 37 | + fmt.Println(err.Error()) |
| 38 | + } else { |
| 39 | + _, httpResponse, err := pdf_api.UploadFile(path.Join(REMOTE_FOLDER, name), file, args) |
| 40 | + if err != nil { |
| 41 | + fmt.Println(err.Error()) |
| 42 | + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { |
| 43 | + fmt.Println("Unexpected error!") |
| 44 | + } else { |
| 45 | + fmt.Println("File '" + name + " ' successfully uploaded.") |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +// Download file from remote folder and save it locally with check errors |
| 51 | +func downloadFile(pdf_api *asposepdfcloud.PdfApiService, name string, output_name string) { |
| 52 | + args := map[string]interface{}{ |
| 53 | + "folder": REMOTE_FOLDER, |
| 54 | + } |
| 55 | + result_data, httpResponse, err := pdf_api.DownloadFile(path.Join(REMOTE_FOLDER, name), args) |
| 56 | + if err != nil { |
| 57 | + fmt.Println(err.Error()) |
| 58 | + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { |
| 59 | + fmt.Println("Unexpected error!") |
| 60 | + } else { |
| 61 | + fileName := path.Join(LOCAL_FOLDER, output_name) |
| 62 | + f, _ := os.Create(fileName) |
| 63 | + _, _ = f.Write(result_data) |
| 64 | + fmt.Println("File '" + fileName + "' successfully downloaded.") |
| 65 | + } |
| 66 | +} |
0 commit comments