1
+ // 1. Load your Application Secret and Key from the JSON file or set credentials in another way
2
+ // 2. Create an object to connect to the Pdf.Cloud API
3
+ // 3. Upload your document file
4
+ // 4. Create a new Link Annotation with the required properties
5
+ // 5. Append new Link Annotation to the document using postPageLinkAnnotations() function
6
+ // 6. Perform some action after successful addition
7
+ // All values of variables starting with "YOUR_****" should be replaced by real user values
8
+
9
+ import credentials from "../../../../Credentials/credentials.json" with { type : "json" } ;
10
+ import fs from 'node:fs/promises' ;
11
+ import path from 'node:path' ;
12
+ import { PdfApi } from "../../../src/api/api.js" ;
13
+
14
+ const configParams = {
15
+ LOCAL_FOLDER : "C:\\Samples\\" ,
16
+ PDF_DOCUMENT_NAME : "sample.pdf" ,
17
+ PDF_STAMP_FILE : "pdf_stamp.pdf" ,
18
+ LOCAL_RESULT_DOCUMENT_NAME : "output_sample.pdf" ,
19
+ PAGE_NUMBER : 2 , // Your document page number...
20
+ STAMP_ID : "GE5TCOZQ" , // Your Stamp Id to be deleted...
21
+ } ;
22
+
23
+ const pdfApi = new PdfApi ( credentials . id , credentials . key ) ;
24
+
25
+ const pdfStamps = {
26
+ async uploadDocument ( ) {
27
+ const fileNamePath = path . join ( configParams . LOCAL_FOLDER , configParams . PDF_DOCUMENT_NAME ) ;
28
+ const pdfFileData = await fs . readFile ( fileNamePath ) ;
29
+ await pdfApi . uploadFile ( configParams . PDF_DOCUMENT_NAME , pdfFileData ) ;
30
+ } ,
31
+
32
+ async downloadResult ( ) {
33
+ const changedPdfData = await pdfApi . downloadFile ( configParams . PDF_DOCUMENT_NAME ) ;
34
+ const filePath = path . join ( configParams . LOCAL_FOLDER , configParams . LOCAL_RESULT_DOCUMENT_NAME ) ;
35
+ await fs . writeFile ( filePath , changedPdfData . body ) ;
36
+ console . log ( "Downloaded: " + filePath ) ;
37
+ } ,
38
+
39
+ async deletePageStamps ( ) {
40
+ const addResult = await pdfApi . deletePageStamps ( configParams . PDF_DOCUMENT_NAME , configParams . PAGE_NUMBER ) ;
41
+
42
+ if ( addResult . body . code == 200 ) {
43
+ console . log ( "Pdf page stamps on page #" + configParams . PAGE_NUMBER + " deleted!" ) ;
44
+ return true ;
45
+ }
46
+ else
47
+ console . error ( "Unexpected error : can't get pages!!!" ) ;
48
+ } ,
49
+
50
+ async deletePageStampById ( stamp_id ) {
51
+ const addResult = await pdfApi . deleteStamp ( configParams . PDF_DOCUMENT_NAME , stamp_id ) ;
52
+
53
+ if ( addResult . body . code == 200 ) {
54
+ console . log ( "Pdf stamps " + stamp_id + " deleted!" ) ;
55
+ return true ;
56
+ }
57
+ else
58
+ console . error ( "Unexpected error : can't get pages!!!" ) ;
59
+ } ,
60
+
61
+ }
62
+
63
+ async function main ( ) {
64
+ try {
65
+ await pdfStamps . uploadDocument ( ) ;
66
+ await pdfStamps . deletePageStampById ( configParams . STAMP_ID ) ;
67
+ await pdfStamps . deletePageStamps ( ) ;
68
+ await pdfStamps . downloadResult ( ) ;
69
+ } catch ( error ) {
70
+ console . error ( "Error:" , error . message ) ;
71
+ }
72
+ }
73
+
74
+ main ( ) ;
0 commit comments