Skip to content

Commit af1d091

Browse files
authored
Merge pull request #96 from aspose-pdf-cloud/develop
update to 25.9
2 parents b3df442 + 2c9ca31 commit af1d091

File tree

12 files changed

+427
-7
lines changed

12 files changed

+427
-7
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ These SDKs are now fully supported. If you have any questions, see any bugs or h
99

1010
Extract Text & Images of a PDF document online https://products.aspose.app/pdf/parser.
1111

12-
## Enhancements in Version 25.8
13-
- Implement document page resize functionality using the Pdf.Cloud API library.
12+
## Enhancements in Version 25.9
13+
- Implement PDF document page crop functionality using the Pdf.Cloud API library.
1414
- A new version of Aspose.PDF Cloud was prepared using the latest version of Aspose.PDF for .NET.
1515

16-
## Bugs fixed in Version 25.8
17-
- Implement delete watermark from PDF document using the Pdf.Cloud API library.
18-
1916
## Installation
2017
```
2118
go get -u github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25

api_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (c *APIClient) prepareRequest (
176176

177177
// set custom header
178178
headerParams["x-aspose-client"] = "go sdk"
179-
headerParams["x-aspose-client-version"] = "25.8.0"
179+
headerParams["x-aspose-client-version"] = "25.9.0"
180180

181181
// Detect postBody type and post.
182182
if postBody != nil {

docs/PdfApi.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ Method | HTTP request | Description
212212
[**PostDocumentImageStamps**](PdfApi.md#PostDocumentImageStamps) | **Post** /pdf/{name}/stamps/image | Add document pages image stamps.
213213
[**PostDocumentImageStampsPageSpecified**](PdfApi.md#PostDocumentImageStampsPageSpecified) | **Post** /pdf/{name}/stamps/image/pagespecified | Add document image stamps to specified pages.
214214
[**PostDocumentPageNumberStamps**](PdfApi.md#PostDocumentPageNumberStamps) | **Post** /pdf/{name}/stamps/pagenumber | Add document page number stamps.
215+
[**PostDocumentPagesCrop**](PdfApi.md#PostDocumentPagesCrop) | **Post** /pdf/{name}/crop | Crop PDF document pages.
215216
[**PostDocumentPagesResize**](PdfApi.md#PostDocumentPagesResize) | **Post** /pdf/{name}/resize | Rsize PDF document.
216217
[**PostDocumentPagesRotate**](PdfApi.md#PostDocumentPagesRotate) | **Post** /pdf/{name}/rotate | Rotate PDF document.
217218
[**PostDocumentTextFooter**](PdfApi.md#PostDocumentTextFooter) | **Post** /pdf/{name}/footer/text | Add document text footer.
@@ -7255,6 +7256,42 @@ Name | Type | Description | Notes
72557256

72567257
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
72577258

7259+
# **PostDocumentPagesCrop**
7260+
> AsposeResponse PostDocumentPagesCrop(name, pages, rect, optional)
7261+
Crop PDF document pages.
7262+
7263+
### Required Parameters
7264+
7265+
Name | Type | Description | Notes
7266+
------------- | ------------- | ------------- | -------------
7267+
**name** | **string**| The document name. |
7268+
**pages** | **string**| Comma separated list of pages and page ranges. (Example: 1,3-5,8) |
7269+
**rect** | [**Rectangle**](Rectangle.md)| Rectangle of document area. |
7270+
**optional** | **map[string]interface{}** | optional parameters | nil if no parameters
7271+
7272+
### Optional Parameters
7273+
Optional parameters are passed through a map[string]interface{}.
7274+
7275+
Name | Type | Description | Notes
7276+
------------- | ------------- | ------------- | -------------
7277+
**name** | **string**| The document name. |
7278+
**pages** | **string**| Comma separated list of pages and page ranges. (Example: 1,3-5,8) |
7279+
**rect** | [**Rectangle**](Rectangle.md)| Rectangle of document area. |
7280+
**storage** | **string**| The document storage. |
7281+
**folder** | **string**| The document folder. |
7282+
**password** | **string**| Base64 encoded password. |
7283+
7284+
### Return type
7285+
7286+
[**AsposeResponse**](AsposeResponse.md)
7287+
7288+
### HTTP request headers
7289+
7290+
- **Content-Type**: application/json
7291+
- **Accept**: application/json
7292+
7293+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
7294+
72587295
# **PostDocumentPagesResize**
72597296
> AsposeResponse PostDocumentPagesResize(name, height, width, pages, optional)
72607297
Rsize PDF document.

document_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,23 @@ func TestPostDocumentPagesResize(t *testing.T) {
341341
} else {
342342
fmt.Printf("%d\tPostDocumentPagesResize - %db\n", GetBaseTest().GetTestNumber(), response.Code)
343343
}
344-
}
344+
}
345+
346+
func TestPostDocumentPagesCrop(t *testing.T) {
347+
name := "4pages.pdf"
348+
if err := GetBaseTest().UploadFile(name); err != nil {
349+
t.Error(err)
350+
}
351+
args := map[string]interface{}{
352+
"folder": GetBaseTest().remoteFolder,
353+
}
354+
response, httpResponse, err := GetBaseTest().PdfAPI.PostDocumentPagesCrop(
355+
name, "2-3", Rectangle{LLX: 0, LLY: 0, URX: 800, URY: 400}, args)
356+
if err != nil {
357+
t.Error(err)
358+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
359+
t.Fail()
360+
} else {
361+
fmt.Printf("%d\tPostDocumentPagesCrop - %db\n", GetBaseTest().GetTestNumber(), response.Code)
362+
}
363+
}

pdf_api.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17353,6 +17353,95 @@ func (a *PdfApiService) PostDocumentPageNumberStamps(name string, stamp PageNumb
1735317353
return successPayload, localVarHttpResponse, err
1735417354
}
1735517355

17356+
/* PdfApiService Crop PDF document pages.
17357+
@param name The document name.
17358+
@param pages Comma separated list of pages and page ranges. (Example: 1,3-5,8)
17359+
@param rect Rectangle of document area.
17360+
@param optional (nil or map[string]interface{}) with one or more of:
17361+
@param "storage" (string) The document storage.
17362+
@param "folder" (string) The document folder.
17363+
@param "password" (string) Base64 encoded password.
17364+
@return AsposeResponse*/
17365+
func (a *PdfApiService) PostDocumentPagesCrop(name string, pages string, rect Rectangle, localVarOptionals map[string]interface{}) (AsposeResponse, *http.Response, error) {
17366+
var (
17367+
localVarHttpMethod = strings.ToUpper("Post")
17368+
localVarPostBody interface{}
17369+
localVarFileName string
17370+
localVarFileBytes []byte
17371+
successPayload AsposeResponse
17372+
)
17373+
17374+
// create path and map variables
17375+
localVarPath := a.client.cfg.BasePath + "/pdf/{name}/crop"
17376+
localVarPath = strings.Replace(localVarPath, "{"+"name"+"}", fmt.Sprintf("%v", name), -1)
17377+
17378+
localVarHeaderParams := make(map[string]string)
17379+
localVarQueryParams := _url.Values{}
17380+
localVarFormParams := _url.Values{}
17381+
17382+
if err := typeCheckParameter(localVarOptionals["storage"], "string", "storage"); err != nil {
17383+
return successPayload, nil, err
17384+
}
17385+
if err := typeCheckParameter(localVarOptionals["folder"], "string", "folder"); err != nil {
17386+
return successPayload, nil, err
17387+
}
17388+
if err := typeCheckParameter(localVarOptionals["password"], "string", "password"); err != nil {
17389+
return successPayload, nil, err
17390+
}
17391+
17392+
localVarQueryParams.Add("pages", parameterToString(pages, ""))
17393+
if localVarTempParam, localVarOk := localVarOptionals["storage"].(string); localVarOk {
17394+
localVarQueryParams.Add("storage", parameterToString(localVarTempParam, ""))
17395+
}
17396+
if localVarTempParam, localVarOk := localVarOptionals["folder"].(string); localVarOk {
17397+
localVarQueryParams.Add("folder", parameterToString(localVarTempParam, ""))
17398+
}
17399+
if localVarTempParam, localVarOk := localVarOptionals["password"].(string); localVarOk {
17400+
localVarQueryParams.Add("password", parameterToString(localVarTempParam, ""))
17401+
}
17402+
// to determine the Content-Type header
17403+
localVarHttpContentTypes := []string{ "application/json", }
17404+
17405+
// set Content-Type header
17406+
localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
17407+
if localVarHttpContentType != "" {
17408+
localVarHeaderParams["Content-Type"] = localVarHttpContentType
17409+
}
17410+
17411+
// to determine the Accept header
17412+
localVarHttpHeaderAccepts := []string{
17413+
"application/json",
17414+
}
17415+
17416+
// set Accept header
17417+
localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
17418+
if localVarHttpHeaderAccept != "" {
17419+
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
17420+
}
17421+
// body params
17422+
localVarPostBody = &rect
17423+
r, err := a.client.prepareRequest(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
17424+
if err != nil {
17425+
return successPayload, nil, err
17426+
}
17427+
17428+
localVarHttpResponse, err := a.client.callAPI(r)
17429+
if err != nil || localVarHttpResponse == nil {
17430+
return successPayload, localVarHttpResponse, err
17431+
}
17432+
defer localVarHttpResponse.Body.Close()
17433+
if localVarHttpResponse.StatusCode >= 300 {
17434+
bodyBytes, _ := io.ReadAll(localVarHttpResponse.Body)
17435+
return successPayload, localVarHttpResponse, reportError("Status: %v, Body: %s", localVarHttpResponse.Status, bodyBytes)
17436+
}
17437+
17438+
if err = deserializeDTO(localVarHttpResponse.Body, &successPayload); err != nil {
17439+
return successPayload, localVarHttpResponse, err
17440+
}
17441+
17442+
return successPayload, localVarHttpResponse, err
17443+
}
17444+
1735617445
/* PdfApiService Rsize PDF document.
1735717446
@param name The document name.
1735817447
@param height Page Height
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"path"
6+
7+
asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
8+
)
9+
10+
func ParseExtractFormsAsFDF(pdf_api *asposepdfcloud.PdfApiService, documentName string, outputFDFName string, remoteFolder string) {
11+
// Extract Form fields from the document to FDF file
12+
uploadFile(pdf_api, documentName)
13+
14+
args := map[string]interface{}{
15+
"folder": remoteFolder,
16+
}
17+
18+
fdfPath := path.Join(remoteFolder, outputFDFName)
19+
20+
_, httpResponse, err := pdf_api.PutExportFieldsFromPdfToFdfInStorage(documentName, fdfPath, args)
21+
if err != nil {
22+
fmt.Println(err.Error())
23+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
24+
fmt.Println("ParseExtractFormsAsFDF(): Failed to extract Form fields from the document.")
25+
} else {
26+
fmt.Println("ParseExtractFormsAsFDF(): Forms fields successfully extracted from the document '" + documentName + "'.")
27+
downloadFile(pdf_api, outputFDFName, outputFDFName)
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"path"
6+
7+
asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
8+
)
9+
10+
func ParseExtractFormsAsXML(pdf_api *asposepdfcloud.PdfApiService, documentName string, outputXMLName string, remoteFolder string) {
11+
// Extract Form fields from the document to XML file
12+
uploadFile(pdf_api, documentName)
13+
14+
args := map[string]interface{}{
15+
"folder": remoteFolder,
16+
}
17+
18+
xmlPath := path.Join(remoteFolder, outputXMLName)
19+
20+
_, httpResponse, err := pdf_api.PutExportFieldsFromPdfToXmlInStorage(documentName, xmlPath, args)
21+
if err != nil {
22+
fmt.Println(err.Error())
23+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
24+
fmt.Println("ParseExtractFormsAsXML(): Failed to extract Form fields from the document.")
25+
} else {
26+
fmt.Println("ParseExtractFormsAsXML(): Forms fields successfully extracted from the document '" + documentName + "'.")
27+
downloadFile(pdf_api, outputXMLName, outputXMLName)
28+
}
29+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path"
7+
8+
asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
9+
)
10+
11+
func ParseExtractImages(pdf_api *asposepdfcloud.PdfApiService, documentName string, pageNumber int32, localFolder string, remoteFolder string) {
12+
// Extract Images from the page of PDF document
13+
uploadFile(pdf_api, documentName)
14+
15+
args := map[string]interface{}{
16+
"folder": remoteFolder,
17+
}
18+
19+
respImages, httpResponse, err := pdf_api.GetImages(documentName, pageNumber, args)
20+
if err != nil {
21+
fmt.Println(err.Error())
22+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
23+
fmt.Println("ParseExtractImages(): Failed to extract images from the page of document.")
24+
} else {
25+
for _, image := range respImages.Images.List {
26+
27+
response, httpResponse, err := pdf_api.GetImageExtractAsPng(documentName, image.Id, args)
28+
29+
if err != nil {
30+
fmt.Println(err.Error())
31+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
32+
fmt.Println("ParseExtractImages(): Failed to extract image.")
33+
} else {
34+
fmt.Println("ParseExtractImages(): Images'" + image.Id + "' successfully extracted from the page of document.")
35+
36+
fileName := path.Join(localFolder, (image.Id + ".png"))
37+
f, _ := os.Create(fileName)
38+
_, _ = f.Write(response)
39+
fmt.Println("File '" + fileName + "' successfully downloaded.")
40+
}
41+
}
42+
}
43+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
"path"
8+
9+
asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
10+
)
11+
12+
func ParseExtractTables(pdf_api *asposepdfcloud.PdfApiService, documentName string, localFolder string, remoteFolder string) {
13+
// Extract tables form the document
14+
uploadFile(pdf_api, documentName)
15+
16+
args := map[string]interface{}{
17+
"folder": remoteFolder,
18+
}
19+
20+
result, httpResponse, err := pdf_api.GetDocumentTables(documentName, args)
21+
if err != nil {
22+
fmt.Println(err.Error())
23+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
24+
fmt.Println("ExtractTables(): Failed to extract tables from the document.")
25+
} else {
26+
if result.Tables == nil || len(result.Tables.List) == 0 {
27+
fmt.Println("ExtractTables(): Tables not found in the document.")
28+
} else {
29+
resultJson := "[\n"
30+
for _, t := range result.Tables.List {
31+
respTable, httpResponse, err := pdf_api.GetTable(documentName, t.Id, args)
32+
if err != nil {
33+
fmt.Println(err.Error())
34+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
35+
fmt.Println("ExtractTables(): Failed to extract table from the document.")
36+
} else {
37+
fmt.Println("table", respTable.Table)
38+
jsTable, _ := json.Marshal(respTable.Table)
39+
resultJson += string(jsTable) + ",\n\n"
40+
}
41+
}
42+
resultJson += "]"
43+
fileName := path.Join(localFolder, ("parsed_tables_output.json"))
44+
f, _ := os.Create(fileName)
45+
_, _ = f.Write([]byte(resultJson))
46+
fmt.Println("File '" + fileName + "' successfully downloaded.")
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)