Documents for PDF .NET Edition
GrapeCity Documents PDF Viewer / Edit PDF / Share and Collaborate
In This Topic
    Share and Collaborate
    In This Topic

    GcDocs PDF Viewer allows you to share a PDF document with other users. The document can be shared in view or/and edit mode and can be worked upon by multiple users in real time. You can also observe the presence of other users and the changes made by them in the shared document, known as real-time collaboration.

    The below image shows a PDF document in shared mode which has been edited by multiple users and their changes are visible along with their user names. 

    Once configured to use the SupportApi, a PDF document can be edited in following ways:

    Set up Collaboration Mode

    The collaboration mode, where multiple users can work on a shared document, is designed to work only with persistent client connections. To ensure this, the SupportApi includes the following nuget package dependencies:

    When a shared document is modified, the server-side SupportApi code instantly pushes the changes to connected clients as soon as the changes become available.

    To support persistent client connections for collaboration mode, configure your web application by editing Startup.cs file:

    1. Add SignalR service to the services collection  by calling SupportApi.Connection.GcPdfViewerHub.ConfigureServices(services); Inside the ConfigureServices method:

            public void ConfigureServices(IServiceCollection services)
            {
                services.AddRazorPages();
                // Enable routing:
                services.AddMvc((opts) => { opts.EnableEndpointRouting = false; });
                services.AddRouting();
                // Add SignalR service to the services collection:
                SupportApi.Connection.GcPdfViewerHub.ConfigureServices(services);
            }

    2. Map SignalR hub inside the Configure method as follows:


            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapRazorPages();
                   // Map SignalR hub:
                    endpoints.MapHub<SupportApi.Connection.GcPdfViewerHub>("/signalr");
                });
      }

    [assembly: OwinStartup(typeof(SupportApiDemo_WebForms.Startup))]
    namespace SupportApiDemo_WebForms {


      public class Startup {

        public void Configuration(IAppBuilder app)

        {
          // ... the rest of the code goes here
          SupportApi.Connection.GcPdfViewerHub.Configure(app);
          // Optionally, you can add known users, these users will be displayed in the user interface as a suggestions pop-up:
          GcPdfViewerController.Settings.AvailableUsers.Add("Anonymous");
          GcPdfViewerController.Settings.AvailableUsers.Add("James");
          GcPdfViewerController.Settings.AvailableUsers.Add("Lisa");    
          // For example, you can use your own shared document storage
          // which implements the ICollaborationStorage interface:
          GcPdfViewerController.Settings
              .Collaboration
              .Storage
              .UseCustomStorage(myCloudStorage);
        }
      }
    }

     

    Note: Using SupportApi in ASP.NET Core projects requires ASP.NET Core 3.0 or later. For more details on how to upgrade an existing ASP.NET Core 2.2 project to 3.0, refer this link.

    Store Changes in Collaboration Mode

    When you make changes to PDF documents in shared mode, the modified documents are stored in server's memory by default. These changes are discarded in either of the below cases:

    To prevent this, you can do any of the following:

    Share a PDF Document

    You can share a PDF document by clicking on the 'share' button in GcDocs PDF Viewer's toolbar.

    To add the 'share' button in toolbar, use the following code:

    Index.cshtml
    Copy Code
    viewer.toolbarLayout.viewer.default = ["share"];
    viewer.applyToolbarLayout();
    

    When you click on 'share' button, the 'Manage Access' dialog box opens as shown below: 

    You can provide access to other users and set their permissions to 'View only' or 'View and Change'.

    You can also change the access of existing users or stop sharing the document with them.

    Note: The PDF document owner can perform all the above operations. Other users cannot edit/delete the document owner or change his permissions. However, other users with edit permissions can add other users, change their permissions or stop sharing the document.

    Open a Shared PDF Document

    You can open a shared PDF document by using the 'Shared Documents' panel. This panel lists all the documents that the current user has shared and has access to, with information about the access mode.

    To add the 'Shared Documents' panel to the sidebar panel, use the following code:

    Index.cshtml
    Copy Code
    var viewer = new GcPdfViewer("#root", { supportApi: 'api/pdf-viewer'} );
    viewer.addSharedDocumentsPanel();
    

    Real-time Co-authoring

    When multiple users collaborate in a PDF document at the same time, you can see the real-time changes along with the name of users. Whenever a shared document is opened, the ‘shared mode’ label with the document's access type is shown on the top right corner of the document, as shown below:

    You can also use "sharing" option in API to configure document sharing options, like: