Skip to content

Commit 9d82257

Browse files
PDFCLOUD-4967: added snippets for Stamps
1 parent 381763c commit 9d82257

File tree

6 files changed

+192
-0
lines changed

6 files changed

+192
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 AppendStampImage(pdf_api *asposepdfcloud.PdfApiService, documentName string, outputDocument string, imageFileName string, width float64, height float64, remoteFolder string) {
11+
uploadFile(pdf_api, documentName)
12+
uploadFile(pdf_api, imageFileName)
13+
14+
args := map[string]interface{}{
15+
"folder": remoteFolder,
16+
}
17+
18+
stamp := asposepdfcloud.ImageStamp{
19+
Background: true,
20+
HorizontalAlignment: asposepdfcloud.HorizontalAlignmentCenter,
21+
VerticalAlignment: asposepdfcloud.VerticalAlignmentCenter,
22+
Opacity: 1,
23+
Rotate: asposepdfcloud.RotationNone,
24+
RotateAngle: 45,
25+
Width: width,
26+
Height: height,
27+
Zoom: 1,
28+
FileName: path.Join(remoteFolder, imageFileName),
29+
}
30+
_, httpResponse, err := pdf_api.PostDocumentImageStamps(documentName, []asposepdfcloud.ImageStamp{stamp}, args)
31+
if err != nil {
32+
fmt.Println(err.Error())
33+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
34+
fmt.Println("appendStampImage()): Failed to append image stamp to the document.")
35+
} else {
36+
fmt.Println("appendStampImage(): image stamp '" + imageFileName + "' appended successfully to the document '" + documentName + "'.")
37+
downloadFile(pdf_api, documentName, outputDocument, "add_image_stamp_")
38+
}
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
7+
)
8+
9+
func AppendStampText(pdf_api *asposepdfcloud.PdfApiService, documentName string, outputDocument string, text_value string, remoteFolder string) {
10+
uploadFile(pdf_api, documentName)
11+
12+
args := map[string]interface{}{
13+
"folder": remoteFolder,
14+
}
15+
16+
stamp := asposepdfcloud.TextStamp{
17+
Background: true,
18+
HorizontalAlignment: asposepdfcloud.HorizontalAlignmentCenter,
19+
VerticalAlignment: asposepdfcloud.VerticalAlignmentCenter,
20+
Opacity: 1,
21+
Rotate: asposepdfcloud.RotationNone,
22+
RotateAngle: 30,
23+
Zoom: 1,
24+
TextAlignment: asposepdfcloud.HorizontalAlignmentCenter,
25+
Value: text_value,
26+
TextState: &asposepdfcloud.TextState{FontSize: 14, FontStyle: asposepdfcloud.FontStylesBoldItalic, Font: "Arial", ForegroundColor: &asposepdfcloud.Color{A: 0xFF, R: 0xFF, G: 0x00, B: 0x00}},
27+
}
28+
29+
_, httpResponse, err := pdf_api.PostDocumentTextStamps(documentName, []asposepdfcloud.TextStamp{stamp}, args)
30+
if err != nil {
31+
fmt.Println(err.Error())
32+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
33+
fmt.Println("appendStampText(): Failed to append text stamp to the document.")
34+
} else {
35+
fmt.Println("appendStampText(): text stamp '" + text_value + "' appended successfully to the document '" + documentName + "'.")
36+
downloadFile(pdf_api, documentName, outputDocument, "add_text_stamp_")
37+
}
38+
}

uses_cases/stamps/stamps_delete.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
7+
)
8+
9+
func DeleteDocumentStamps(pdf_api *asposepdfcloud.PdfApiService, documentName string, outputDocument string, remoteFolder string) {
10+
uploadFile(pdf_api, documentName)
11+
12+
args := map[string]interface{}{
13+
"folder": remoteFolder,
14+
}
15+
16+
_, httpResponse, err := pdf_api.DeleteDocumentStamps(documentName, args)
17+
if err != nil {
18+
fmt.Println(err.Error())
19+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
20+
fmt.Println("DeleteDocumentStamps(): Failed to delete stamps in the document.")
21+
} else {
22+
fmt.Println("DeleteDocumentStamps(): all stamps successfully deleted in the document '" + documentName + "'.")
23+
downloadFile(pdf_api, documentName, outputDocument, "del_doc_stamps_")
24+
}
25+
}

uses_cases/stamps/stamps_helper.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.pdf"
17+
18+
IMAGE_STAMP_FILE = "sample.png"
19+
PAGE_NUMBER = 2
20+
STAMP_TEXT = "NEW TEXT STAMP"
21+
IMAGE_STAMP_LLY = 800
22+
IMAGE_STAMP_WIDTH = 24
23+
IMAGE_STAMP_HEIGHT = 24
24+
25+
APP_SID = "****************" // Your Application SID
26+
APP_KEY = "****************" // Your Application Key
27+
)
28+
29+
func initPdfApi() *asposepdfcloud.PdfApiService {
30+
// Initialize Credentials and create Pdf.Cloud service object
31+
pdfApi := asposepdfcloud.NewPdfApiService(APP_SID, APP_KEY, "")
32+
return pdfApi
33+
}
34+
35+
func uploadFile(pdf_api *asposepdfcloud.PdfApiService, name string) {
36+
args := map[string]interface{}{
37+
"folder": REMOTE_FOLDER,
38+
}
39+
file, _ := os.Open(filepath.Join(LOCAL_FOLDER, name))
40+
_, _, _ = pdf_api.UploadFile(filepath.Join(REMOTE_FOLDER, name), file, args)
41+
fmt.Println("File '" + name + "' successfully uploaded!")
42+
}
43+
func downloadFile(pdf_api *asposepdfcloud.PdfApiService, name string, output_name string, output_prefix string) {
44+
args := map[string]interface{}{
45+
"folder": REMOTE_FOLDER,
46+
}
47+
result_data, _, _ := pdf_api.DownloadFile(path.Join(REMOTE_FOLDER, name), args)
48+
fileName := path.Join(LOCAL_FOLDER, output_prefix+output_name)
49+
f, _ := os.Create(fileName)
50+
_, _ = f.Write(result_data)
51+
fmt.Println("Result file'" + (output_prefix + output_name) + "' successfully downloaded!")
52+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
func main() {
4+
pdfApi := initPdfApi()
5+
6+
AppendStampText(pdfApi, PDF_DOCUMENT, PDF_OUTPUT, STAMP_TEXT, REMOTE_FOLDER)
7+
8+
AppendStampImage(pdfApi, PDF_DOCUMENT, PDF_OUTPUT, IMAGE_STAMP_FILE, IMAGE_STAMP_WIDTH, IMAGE_STAMP_HEIGHT, REMOTE_FOLDER)
9+
10+
DeleteDocumentStamps(pdfApi, PDF_DOCUMENT, PDF_OUTPUT, REMOTE_FOLDER)
11+
12+
DeletePageStamps(pdfApi, PDF_DOCUMENT, PAGE_NUMBER, PDF_OUTPUT, REMOTE_FOLDER)
13+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
7+
)
8+
9+
func DeletePageStamps(pdf_api *asposepdfcloud.PdfApiService, documentName string, pageNumber int32, outputDocument string, remoteFolder string) {
10+
uploadFile(pdf_api, documentName)
11+
12+
args := map[string]interface{}{
13+
"folder": remoteFolder,
14+
}
15+
16+
_, httpResponse, err := pdf_api.DeletePageStamps(documentName, pageNumber, args)
17+
if err != nil {
18+
fmt.Println(err.Error())
19+
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
20+
fmt.Println("DeletDeletePageStampseStampText(): Failed to delete stamps in the document.")
21+
} else {
22+
fmt.Println("DeletePageStamps(): stamps successfully deleted on ", pageNumber, "page in the document '"+documentName+"'.")
23+
downloadFile(pdf_api, documentName, outputDocument, "del_page_stamps_")
24+
}
25+
}

0 commit comments

Comments
 (0)