Beispiel #1
0
        //ExEnd:SourceDocFilePath

        /// <summary>
        /// Picks the annotations from document.pdf and exports them to sample.pdf
        /// </summary>
        public static void ExportAnnotationInFile()
        {
            try
            {
                //ExStart:ExportAnnotationInFile
                // Create instance of annotator.
                IRepositoryPathFinder pathFinder = new RepositoryPathFinder();
                IAnnotator            annotator  = new Annotator(
                    new UserRepository(pathFinder),
                    new DocumentRepository(pathFinder),
                    new AnnotationRepository(pathFinder),
                    new AnnotationReplyRepository(pathFinder),
                    new AnnotationCollaboratorRepository(pathFinder));


                var documentRepository = new DocumentRepository(pathFinder);

                // Get file stream
                Stream manifestResourceStream     = new FileStream(CommonUtilities.MapSourceFilePath(filePath), FileMode.Open, FileAccess.ReadWrite);
                List <AnnotationInfo> annotations = new List <AnnotationInfo>();

                // Get document
                var document = documentRepository.GetDocument("Document.pdf");

                Stream stream = annotator.ExportAnnotationsToDocument(document.Id, manifestResourceStream, DocumentType.Pdf);

                // Save result stream to file.
                using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.pdf"), FileMode.Create))
                {
                    byte[] buffer = new byte[stream.Length];
                    stream.Seek(0, SeekOrigin.Begin);
                    stream.Read(buffer, 0, buffer.Length);
                    fileStream.Write(buffer, 0, buffer.Length);
                    fileStream.Close();
                }
                //ExEnd:ExportAnnotationInFile
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }
Beispiel #2
0
        //ExEnd:MapDestinationFilePath

        /// <summary>
        /// Saves output document
        /// </summary>
        public static void SaveOutputDocument(Stream inputFile, List <AnnotationInfo> annotations, DocumentType type)
        {
            try
            {
                //ExStart:SaveOutputDocument
                IAnnotator annotator = new Annotator();
                Stream     result    = annotator.ExportAnnotationsToDocument(inputFile, annotations, DocumentType.Pdf);

                // Save result stream to file.
                using (FileStream fileStream = new FileStream(MapDestinationFilePath("Annotated.pdf"), FileMode.Create))
                {
                    byte[] buffer = new byte[result.Length];
                    result.Seek(0, SeekOrigin.Begin);
                    result.Read(buffer, 0, buffer.Length);
                    fileStream.Write(buffer, 0, buffer.Length);
                    fileStream.Close();
                }
                //ExEnd:SaveOutputDocument
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }