Opening and saving files

Posted by: storm.binary on 30 May 2023, 7:09 am EST

  • Posted 30 May 2023, 7:09 am EST

    Hello,

    First of all, here is my use case, from the viewer angle, on the client side:

    I like to be able to use the viewer.open(arrayBuffer) to load a pdf file into the viewer and then whenever content of document in the viewer is changed then I am notified and has access to the fully updated document for my further processing.

    Secondly, how can I simulate the viewer save toolbar item click event in code?

    Thank you.

  • Posted 1 June 2023, 1:17 am EST

    Hi Storm,

    We are sorry for the inconvenience but currently, there is no method or property for fetching the updated PDF. The updated PDF can be found on the server by calling the saveChanges() method from the client.

    This is with the internal team with internal tracking id DOC-4254. but this is the limitation for now.

    On the server, we may get the updated PDF and process on the server.

    Secondly, how can I simulate the viewer save toolbar item click event in code?

    For this, we may define the callback in action of the custom button.

    viewer.toolbar.addItem({ 
    	key: 'custom-save', 
    	icon: '*'
    	title: 'Save document',
    	enabled: false,
    	action: function() {
    		// custom action
    	},

    Hope it helps!

    Regards,

    Manish Gupta

  • Posted 1 June 2023, 4:46 am EST

    Hi Manish,

    I am grateful for the reply.

    In that case then, can I send a string value to the server-side when viewer.saveChanges() is called? In otherwords, can I set some key on the viewer side which then I can recall on the server-side?

    Thanks

  • Posted 2 June 2023, 4:17 am EST

    Hi Storm,

    If we understand correctly you would like to send the user name or user id along with the data to parse on the server so that it can be saved at the appropriate location.

    Please confirm and elaborate on your use case.

    Regards,

    Manish Gupta

  • Posted 2 June 2023, 7:41 am EST

    Hi Manish,

    Yes correct. I need to send a small json with about 5 properties containing user details etc.

    Regards.

  • Posted 5 June 2023, 10:16 am EST

    Hi Storm,

    You may define the userData while initializing the GcPdfViewer like below:

    var options = {
            workerSrc: "/lib/gc-pdfviewer/build/gcpdfviewer.worker.js",
            supportApi: {
                apiUrl: 'api/pdf-viewer',
                token: 'support-api-demo-net-core-token',
                reconnectInterval: 1000
            },
            logLevel: 'Debug',
            userName: getHashValue('user') || 'Anonymous',
            userData: { secretNumber: 5, innerData: { innerContent: 'content' } }
        };

    And this data can be fetched on Server within the OnDocumentModified method.

    public override void OnDocumentModified(GcPdfDocumentLoader documentLoader)
            {
                var userData = documentLoader.Info.documentOptions.userData as JObject;
                // code here
            }


    For now, the userData cannot be updated after initializing the GcPdfViewer. And we are investigating this with the internal tracking id DOC-5467.

    We will let you know as we get an update on this.

    Regards,

    Manish Gupta

  • Posted 5 June 2023, 11:11 am EST - Updated 5 June 2023, 6:20 pm EST

    Thank you for the reply.

    It is obviously important to be able to send user data with each update.

    Do you happen to know when DOC-5467 will close?

    Meanwhile, any other way to send userdata, any work around at all?

    Thanks.

  • Posted 5 June 2023, 8:25 pm EST

    Hi Storm,

    I think I was not so clear. The issue is that the userData cannot be updated later after Viewer initialization means the on-server userData during Viewer initializing can be fetched.

    The way suggested above is by defining the userData with options, the userData can be sent to the server on each server call in your case saveChanges() method call.

    We will let you know as we get an update.

    Hope it clears!

    Regards,

    Manish Gupta

  • Posted 16 June 2023, 10:10 pm EST

    Hi,

    This issue has been fixed and now the data can be transferred later too. The official fix would be included in the next release but for now, please find the attached sample and use that sample in the meantime.

    Regards,

    Manish Gupta

    userData_updated_230610.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels