コード例 #1
0
    void SaveDocument(IDocumentInfo documentInfo, bool checkModificationTime)
    {
        long itemId  = ParseDocumentIdFromEditor(documentInfo.DocumentId);
        Item docItem = DataService.FindItemById(itemId);

        if (docItem == null || checkModificationTime && documentInfo.LastModifyTime < docItem.LastWriteTime)
        {
            return;
        }

        byte[] content = null;
        if (IsRichEditDocument(docItem))
        {
            RichEditDocumentInfo richEditDocument = (RichEditDocumentInfo)documentInfo;
            content = richEditDocument.SaveCopy(RichEditDocumentManager.GetFormat(docItem));
        }
        else if (IsSpreadsheetDocument(docItem))
        {
            SpreadsheetDocumentInfo spreadsheetDocument = (SpreadsheetDocumentInfo)documentInfo;
            content = spreadsheetDocument.SaveCopy(SpreadsheetDocumentManager.GetFormat(docItem));
        }
        else
        {
            throw new Exception("Incorrect document format.");
        }

        docItem.UpdateContent(content);
        DataService.SaveChanges();
    }
コード例 #2
0
 protected void Spreadsheet_Init(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         Spreadsheet.ReadOnly = DocumentService.CurrentDocumentReadOnly;
         string        currentDocumentId = DocumentService.GetDocumentIdForEditor(CurrentDocument);
         IDocumentInfo openedDocument    = DocumentManager.FindDocument(currentDocumentId);
         if (openedDocument == null)
         {
             if (CurrentDocument.Content == null)
             {
                 Spreadsheet.New();
                 Spreadsheet.DocumentId  = currentDocumentId;
                 CurrentDocument.Content = DocumentsApp.Data.CreateBinaryContent(Spreadsheet.SaveCopy(DocumentService.GetSpreadsheetDocumentFormat(CurrentDocument)));
                 DocumentsApp.Data.SaveChanges();
             }
             else
             {
                 Spreadsheet.Open(
                     currentDocumentId,
                     DocumentService.CurrentSpreadsheetDocumentFormat,
                     () => CurrentDocument.Content.Data);
             }
         }
         else
         {
             Spreadsheet.Open((SpreadsheetDocumentInfo)openedDocument);
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Get document basic info
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Basic Usage] # GetDocumentInfo : Get document basic info\n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_SIGNED_MULTI;

            using (Signature signature = new Signature(filePath))
            {
                IDocumentInfo documentInfo = signature.GetDocumentInfo();
                Console.WriteLine($"Document properties {Path.GetFileName(filePath)}:");
                Console.WriteLine($" - format : {documentInfo.FileType.FileFormat}");
                Console.WriteLine($" - extension : {documentInfo.FileType.Extension}");
                Console.WriteLine($" - size : {documentInfo.Size}");
                Console.WriteLine($" - page count : {documentInfo.PageCount}");
                Console.WriteLine($" - Form Fields count : {documentInfo.FormFields.Count}");
                Console.WriteLine($" - Text signatures count : {documentInfo.TextSignatures.Count}");
                Console.WriteLine($" - Image signatures count : {documentInfo.ImageSignatures.Count}");
                Console.WriteLine($" - Digital signatures count : {documentInfo.DigitalSignatures.Count}");
                Console.WriteLine($" - Barcode signatures count : {documentInfo.BarcodeSignatures.Count}");
                Console.WriteLine($" - QrCode signatures count : {documentInfo.QrCodeSignatures.Count}");
                Console.WriteLine($" - FormField signatures count : {documentInfo.FormFieldSignatures.Count}");
                foreach (PageInfo pageInfo in documentInfo.Pages)
                {
                    Console.WriteLine($" - page-{pageInfo.PageNumber} Width {pageInfo.Width}, Height {pageInfo.Height}");
                }
            }
        }
コード例 #4
0
        public static void Run()
        {
            using (Converter converter = new Converter(Constants.SAMPLE_PDF_WITH_TOC))
            {
                IDocumentInfo info = converter.GetDocumentInfo();

                PdfDocumentInfo pdfInfo = (PdfDocumentInfo)info;

                Console.WriteLine("Author: {0}", pdfInfo.Author);
                Console.WriteLine("Creation date: {0}", pdfInfo.CreationDate);
                Console.WriteLine("Title: {0}", pdfInfo.Title);
                Console.WriteLine("Version: {0}", pdfInfo.Version);
                Console.WriteLine("Pages count: {0}", pdfInfo.PagesCount);
                Console.WriteLine("Width: {0}", pdfInfo.Width);
                Console.WriteLine("Height: {0}", pdfInfo.Height);
                Console.WriteLine("Is landscaped: {0}", pdfInfo.IsLandscape);
                Console.WriteLine("Is Password Protected: {0}", pdfInfo.IsPasswordProtected);

                Console.WriteLine("Table of contents");
                Console.WriteLine(new string('=', 40));
                foreach (var tocItem in pdfInfo.TableOfContents)
                {
                    Console.WriteLine($"{tocItem.Title}: {tocItem.Page}");
                }
            }

            Console.WriteLine("\nDocument info retrieved successfully.");
        }
 public static void Run()
 {
     // Create an instance of Parser class
     using (Parser parser = new Parser(Constants.SamplePdf))
     {
         // Check if the document supports text extraction
         if (!parser.Features.Text)
         {
             Console.WriteLine("Document isn't supports text extraction.");
             return;
         }
         // Get the document info
         IDocumentInfo documentInfo = parser.GetDocumentInfo();
         // Check if the document has pages
         if (documentInfo == null || documentInfo.RawPageCount == 0)
         {
             Console.WriteLine("Document hasn't pages.");
             return;
         }
         // Iterate over pages
         for (int p = 0; p < documentInfo.RawPageCount; p++)
         {
             // Print a page number
             Console.WriteLine(string.Format("Page {0}/{1}", p + 1, documentInfo.RawPageCount));
             // Extract a text into the reader
             using (TextReader reader = parser.GetText(p, new TextOptions(true)))
             {
                 // Print a text from the document
                 // We ignore null-checking as we have checked text extraction feature support earlier
                 Console.WriteLine(reader.ReadToEnd());
             }
         }
     }
 }
        /// <summary>
        /// Get document form fields and signatures information
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # GetDocumentProcessHistoryAdvanced : Get advanced document process history\n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_HISTORY;

            using (Signature signature = new Signature(filePath))
            {
                IDocumentInfo documentInfo = signature.GetDocumentInfo();
                // display document process history information
                Console.WriteLine($"Document Process logs information: count = {documentInfo.ProcessLogs.Count}");
                foreach (ProcessLog processLog in documentInfo.ProcessLogs)
                {
                    Console.WriteLine($" - operation [{processLog.Type}] on {processLog.Date.ToShortDateString()}. Succedded/Failed {processLog.Succeeded}/{processLog.Failed}. Message: {processLog.Message} : ");
                    if (processLog.Signatures != null)
                    {
                        foreach (BaseSignature logSignature in processLog.Signatures)
                        {
                            Console.WriteLine($"\t\t -{logSignature.SignatureType} #{logSignature.SignatureId} at {logSignature.Top} x {logSignature.Left} pos;");
                        }
                    }
                }
            }
        }
 public static void Run()
 {
     // Create an instance of Parser class
     using (Parser parser = new Parser(Constants.SampleImagesPdf))
     {
         // Check if the document supports images extraction
         if (!parser.Features.Images)
         {
             Console.WriteLine("Document isn't supports images extraction.");
             return;
         }
         // Get the document info
         IDocumentInfo documentInfo = parser.GetDocumentInfo();
         // Check if the document has pages
         if (documentInfo.PageCount == 0)
         {
             Console.WriteLine("Document hasn't pages.");
             return;
         }
         // Iterate over pages
         for (int pageIndex = 0; pageIndex < documentInfo.PageCount; pageIndex++)
         {
             // Print a page number
             Console.WriteLine(string.Format("Page {0}/{1}", pageIndex + 1, documentInfo.PageCount));
             // Iterate over images
             // We ignore null-checking as we have checked images extraction feature support earlier
             foreach (PageImageArea image in parser.GetImages(pageIndex))
             {
                 // Print a rectangle and image type
                 Console.WriteLine(string.Format("R: {0}, Text: {1}", image.Rectangle, image.FileType));
             }
         }
     }
 }
コード例 #8
0
        /// <inheritdoc/>
        public async Task <IDocumentInfo <T> > ReplaceAsync <T>(IDocumentInfo <T> existing,
                                                                T newItem, CancellationToken ct)
        {
            if (existing == null)
            {
                throw new ArgumentNullException(nameof(existing));
            }
            var ac = string.IsNullOrEmpty(existing.Etag) ? null : new AccessCondition {
                Condition = existing.Etag,
                Type      = AccessConditionType.IfMatch
            };
            var pk = _partitioned || string.IsNullOrEmpty(existing.PartitionKey) ? null :
                     new PartitionKey(existing.PartitionKey);

            return(await Retry.WithExponentialBackoff(_logger, ct, async() => {
                try {
                    return new DocumentInfo <T>(await this._db.Client.ReplaceDocumentAsync(
                                                    UriFactory.CreateDocumentUri(_db.DatabaseId, Container.Id, existing.Id),
                                                    DocumentCollection.GetItem(existing.Id, newItem, existing.PartitionKey),
                                                    new RequestOptions {
                        AccessCondition = ac, PartitionKey = pk
                    }, ct));
                }
                catch (Exception ex) {
                    FilterException(ex);
                    return null;
                }
            }));
        }
コード例 #9
0
        public PageDescriptionEntity LoadDocumentPage(PostedDataEntity postedData)
        {
            PageDescriptionEntity loadedPage = new PageDescriptionEntity();

            try
            {
                // get/set parameters
                string documentGuid = postedData.guid;
                int    pageNumber   = postedData.page;
                string password     = (string.IsNullOrEmpty(postedData.password)) ? null : postedData.password;

                using (Comparer comparer = new Comparer(documentGuid, GetLoadOptions(password)))
                {
                    IDocumentInfo info = comparer.Source.GetDocumentInfo();

                    string encodedImage = GetPageData(pageNumber - 1, documentGuid, password);
                    loadedPage.SetData(encodedImage);

                    loadedPage.height = info.PagesInfo[pageNumber - 1].Height;
                    loadedPage.width  = info.PagesInfo[pageNumber - 1].Width;
                    loadedPage.number = pageNumber;
                }
            }
            catch (Exception ex)
            {
                throw new FileLoadException("Exception occurred while loading result page", ex);
            }

            return(loadedPage);
        }
コード例 #10
0
            /// <inheritdoc/>
            public Task <IDocumentInfo <T> > ReplaceAsync <T>(IDocumentInfo <T> existing, T value,
                                                              CancellationToken ct, OperationOptions options)
            {
                if (existing == null)
                {
                    throw new ArgumentNullException(nameof(existing));
                }
                var newDoc = new Document <T>(existing.Id, value, existing.PartitionKey);

                lock (_data) {
                    if (_data.TryGetValue(newDoc.Id, out var doc))
                    {
                        if (!string.IsNullOrEmpty(existing.Etag) && doc.Etag != existing.Etag)
                        {
                            return(Task.FromException <IDocumentInfo <T> >(
                                       new ResourceOutOfDateException(existing.Etag)));
                        }
                        _data.Remove(newDoc.Id);
                    }
                    else
                    {
                        return(Task.FromException <IDocumentInfo <T> >(
                                   new ResourceNotFoundException(newDoc.Id)));
                    }
                    AddDocument(newDoc);
                    return(Task.FromResult <IDocumentInfo <T> >(newDoc));
                }
            }
コード例 #11
0
        private static List <PageDataDescriptionEntity> GetAnnotatedPagesForPrint(string password, string documentGuid)
        {
            AnnotatedDocumentEntity description = new AnnotatedDocumentEntity();

            try
            {
                using (FileStream outputStream = File.OpenRead(documentGuid))
                {
                    using (GroupDocs.Annotation.Annotator annotator = new GroupDocs.Annotation.Annotator(outputStream, GetLoadOptions(password)))
                    {
                        IDocumentInfo info         = annotator.Document.GetDocumentInfo();
                        List <string> pagesContent = GetAllPagesContent(annotator, info);

                        for (int i = 0; i < info.PagesInfo.Count; i++)
                        {
                            PageDataDescriptionEntity page = new PageDataDescriptionEntity();

                            if (pagesContent.Count > 0)
                            {
                                page.SetData(pagesContent[i]);
                            }

                            description.pages.Add(page);
                        }
                    }
                }

                return(description.pages);
            }
            catch (FileNotFoundException ex)
            {
                throw ex;
            }
        }
