• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Save button is disabled

New Here ,
May 03, 2022 May 03, 2022

Copy link to clipboard

Copied

Hello Adobe,
I am using embeded pdf API to display pdf and allow to annotate document. I am saving annotations in my database and also able to load annotation from database to file. But now "Save" button is getting disabled. I am not able to download pdf file with modified changes.

I have attached screnshot for it. From "Download Pdf" option it's getting download file without any annotation But I want to allow to download file with annotation.
When I was testing with simple demo It's allow me to download file with annotation from save button. 
But now "Save" button is disabled so I am not able to download file with annotation.
After making any changes in file it's not getting enabled.

I have also attached following code.

var AdobePdfViewer = AdobePdfViewer || {};
AdobePdfViewer.AnnotationDataListName = 'AnnotationData';
AdobePdfViewer.ExistingAnnotationData = [];
AdobePdfViewer.ExistingAnnotationDataId = 0;
AdobePdfViewer.MeetingId = 0;
AdobePdfViewer.AgendaId = 0;
AdobePdfViewer.DocumentId = 0;

var pdfInfo = {
    username: _spPageContextInfo.userDisplayName,
    email: _spPageContextInfo.userEmail,
    url: "",
    x: 0,
    y: 0,
    id: 0,
    name: "",
    note: "",
    pege: 1,
    documentId: 0
};
var adobeDocViwer;
const saveOptions = {
    autoSaveFrequency: 0,
    enableFocusPolling: false,
    showSaveButton: true
};

document.addEventListener("adobe_dc_view_sdk.ready", function () {
    console.log("Adobe pdf viewer ready");
});

// document.addEventListener("adobe_dc_view_sdk.ready", function () {
AdobePdfViewer.OpenFileInPdfViewer = function (MeetingId, AgendaId, DocumentId, DocumentURL, DocumentName) {
    AdobePdfViewer.MeetingId = MeetingId;
    AdobePdfViewer.AgendaId = AgendaId;
    AdobePdfViewer.DocumentId = DocumentId;
    pdfInfo.name = DocumentName;
    pdfInfo.id = DocumentId;
    pdfInfo.documentId = DocumentId;
    pdfInfo.url = DocumentURL;
    AdobePdfViewer.GetAnnotationData(AgendaId, DocumentId);

    var adobeDCView = new AdobeDC.View({
        clientId: "e030789a44534e3394c88b51d63f39c2",
        divId: "adobe-dc-view"
    });
    var previewFilePromise = adobeDCView.previewFile({
        content: {
            location: {
                url: DocumentURL
            }
        },
        metaData: {
            fileName: pdfInfo.name,
            //id: "FileID1" //pdfInfo.id || "file1" /* this is required for annotation to work */
            id: "Document_" + pdfInfo.id
        },
    }, {
        showAnnotationTools: true,
        enableAnnotationAPIs: true,
        showDisabledSaveButton: true,
        //defaultViewMode: "FIT_PAGE",
        enableFormFilling: true
    });
    adobeDocViwer = adobeDCView;


    previewFilePromise.then(adobeViewer => {
        adobeViewer.getAnnotationManager().then(annotationManager => {
            window.AdobeAnnotationManager = annotationManager;
            // All annotation APIs can be invoked here
            console.log("loading annotations ....")

            return loadDocumentAnnotations(AdobePdfViewer.AgendaId, AdobePdfViewer.DocumentId).then(function (listOfAnnotations) {
                console.log("List of annotations from db1 ", listOfAnnotations);
                if (listOfAnnotations && listOfAnnotations.length) {
                    annotationManager.addAnnotations(listOfAnnotations).then(function () {
                        registerAnnotationEventListeners(annotationManager);
                    });
                } else {
                    registerAnnotationEventListeners(annotationManager);
                }
                document.title = pdfInfo.name;
                var div = document.querySelector("#righPanel");
                if (div) {
                    div.classList.remove("loading");
                }
                toggleRightPanel();

                var note = window.pdfInfo.note;
                if (note) {
                    annotationManager.selectAnnotation(note);
                }
            }).catch(function () {
                registerAnnotationEventListeners(annotationManager);
            });
        });

        adobeViewer.getAPIs().then(function (apis) {
            if (window.pdfInfo.page) {
                var x = Number(pdfInfo.x || 0);
                var y = Number(pdfInfo.y || 0);
                var page = Number(page) || 1;

                setTimeout(function () {
                    apis.gotoLocation(page, x, y);
                }, 800);
            }
            window.AdobeVieweApi = apis;
        });

        window.AdobeViewer = adobeViewer;
    });


    adobeDCView.registerCallback(AdobeDC.View.Enum.CallbackType.GET_USER_PROFILE_API, function () {
        return Promise.resolve({
            code: AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
            data: {
                userProfile: {
                    name: window.pdfInfo.username,
                    firstName: "",
                    lastName: "",
                    email: window.pdfInfo.email
                }
            }
        });
    });

    adobeDCView.registerCallback(
        AdobeDC.View.Enum.CallbackType.SAVE_API,
        function (metaData, content, options) {
            console.log("Save button click call");
            return new Promise(function (resolve, reject) {
                var url = '/pdf/updatebinary?fileStreamId=' + pdfInfo.documentId;

                console.log("saving...")
                fetch(url, {
                    method: 'POST',
                    body: content
                }).then(function (response) {
                    return response.json();
                }).then(function (result) {
                    console.log("saving done");
                    resolve({
                        code: AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
                        data: {
                            metaData: metaData
                        }
                    });
                }).catch(function (err) {
                    reject({
                        code: AdobeDC.View.Enum.ApiResponseCode.FAIL,
                        data: {
                            metaData: metaData
                        }
                    });
                });
            });
        }, {
            autoSaveFrequency: 0,
            enableFocusPolling: false,
            showSaveButton: true
        }
    );


    adobeDCView.registerCallback(
        AdobeDC.View.Enum.CallbackType.EVENT_LISTENER,
        function (event) {
            console.log("Alert annotation started.......................")
            console.log(event.type, event.data);
            toggleRightPanel('notes');
        }, {
            // Pass the events to receive.
            // If no event is passed in listenOn, then all the annotation events will be received.
            listenOn: [
                AdobeDC.View.Enum.AnnotationEvents.ANNOTATION_ADDED,
                AdobeDC.View.Enum.AnnotationEvents.ANNOTATION_CLICKED,
                AdobeDC.View.Enum.AnnotationEvents.ANNOTATION_MODE_STARTED
            ],
            enableAnnotationEvents: true
        }
    );

    adobeDCView.registerCallback(
        AdobeDC.View.Enum.CallbackType.EVENT_LISTENER,
        function (event) {
            console.log("preview selection end fired")
            AdobeVieweApi.getSelectedContent().then(function (result) {
                copyToClipboard(result);
            });
        }, {
            listenOn: [AdobeDC.View.Enum.FilePreviewEvents.PREVIEW_SELECTION_END],
            enableFilePreviewEvents: true
        }
    );


    adobeDCView.registerCallback(
        AdobeDC.View.Enum.CallbackType.EVENT_LISTENER,
        function (event) {
            console.log("event", event);
            var copiedText = event.data.copiedText;

            var frame = document.querySelector('#propIFrame');
            if (frame && frame.contentWindow) {
                var selectedField = frame.contentWindow.lastFocusedField;
                if (selectedField && /(input|select|textarea)/i.test(selectedField.nodeName)) {
                    selectedField.value = copiedText;
                }
            }
        }, {
            //Pass the PDF analytics events to receive.
            //If no event is passed in listenOn, then all PDF analytics events will be received.
            listenOn: [AdobeDC.View.Enum.PDFAnalyticsEvents.TEXT_COPY],
            enablePDFAnalytics: true
        }
    );

}
// });



function loadDocumentAnnotations(AgendaId, DocumentId) {
    return new Promise(function (resolve, reject) {
        var annotationData = [];
        if (AdobePdfViewer.ExistingAnnotationDataId > 0 && AdobePdfViewer.ExistingAnnotationData && AdobePdfViewer.ExistingAnnotationData.length > 0) {
            annotationData = AdobePdfViewer.ExistingAnnotationData;
        } else {
            annotationData = [];
            //return  JSON.parse(result.ResultString || [])
        }
        resolve(annotationData);
    });
    //return AdobePdfViewer.GetAnnotationData(AgendaId, DocumentId);
}

function registerAnnotationEventListeners(annotationManager) {

    var eventOptions = {
        // Pass the events to receive.
        // If no event is passed in listenOn, then all the annotation events will be received.
        listenOn: [
            "ANNOTATION_ADDED", "ANNOTATION_UPDATED", "ANNOTATION_DELETED"
        ]
    };
    annotationManager.registerEventListener(
        function (event) {
            console.log(event.type, event.data);
            annotationManager.getAnnotations().then(function (result) {
                console.log("all annotations => ", result);
                console.log("saving annotations");
                // saveDocumentAnnotations(pdfInfo.name, pdfInfo.url, result).then(function (done) {
                //     console.log("Annotations updated.")
                // });

                AdobePdfViewer.SaveAnnotationData(AdobePdfViewer.MeetingId, AdobePdfViewer.AgendaId, AdobePdfViewer.DocumentId, result, AdobePdfViewer.ExistingAnnotationDataId);
            });
        },
        eventOptions
    );
}

function toggleRightPanel(panel) {
    panel = panel || sessionStorage.getItem("rpanel") || "notes";
    document.body.setAttribute('data-rpanel', panel);
    sessionStorage.setItem("rpanel", panel);

    //AdobeViewer.executeCommand('TOGGLE_COMMENTING', true); 
    AdobeAnnotationManager.setConfig({
        showCommentsPanel: true
    });
}

function copyToClipboard(str) {
    var el = document.createElement('textarea');
    el.value = str;
    el.setAttribute('readonly', '');
    el.style.position = 'absolute';
    el.style.left = '-9999px';
    document.body.appendChild(el);
    var selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
    el.select();
    document.execCommand('copy');
    document.body.removeChild(el);
    if (selected) {
        document.getSelection().removeAllRanges();
        document.getSelection().addRange(selected);
    }
};

AdobePdfViewer.SaveAnnotationData = function (MeetingId, AgendaId, DocumentId, AnnotationData, ExistingAnnotationId) {
    // $(".preloader").fadeIn();    
    var objAnnotationData = {}
    objAnnotationData.MeetingId = MeetingId;
    objAnnotationData.AgendaId = AgendaId;
    objAnnotationData.DocumentId = DocumentId;
    objAnnotationData.AnnotationData = JSON.stringify(AnnotationData);

    var isAsync = true;
    var siteUrl = _spPageContextInfo.webAbsoluteUrl;
    if (ExistingAnnotationId > 0) {
        //console.log('update annotation');
        spRestAPICallsUtil.updateListItem(siteUrl, AdobePdfViewer.AnnotationDataListName, objAnnotationData, ExistingAnnotationId, isAsync)
            .done(function (data) {
                //console.log("Update Annotation SP", data);
                //DisplayNotification("Success", "Your annotation has been saved for this document!", "success");
                // $(".preloader").fadeOut(200);
            }).fail(function () {
                //DisplayNotification("Alert", "Error in saving annotation data. Please try again", "danger");
            });
    } else {
        // console.log('add annotation');
        spRestAPICallsUtil.createListItem(siteUrl, AdobePdfViewer.AnnotationDataListName, objAnnotationData, isAsync)
            .done(function (data) {
                //console.log("Save Annotation SP", data);
                AdobePdfViewer.ExistingAnnotationDataId = data.d.Id;
                //DisplayNotification("Success", "Your annotation has been saved for this document!", "success");
                //$(".preloader").fadeOut(200);
            });
    }
    return false;
}

AdobePdfViewer.GetAnnotationData = function (AgendaId, DocumentId) {
    var UserId = _spPageContextInfo.userId;
    var deferred = $.Deferred()
    var listName = AdobePdfViewer.AnnotationDataListName;
    var queryStr = "$select=*&$filter=(AuthorId eq " + UserId + " and AgendaId eq " + AgendaId + " and DocumentId eq " + DocumentId + ")";
    var siteUrl = _spPageContextInfo.webAbsoluteUrl
    // spRestAPICallsUtil.getListItemById(siteUrl, listName, queryStr, ptoID)
    spRestAPICallsUtil.getListItems(siteUrl, listName, queryStr, false)
        .done(function (data) {
            //console.log(data);
            if (data && data.value && data.value.length > 0) {
                var i;
                for (i = 0; i < data.value.length; ++i) {
                    // do something with `substr[i]`
                    AdobePdfViewer.ExistingAnnotationDataId = data.value[i].ID;
                    if (data.value[i].AnnotationData) {
                        AdobePdfViewer.ExistingAnnotationData = JSON.parse(data.value[i].AnnotationData);
                    } else {
                        AdobePdfViewer.ExistingAnnotationData = [];
                    }
                }

            }
            return deferred.resolve(data);
            //return deferred.resolve(JSON.parse(AdobePdfViewer.ExistingAnnotationData));
        })
    return deferred.promise();
}

function uuidv4() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0,
            v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}

 

Views

146

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Resources