diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js
index 61de69946ca75ba047581d8b78337bf7ba8858de..98391ddf14ba6b3cbedca736d0639f2ee6ef8ae0 100644
--- a/javascript/src/iframe/viamapi-iframe.js
+++ b/javascript/src/iframe/viamapi-iframe.js
@@ -932,68 +932,8 @@ const connection = Penpal.connectToParent({
 
       return encodeResponse("200", response.data, "Email signed");
     },
-    signPdf: async (passportUUID, pdfRaw /*array buffer*/) => {
-
-        //TODO api is not finished
-
-        const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
-
-        if (
-            !authenticationPublicKey ||
-            !window.loadedIdentities[authenticationPublicKey] ||
-            !extendPinCodeTtl(authenticationPublicKey)
-        ) {
-            return encodeResponse("400", "", "Identity not authenticated");
-        }
-
-        let response = await getCertificateForPassport(passportUUID, true);
-
-        if (response.code !== "200") {
-            return encodeResponse("400", "", response.status);
-        }
-
-        const {
-            x509Certificate: passportCertificate,
-            privateKey: passportPrivateKey,
-            chain: passportChain
-        } = response.data;
-
-        const keys =
-            await createOneTimePassportCertificate(
-                makeid() + "-" + passportUUID, null, passportPrivateKey, passportCertificate);
-
-        const { privateKeyPEM: privateKeyOneTime, certificatePEM: certificateOneTime } = keys;
-
-        passportChain.push(passportCertificate);
-
-        const signedPdf = await signPdf(pdfRaw, certificateOneTime, passportChain, privateKeyOneTime);
-
-        //for test
-        response.data.signedPdf = signedPdf;
-        //for test
-
-        // response = await executeRestfulFunction(
-        //     "private", window.viamApi, window.viamApi.passportGetEmailWithHeaderByPassport, null, passportUUID, emailMessage);
-        //
-        // if (response.code !== "200") {
-        //     return encodeResponse("400", "", response.status);
-        // }
-        //
-        // const signedEmail = await signEmail(response.data, certificateOneTime, passportChain, privateKeyOneTime);
-        //
-        // response = await executeRestfulFunction(
-        //     "private", window.viamApi, window.viamApi.signResignEmail, null, passportUUID, signedEmail);
-        //
-        // if (response.code !== "200") {
-        //     return encodeResponse("400", "", response.status);
-        // }
-
-        return encodeResponse("200", response.data, "PDF signed");
-    },
     signDocument: async (passportUUID, documentUUID, documentContentType) => {
 
-      //TODO api is not finished
-
       const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
 
       if (
@@ -1004,17 +944,17 @@ const connection = Penpal.connectToParent({
         return encodeResponse("400", "", "Identity not authenticated");
       }
 
-      const response = await getCertificateForPassport(passportUUID, true);
+      const certResponse = await getCertificateForPassport(passportUUID, true);
 
-      if (response.code !== "200") {
-        return encodeResponse("400", "", response.status);
+      if (certResponse.code !== "200") {
+        return encodeResponse("400", "", certResponse.status);
       }
 
       const {
         x509Certificate: passportCertificate,
         privateKey: passportPrivateKey,
         chain: passportChain
-      } = response.data;
+      } = certResponse.data;
 
       const keys =
         await createOneTimePassportCertificate(
@@ -1035,37 +975,31 @@ const connection = Penpal.connectToParent({
       }
 
       const downloadResponse = await executeRestfulFunction(
-        "private", window.viamApi, window.viamApi.documentGetDocumentByUUID, null, documentUUID, pdfContentType)
+        "private", window.viamApi, window.viamApi.documentGetDocumentByUUID, null, documentUUID, pdfContentType);
 
       if (downloadResponse.code !== "200") {
         return encodeResponse("400", "", downloadResponse.status);
       }
 
-      let pdfRaw = this.base64ToByteArray(downloadResponse.data);
+      const pdfRaw = await this.base64ToByteArray(downloadResponse.data);
 
       const signedPdf = await signPdf(pdfRaw, certificateOneTime, passportChain, privateKeyOneTime);
 
-      //for test
-      response.data.signedPdf = signedPdf;
-      //for test
-
-      // response = await executeRestfulFunction(
-      //     "private", window.viamApi, window.viamApi.passportGetEmailWithHeaderByPassport, null, passportUUID, emailMessage);
-      //
-      // if (response.code !== "200") {
-      //     return encodeResponse("400", "", response.status);
-      // }
-      //
-      // const signedEmail = await signEmail(response.data, certificateOneTime, passportChain, privateKeyOneTime);
-      //
-      // response = await executeRestfulFunction(
-      //     "private", window.viamApi, window.viamApi.signResignEmail, null, passportUUID, signedEmail);
-      //
-      // if (response.code !== "200") {
-      //     return encodeResponse("400", "", response.status);
-      // }
-
-      return encodeResponse("200", response.data, "PDF signed");
+      const signedPdfB64 = await this.byteArrayToBase64(signedPdf);
+
+      const uploadResponse = await executeRestfulFunction(
+        "private", window.viamApi, window.viamApi.documentPutDocumentByUUID, null, documentUUID, pdfContentType, signedPdfB64);
+      if (uploadResponse.code !== "200") {
+        return encodeResponse("400", "", uploadResponse.status);
+      }
+
+      const signResponse = await executeRestfulFunction(
+        "private", window.viamApi, window.viamApi.documentSignDocumentByUUID, null, passportUUID, documentUUID, pdfContentType);
+      if (signResponse.code !== "200") {
+        return encodeResponse("400", "", signResponse.status);
+      }
+
+      return encodeResponse("200", "", "Document signed");
     },
     documentCreateDocument: async (path, passportUUID, contenttype) => {
       const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");