コード例 #12
0
 /// <inheritdoc/>
 public Task DeleteAsync <T>(IDocumentInfo <T> item, CancellationToken ct)
 {
     if (item == null)
     {
         throw new ArgumentNullException(nameof(item));
     }
     return(DeleteAsync(item.Id, ct, item.PartitionKey, item.Etag));
 }
コード例 #13
0
    public DocumentCommandResult TrySaveAsNewDocument(string documentName, out string newDocumentUrl)
    {
        newDocumentUrl = null;
        Item newDocument = new Item()
        {
            Name     = documentName,
            IsFolder = false
        };

        if (!IsDocumentEditingAllowed(newDocument))
        {
            return(DocumentCommandResult.NotSupportedFormat);
        }

        Item document = GetDocumentInCurrentFolder(documentName);

        if (document != null)
        {
            return(DocumentCommandResult.DocumentAlreadyExists);
        }

        newDocument.Owner          = DocumentsApp.User.CurrentUser;
        newDocument.ParentItem     = CurrentDocument.ParentItem;
        newDocument.CreationTime   = DateTime.UtcNow;
        newDocument.LastAccessTime = DateTime.UtcNow;
        newDocument.LastWriteTime  = DateTime.UtcNow;

        byte[]        newDocumentData;
        string        sourceDocIdForEditor = GetDocumentIdForEditor(CurrentDocument);
        IDocumentInfo sourceDocInfo        = DocumentManager.FindDocument(sourceDocIdForEditor);

        if (IsRichEditDocument(CurrentDocument))
        {
            RichEditDocumentInfo richEditDocInfo = sourceDocInfo as RichEditDocumentInfo;
            DevExpress.XtraRichEdit.DocumentFormat richEditFormat = GetRichEditDocumentFormat(newDocument);
            newDocumentData = richEditDocInfo.SaveCopy(richEditFormat);
        }
        else if (IsSpreadsheetDocument(CurrentDocument))
        {
            SpreadsheetDocumentInfo spreadsheetDocInfo = sourceDocInfo as SpreadsheetDocumentInfo;
            DevExpress.Spreadsheet.DocumentFormat spreadsheetFormat = GetSpreadsheetDocumentFormat(newDocument);
            newDocumentData = spreadsheetDocInfo.SaveCopy(spreadsheetFormat);
        }
        else
        {
            throw new Exception("Incorrect document format.");
        }
        newDocument.Content = DataService.CreateBinaryContent(newDocumentData);

        DataService.AddItem(newDocument);
        DataService.SaveChanges();
        string newDocumentPath = GetPathForDocumentInCurrentFolder(documentName);

        newDocumentUrl = GetDocumentEditorRequestUrl(newDocumentPath);
        return(DocumentCommandResult.OK);
    }
        public static void Run()
        {
            using (Merger merger = new Merger(Constants.SAMPLE_VSDX))
            {
                IDocumentInfo info = merger.GetDocumentInfo();
                Console.WriteLine(info);
            }

            Console.WriteLine("Document info retrieved successfully.");
        }
コード例 #15
0
 void OnDocumentAutoSaving(IDocumentInfo documentInfo, DocumentSavingEventArgs e)
 {
     try {
         SaveDocument(documentInfo, false);
     }
     finally {
         e.Handled = true;
         DataService.CloseUnitOfWork();
     }
 }
コード例 #16
0
        private async Task CommitDeleteAsync <TEntity>(TEntity entity, IDocumentInfo docInfo, object id) where TEntity : class
        {
            await _elasticClient.DeleteAsync(DocumentPath <TEntity> .Id(Convert.ToString(id)),
                                             d => d.Index(docInfo.Index)
                                             .Type(docInfo.Type));

            if (docInfo.RefeshAfterDeleted)
            {
                await _elasticClient.RefreshAsync(docInfo.Index);
            }
        }
コード例 #17
0
 /// <inheritdoc/>
 public Task DeleteAsync <T>(IDocumentInfo <T> item, CancellationToken ct,
                             OperationOptions options)
 {
     if (item == null)
     {
         throw new ArgumentNullException(nameof(item));
     }
     options = options ?? new OperationOptions();
     options.PartitionKey = item.PartitionKey;
     return(DeleteAsync(item.Id, ct, options, item.Etag));
 }
コード例 #18
0
        private async Task CommitUpdateAsync <TEntity>(TEntity entity, IDocumentInfo docInfo, object id) where TEntity : class
        {
            await _elasticClient.UpdateAsync(DocumentPath <TEntity> .Id(Convert.ToString(id)), d => d
                                             .Index(docInfo.Index)
                                             .Type(docInfo.Type)
                                             .DocAsUpsert(true)
                                             .Doc(entity));

            if (docInfo.RefeshAfterUpdate)
            {
                await _elasticClient.RefreshAsync(docInfo.Index);
            }
        }
コード例 #19
0
        public object?Create(object?value, ServerTimestampBehavior?serverTimestampBehavior)
        {
            IDocumentInfo documentInfo = _objectDocumentInfo;

            if (value is NSArray)
            {
                documentInfo = _listDocumentInfo ?? ObjectProvider.GetDocumentInfo <List <object> >();
            }
            else if (value is NSDictionary && _type == typeof(object))
            {
                documentInfo = ObjectProvider.GetDocumentInfo <Dictionary <string, object> >();
            }
            return(documentInfo.Create(value, serverTimestampBehavior));
        }
コード例 #20
0
        public static void Run()
        {
            // Create an instance of Parser class
            using (Parser parser = new Parser(Constants.SampleDocx))
            {
                // Get the document info
                IDocumentInfo info = parser.GetDocumentInfo();

                // Print document information
                Console.WriteLine(string.Format("FileType: {0}", info.FileType));
                Console.WriteLine(string.Format("PageCount: {0}", info.PageCount));
                Console.WriteLine(string.Format("Size: {0}", info.Size));
            }
        }
コード例 #21
0
        private object?PlatformCreate(object?value, ServerTimestampBehavior?serverTimestampBehavior)
        {
            IDocumentInfo documentInfo = _objectDocumentInfo;

            if (value is JavaList || value is AbstractList)
            {
                documentInfo = _listDocumentInfo ?? ObjectProvider.GetDocumentInfo <List <object> >();
            }
            else if ((value is JavaDictionary || value is AbstractMap) && _type == typeof(object))
            {
                documentInfo = ObjectProvider.GetDocumentInfo <Dictionary <string, object> >();
            }
            return(documentInfo.Create(value, serverTimestampBehavior));
        }
コード例 #22
0
        public AnnotatedDocumentEntity LoadDocument(AnnotationPostedDataEntity loadDocumentRequest, bool loadAllPages)
        {
            string password = loadDocumentRequest.password;
            AnnotatedDocumentEntity description = new AnnotatedDocumentEntity();
            string documentGuid = loadDocumentRequest.guid;

            using (GroupDocs.Annotation.Annotator annotator = new GroupDocs.Annotation.Annotator(documentGuid, GetLoadOptions(password)))
            {
                IDocumentInfo    info        = annotator.Document.GetDocumentInfo();
                AnnotationBase[] annotations = annotator.Get().ToArray();
                description.guid = loadDocumentRequest.guid;

                string documentType = getDocumentType(info);

                description.supportedAnnotations = new SupportedAnnotations().GetSupportedAnnotations(documentType);

                List <string> pagesContent = new List <string>();

                if (loadAllPages)
                {
                    pagesContent = GetAllPagesContent(annotator, info);
                }

                for (int i = 0; i < info.PagesInfo.Count; i++)
                {
                    PageDataDescriptionEntity page = new PageDataDescriptionEntity
                    {
                        number = i + 1,
                        height = info.PagesInfo[i].Height,
                        width  = info.PagesInfo[i].Width,
                    };

                    if (annotations != null && annotations.Length > 0)
                    {
                        page.SetAnnotations(AnnotationMapper.MapForPage(annotations, i + 1, info.PagesInfo[i], documentType));
                    }

                    if (pagesContent.Count > 0)
                    {
                        page.SetData(pagesContent[i]);
                    }
                    description.pages.Add(page);
                }
            }

            description.guid = documentGuid;
            // return document description
            return(description);
        }
コード例 #23
0
        private string getDocumentType(IDocumentInfo info)
        {
            string documentType = string.Empty;

            if (info.FileType != null)
            {
                documentType = SupportedImageFormats.Contains(info.FileType.Extension) ? "image" : info.FileType.ToString();
            }
            else
            {
                documentType = "Portable Document Format";
            }

            return(documentType);
        }
コード例 #24
0
        public HttpResponseMessage LoadDocumentPage(AnnotationPostedDataEntity loadDocumentPageRequest)
        {
            string password = "";

            try
            {
                // get/set parameters
                string documentGuid = loadDocumentPageRequest.guid;
                int    pageNumber   = loadDocumentPageRequest.page;
                password = loadDocumentPageRequest.password;
                PageDataDescriptionEntity loadedPage = new PageDataDescriptionEntity();

                // get page image
                byte[] bytes;

                using (GroupDocs.Annotation.Annotator annotator = new GroupDocs.Annotation.Annotator(documentGuid, GetLoadOptions(password)))
                {
                    using (var memoryStream = RenderPageToMemoryStream(annotator, pageNumber))
                    {
                        bytes = memoryStream.ToArray();
                    }

                    IDocumentInfo    info         = annotator.Document.GetDocumentInfo();
                    AnnotationBase[] annotations  = annotator.Get().ToArray();
                    string           documentType = getDocumentType(info);

                    if (annotations != null && annotations.Length > 0)
                    {
                        loadedPage.SetAnnotations(AnnotationMapper.MapForPage(annotations, pageNumber, info.PagesInfo[pageNumber - 1], documentType));
                    }

                    string encodedImage = Convert.ToBase64String(bytes);
                    loadedPage.SetData(encodedImage);

                    loadedPage.height = info.PagesInfo[pageNumber - 1].Height;
                    loadedPage.width  = info.PagesInfo[pageNumber - 1].Width;
                    loadedPage.number = pageNumber;
                }

                // return loaded page object
                return(Request.CreateResponse(HttpStatusCode.OK, loadedPage));
            }
            catch (Exception ex)
            {
                // set exception message
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex, password)));
            }
        }
コード例 #25
0
        public DocumentInfo()
        {
            if (_type.IsDictionaryType())
            {
                _objectDocumentInfo = new DictionaryDocumentInfo <T>();
            }
            else
            {
                _objectDocumentInfo = new ObjectDocumentInfo <T>();
            }

            if (_type.IsListType())
            {
                _listDocumentInfo = new ListDocumentInfo <T>();
            }
        }
コード例 #26
0
        static MemoryStream RenderPageToMemoryStream(Comparer comparer, int pageNumberToRender)
        {
            MemoryStream  result       = new MemoryStream();
            IDocumentInfo documentInfo = comparer.Source.GetDocumentInfo();

            PreviewOptions previewOptions = new PreviewOptions(pageNumber => result)
            {
                PreviewFormat = PreviewFormats.PNG,
                PageNumbers   = new[] { pageNumberToRender + 1 },
                Height        = documentInfo.PagesInfo[pageNumberToRender].Height,
                Width         = documentInfo.PagesInfo[pageNumberToRender].Width
            };

            comparer.Source.GeneratePreview(previewOptions);

            return(result);
        }
コード例 #27
0
        public static LoadDocumentEntity LoadDocumentPages(string documentGuid, string password, bool loadAllPages)
        {
            LoadDocumentEntity loadDocumentEntity = new LoadDocumentEntity();

            using (Comparer comparer = new Comparer(documentGuid, GetLoadOptions(password)))
            {
                Dictionary <int, string> pagesContent = new Dictionary <int, string>();
                IDocumentInfo            documentInfo = comparer.Source.GetDocumentInfo();

                if (documentInfo.PagesInfo == null)
                {
                    throw new GroupDocs.Comparison.Common.Exceptions.ComparisonException("File is corrupted.");
                }

                if (loadAllPages)
                {
                    for (int i = 0; i < documentInfo.PageCount; i++)
                    {
                        string encodedImage = GetPageData(i, documentGuid, password);

                        pagesContent.Add(i, encodedImage);
                    }
                }

                for (int i = 0; i < documentInfo.PageCount; i++)
                {
                    PageDescriptionEntity pageData = new PageDescriptionEntity
                    {
                        height = documentInfo.PagesInfo[i].Height,
                        width  = documentInfo.PagesInfo[i].Width,
                        number = i + 1
                    };

                    if (pagesContent.Count > 0)
                    {
                        pageData.SetData(pagesContent[i]);
                    }

                    loadDocumentEntity.SetPages(pageData);
                }

                return(loadDocumentEntity);
            }
        }
        public static void Run()
        {
            // Create an instance of Parser class
            using (Parser parser = new Parser(Constants.HyperlinksPdf))
            {
                // Check if the document supports hyperlink extraction
                if (!parser.Features.Hyperlinks)
                {
                    Console.WriteLine("Document isn't supports hyperlink extraction.");
                    return;
                }

                // Get the document info
                IDocumentInfo documentInfo = parser.GetDocumentInfo();
                // Check if the document has pages
                if (documentInfo.PageCount == 0)
                {
                    Console.WriteLine("Document hasn't pages.");
                    return;
                }

                // Iterate over pages
                for (int pageIndex = 0; pageIndex < documentInfo.PageCount; pageIndex++)
                {
                    // Print a page number
                    Console.WriteLine(string.Format("Page {0}/{1}", pageIndex + 1, documentInfo.PageCount));

                    // Extract hyperlinks from the document page
                    IEnumerable <PageHyperlinkArea> hyperlinks = parser.GetHyperlinks(pageIndex);

                    // Iterate over hyperlinks
                    foreach (PageHyperlinkArea h in hyperlinks)
                    {
                        // Print the hyperlink text
                        Console.WriteLine(h.Text);
                        // Print the hyperlink URL
                        Console.WriteLine(h.Url);

                        Console.WriteLine();
                    }
                }
            }
        }
コード例 #29
0
        private async Task DeleteAsync <TEntity>(TEntity entity, IDocumentInfo docInfo)
        {
            var docInfoEntity = (DocumentInfo <TEntity>)docInfo;

            if (docInfoEntity.DeleteMethod != null)
            {
                await docInfoEntity.DeleteMethod(_elasticClient, entity);
            }
            else
            {
                var    id         = entity.GetType().GetProperty(docInfo.KeyProperty.Name).GetValue(entity, null);
                object entitySave = entity;
                if (docInfo.EntityTarget != null)
                {
                    entitySave = Entity2Target(entity, docInfo.EntityTarget);
                }

                MethodInfo genericMethod = CommitDeleteAsyncMethodInfo.MakeGenericMethod(entitySave.GetType());
                Task       task          = (Task)genericMethod.Invoke(this, new object[] { entitySave, docInfo, id });
                await      task;
            }
        }
コード例 #30
0
 /// <inheritdoc/>
 public async Task <IDocumentInfo <T> > ReplaceAsync <T>(IDocumentInfo <T> existing,
                                                         T newItem, CancellationToken ct, OperationOptions options)
 {
     if (existing == null)
     {
         throw new ArgumentNullException(nameof(existing));
     }
     options = options ?? new OperationOptions();
     options.PartitionKey = existing.PartitionKey;
     return(await Retry.WithExponentialBackoff(_logger, ct, async() => {
         try {
             return new DocumentInfo <T>(await this._db.Client.ReplaceDocumentAsync(
                                             UriFactory.CreateDocumentUri(_db.DatabaseId, Container.Id, existing.Id),
                                             DocumentCollection.GetItem(existing.Id, newItem, options),
                                             options.ToRequestOptions(_partitioned, existing.Etag), ct));
         }
         catch (Exception ex) {
             FilterException(ex);
             return null;
         }
     }));
 }
コード例 #31
0
ファイル: Documents.cs プロジェクト: simonegli8/Silversite
 /// <summary>
 /// Publishes a new document.
 /// </summary>
 /// <param name="doc">The IDocumentInfo for the document, including the document key.</param>
 /// <param name="text">The document's text.</param>
 public static void Publish(IDocumentInfo doc, string text)
 {
     using (var db = new Silversite.Context()) {
         var d = Current(db, doc.ContentKey);
         if (d == null) throw new ArgumentException("invalid key");
         if (d.Text != string.Empty) db.Documents.Add(d.Old());
         d.CopyFrom(doc);
         d.Text = text;
         db.SaveChanges();
     }
 }
コード例 #32
0
ファイル: Documents.cs プロジェクト: simonegli8/Silversite
 /// <summary>
 /// Sets the IDocumentInfo of the corresponding document in the database.
 /// </summary>
 /// <param name="doc">The IDocumentInfo of the document.</param>
 public static void Modify(IDocumentInfo doc)
 {
     using (var db = new Silversite.Context()) {
         var d = Current(db, doc.ContentKey); if (d == null) return;
         d.CopyFrom(doc);
         db.SaveChanges();
     }
 }
コード例 #33
0
ファイル: Documents.cs プロジェクト: simonegli8/Silversite
 /// <summary>
 /// Copies IDocumentInfos.
 /// </summary>
 /// <param name="doc">The IDocumentInfo to copy from.</param>
 public void CopyFrom(IDocumentInfo doc)
 {
     CopyInfo(doc, this);
 }
コード例 #34
0
ファイル: Documents.cs プロジェクト: simonegli8/Silversite
 /// <summary>
 /// Copies DocumentInfo's.
 /// </summary>
 /// <param name="source">The source IDocumentInfo.</param>
 /// <param name="dest">The destination IDocumentInfo.</param>
 public static void CopyInfo(IDocumentInfo source, IDocumentInfo dest)
 {
     dest.Author = source.Author;
     dest.Categories = source.Categories;
     dest.Title = source.Title;
     dest.Notes = source.Notes;
     dest.Published = source.Published;
     dest.ContentKey = source.ContentKey;
     dest.Revision = source.Revision;
     dest.Tags = source.Tags;
 }
コード例 #35
0
ファイル: EditorRights.cs プロジェクト: simonegli8/Silversite
        /// <summary>
        /// True if the the person is allowed to edit the document.
        /// </summary>
        /// <param name="doc">A document.</param>
        /// <param name="p">A person.</param>
        /// <returns>True if the the person is allowed to edit the document.</returns>
        public static bool IsEditable(IDocumentInfo doc, Person p)
        {
            if (doc == null) return true;
            var cats = (doc.Categories ?? string.Empty).SplitList(',', ';').ToList();
            if (cats.Contains("*")) return true;
            if (p == null) return false;
            if (cats.Contains("?")) return true;

            if (p.EditorSettings.EditableDocuments == null) {	// build the editable documents cache for this person.
                var edocs = p.EditorSettings.EditableDocuments = new List<EditRight>();
                using (var db = new Silversite.Context()) {
                    // first find the rights for this user
                    var rights = db.EditRights.Find(p.UserName);
                    if (rights != null) {
                        edocs.AddRange(rights.DocumentCategories.SplitList(s => new EditRight(s), ',',';'));
                    }
                    // and then for the users roles
                    foreach (var role in p.Roles) {
                        rights = db.EditRights.Find(role);
                        if (rights != null) {
                            edocs.AddRange(rights.DocumentCategories.SplitList(s => new EditRight(s), ',',';'));
                        }
                    }
                }
            }

            foreach (var right in p.EditorSettings.EditableDocuments) {
                foreach (var cat in cats) {
                    if (Paths.Match(right.DocumentCategory, cat)) {
                        return right.Permission == Permission.Allowed;
                    }
                }
            }
            return false;
        }
コード例 #36
0
 public ErrorSnapShot(IDocumentInfo docInfo, BrowserType browserType)
 {
     _docInfo = docInfo;
     _browserType = browserType;
 }