// This code is part of GrapeCity Documents for PDF samples.
// Copyright (c) GrapeCity, Inc. All rights reserved.
using System.IO;
using GrapeCity.Documents.Pdf;

namespace GcPdfWeb.Samples
    // This sample demonstrates stamp annotation editing features of GcPdfViewer with support API
    // provided by the server running GcPdf. It loads an example pdf with some
    // sample stamp annotation added. You can use the annotation editing features of GcPdfViewer
    // to inspect or edit existing stamp annotations, or add new ones.

    // This and other samples in this section demonstrate the features of GcPdfViewer
    // (a JavaScript PDF viewer control included with GcPdf), mainly the ability
    // to change PDF files (add or edit annotations and AcroForm fields, rotate pages etc.)
    // when the JS viewer on the client is supported by GcPdf running on the server.
    // To enable the editing features of the viewer, its supportApi property must be set
    // to a URL on the server that implements all or some of the edit supporting APIs
    // that are known to/expected by the viewer. This GcPdf demo site provides those APIs,
    // which makes it possible to demonstrate the editing when you open the PDF viewer
    // in this sample. When you download this sample, in addition to the .NET Core
    // console app project that generates the sample PDF, an ASP.NET Core project is
    // also included in the download zip (located in the GcPdfViewerWeb sub-folder of the
    // downloaded zip), which also provides the necessary APIs. In particular, it includes
    // a project that implements the APIs and provides them via a special controller.
    // It is actually the same controller that is used by this GcPdf demo site, and which
    // can be used in any ASP.NET Core site to enable the viewer editing features.
    // Look at the following files in the sample download zip for more info:
    // - GcPdfViewerWeb\SupportApiDemo: the sample ASP.NET Core web site.
    // - GcPdfViewerWeb\SupportApiDemo.sln: solution to build/run the sample web site.
    // - GcPdfViewerWeb\SupportApi: support API implementation (can be used in any site).
    // - GcPdfViewerWeb\SupportApi\Controllers\GcPdfViewerController.cs: support API controller.
    // Please note that this and other samples in this section are only available in C# at this time.
        "We enable the annotation editor panel in GcPdfViewer, with only stamp annotation tool enabled by default. " +
        "You can edit the existing, or add new stamp annotations. " +
        "To save your changes, click the 'save' button in the annotation editor or in the main viewer toolbar. " +
        "This sends the PDF and the list of changes to the server where GcPdf applies the edits and " +
        "sends back the modified PDF. You can then open it in Acrobat or save locally.")]*/
    public class ViewerAddStamp
        public void CreatePDF(Stream stream)
            GcPdfDocument doc = new GcPdfDocument();
            using (var fs = new FileStream(Path.Combine("Resources", "PDFs", "viewer-add-stamp.pdf"), FileMode.Open, FileAccess.Read))

        // Used by SupportApiDemo to initialize GcPdfViewer.
        public static GcPdfViewerSupportApiDemo.Models.PdfViewerOptions PdfViewerOptions
            get => new GcPdfViewerSupportApiDemo.Models.PdfViewerOptions(
                GcPdfViewerSupportApiDemo.Models.PdfViewerOptions.Options.AnnotationEditorPanel | 
                viewerTools: new string[] { "save", "$navigation", "$split", "text-selection", "pan", "$zoom", "$fullscreen", "download", "print", "rotate", "view-mode", "hide-annotations", "doc-properties", "about" },
                annotationEditorTools: new string[] { "edit-select", "$split", "edit-stamp", "$split", "edit-undo", "edit-redo", "save" });

        public const string JS_CODE = @"
var viewer;
function createPdfViewer(selector, baseOptions) {
    var options = baseOptions || {};
    if(!options.supportApi) {
        options.supportApi = {
            apiUrl: (window.__baseUrl || '') + 'support-api/gc-pdf-viewer',
            token: window.afToken || '',
            webSocketUrl: false, suppressInfoMessages: true, suppressErrorMessages: true
    options.editorDefaults = { hideFloatingBar: true };
    viewer = new GcPdfViewer(selector, options);
    viewer.layoutMode = 1;
    viewer.toolbarLayout.viewer = { 
        default: ['save', '$navigation', '$split', 'text-selection', 'pan', '$zoom', '$fullscreen', 'download', 'print', 'rotate', 'view-mode', 'hide-annotations', 'doc-properties', 'about'],
        mobile: ['save', '$navigation', '$split', 'text-selection', 'pan', '$zoom', '$fullscreen', 'download', 'print', 'rotate', 'view-mode', 'hide-annotations', 'doc-properties', 'about'],
        fullscreen: ['$fullscreen', 'save', '$navigation', '$split', 'text-selection', 'pan', '$zoom', '$fullscreen', 'download', 'print', 'rotate', 'view-mode', 'hide-annotations', 'doc-properties', 'about']
    viewer.toolbarLayout.annotationEditor = { 
        default: ['open', 'edit-select', '$split', 'edit-stamp', '$split', 'edit-undo', 'edit-redo', 'save'], 
        mobile: ['open', 'edit-select', '$split', 'edit-stamp', '$split', 'edit-undo', 'edit-redo', 'save'], 
        fullscreen: ['$fullscreen', 'edit-select', '$split', 'edit-stamp', '$split', 'edit-undo', 'edit-redo', 'save'] 

    return viewer;