Beispiel #1
0
        public byte[] GetImageBytes()
        {
            using (var stream = new MemoryStream())
            {
                codec.Save(ImageData, stream, RasterImageFormat.CcittGroup4, 0, 1,
                           TotalPages, 1, CodecsSavePageMode.Overwrite);

                foreach (var entry in tagsByPageNumber)
                {
                    codec.WriteTag(stream, entry.Key, entry.Value);
                }

                return(stream.GetBuffer());
            }
        }
Beispiel #2
0
        public static void MergeFiles(string mainFile, string appendFile, bool annotation)
        {
            if (MergeFilesByCopy(mainFile, appendFile))
            {
                return;
            }


            RasterCodecs codec = new RasterCodecs();
            RasterImage  image = null;

            RasterTagMetadata[] tagsData = null;  // stores the annotatin
            RasterImage         image2   = null;

            try
            {
                // load the image and annotation information for the
                // append file.
                image = codec.Load(appendFile);
                int pageCount = image.PageCount;
                if (annotation)
                {
                    tagsData = new RasterTagMetadata[pageCount];
                    for (int i = 0; i < pageCount; ++i)
                    {
                        tagsData[i] = codec.ReadTag(appendFile, i + 1, RasterTagMetadata.AnnotationTiff);
                    }
                }
                StatusForm statusForm = new StatusForm();
                statusForm.LoadFormData(appendFile, mainFile, pageCount);
                statusForm.Show();
                statusForm.Refresh();
                image2 = codec.Load(mainFile);
                int mainPageNumber = image2.PageCount;
                for (int i = 0; i < pageCount; ++i)
                {
                    codec.Save(image, mainFile, RasterImageFormat.CcittGroup4, 1, i + 1, i + 1, 1, CodecsSavePageMode.Append);
                    if (annotation)
                    {
                        if ((tagsData != null) && (tagsData[i] != null))
                        {
                            codec.WriteTag(mainFile, mainPageNumber + i + 1, tagsData[i]);
                        }
                    }
                    statusForm.ShowPageInfo(i);
                }
                statusForm.Close();
            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                }
                if (image2 != null)
                {
                    image2.Dispose();
                }
            }
        }
Beispiel #3
0
        private static void DoExtraction(string srcFileName, string destFileName, int[] pageNumList, bool annotation)
        {
            RasterCodecs codec = new RasterCodecs();
            RasterImage image = null;
            RasterTagMetadata[] tagsData = null;

            try
            {
                image = codec.Load(srcFileName);
                int pageCount = image.PageCount;
                if (annotation)
                {
                    tagsData = new RasterTagMetadata[pageCount];
                    for (int i = 0; i < pageCount; ++i)
                    {
                        tagsData[i] = codec.ReadTag(srcFileName, i + 1, RasterTagMetadata.AnnotationTiff);
                    }
                }
                int listCount = pageNumList.Length;
                if (File.Exists(destFileName))
                {
                    File.Delete(destFileName);
                }
                StatusForm statusForm = new StatusForm();
                statusForm.LoadFormData(srcFileName, destFileName, listCount);
                statusForm.Show();
                statusForm.Refresh();
                for (int i = 0; i < listCount; ++i)
                {
                    codec.Save(image, destFileName, RasterImageFormat.CcittGroup4, 1, pageNumList[i], pageNumList[i], i, CodecsSavePageMode.Append);
                    if (annotation)
                    {
                        if ((tagsData != null) && (tagsData[pageNumList[i] - 1] != null))
                        {
                            codec.WriteTag(destFileName, i + 1, tagsData[pageNumList[i]-1]);
                        }
                    }
                    statusForm.ShowPageInfo(pageNumList[i]);
                }

                if (image.PageCount > listCount)
                {
                    int deleteCount = 0;
                    for (int i = 1; i <= pageCount; ++i)
                    {
                        if (PageNumberFound(i, pageNumList))
                        {
                            image.RemovePageAt(i+deleteCount);
                            deleteCount--;
                        }
                    }
                    codec.Save(image, srcFileName, RasterImageFormat.CcittGroup4, 1, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);
                    if (annotation)
                    {
                        int newPageIndex = 0;
                        for (int i = 0; i < pageCount; ++i)
                        {
                            if (!PageNumberFound(i+1, pageNumList) && (tagsData != null) && (tagsData[i] != null))
                            {
                               codec.WriteTag(srcFileName, ++newPageIndex, tagsData[i]);
                            }
                        }
                    }
                    
                }
                else
                {
                    File.Delete(srcFileName);
                }
                statusForm.Close();

            }
            finally
            {
                if (image != null) {
                    image.Dispose();
                }
            }

        }
Beispiel #4
0
        public static void MergeFiles(string mainFile, string appendFile, bool annotation)
        {


            if (MergeFilesByCopy(mainFile, appendFile))
            {
                return;
            }
            

            RasterCodecs codec = new RasterCodecs();
            RasterImage image = null;
            RasterTagMetadata[] tagsData = null;  // stores the annotatin
            RasterImage image2 = null;
            try
            {
                // load the image and annotation information for the 
                // append file.
                image = codec.Load(appendFile);
                int pageCount = image.PageCount;
                if (annotation)
                {
                    tagsData = new RasterTagMetadata[pageCount];
                    for (int i = 0; i < pageCount; ++i)
                    {
                        tagsData[i] = codec.ReadTag(appendFile, i + 1, RasterTagMetadata.AnnotationTiff);
                    }
                }
                StatusForm statusForm = new StatusForm();
                statusForm.LoadFormData(appendFile, mainFile, pageCount);
                statusForm.Show();
                statusForm.Refresh();
                image2 = codec.Load(mainFile);
                int mainPageNumber = image2.PageCount;
                for (int i = 0; i < pageCount; ++i)
                {
                    codec.Save(image, mainFile, RasterImageFormat.CcittGroup4, 1,  i + 1, i + 1, 1, CodecsSavePageMode.Append);
                    if (annotation)
                    {
                        if ((tagsData != null) && (tagsData[i] != null))
                        {
                            codec.WriteTag(mainFile, mainPageNumber + i + 1, tagsData[i]);
                        }
                    }
                    statusForm.ShowPageInfo(i);
                }
                statusForm.Close();

            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                }
                if (image2 != null)
                {
                    image2.Dispose();
                }
            }


        }
Beispiel #5
0
        private static void DoExtraction(string srcFileName, string destFileName, int[] pageNumList, bool annotation)
        {
            RasterCodecs codec = new RasterCodecs();
            RasterImage  image = null;

            RasterTagMetadata[] tagsData = null;

            try
            {
                image = codec.Load(srcFileName);
                int pageCount = image.PageCount;
                if (annotation)
                {
                    tagsData = new RasterTagMetadata[pageCount];
                    for (int i = 0; i < pageCount; ++i)
                    {
                        tagsData[i] = codec.ReadTag(srcFileName, i + 1, RasterTagMetadata.AnnotationTiff);
                    }
                }
                int listCount = pageNumList.Length;
                if (File.Exists(destFileName))
                {
                    File.Delete(destFileName);
                }
                StatusForm statusForm = new StatusForm();
                statusForm.LoadFormData(srcFileName, destFileName, listCount);
                statusForm.Show();
                statusForm.Refresh();
                for (int i = 0; i < listCount; ++i)
                {
                    codec.Save(image, destFileName, RasterImageFormat.CcittGroup4, 1, pageNumList[i], pageNumList[i], i, CodecsSavePageMode.Append);
                    if (annotation)
                    {
                        if ((tagsData != null) && (tagsData[pageNumList[i] - 1] != null))
                        {
                            codec.WriteTag(destFileName, i + 1, tagsData[pageNumList[i] - 1]);
                        }
                    }
                    statusForm.ShowPageInfo(pageNumList[i]);
                }

                if (image.PageCount > listCount)
                {
                    int deleteCount = 0;
                    for (int i = 1; i <= pageCount; ++i)
                    {
                        if (PageNumberFound(i, pageNumList))
                        {
                            image.RemovePageAt(i + deleteCount);
                            deleteCount--;
                        }
                    }
                    codec.Save(image, srcFileName, RasterImageFormat.CcittGroup4, 1, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);
                    if (annotation)
                    {
                        int newPageIndex = 0;
                        for (int i = 0; i < pageCount; ++i)
                        {
                            if (!PageNumberFound(i + 1, pageNumList) && (tagsData != null) && (tagsData[i] != null))
                            {
                                codec.WriteTag(srcFileName, ++newPageIndex, tagsData[i]);
                            }
                        }
                    }
                }
                else
                {
                    File.Delete(srcFileName);
                }
                statusForm.Close();
            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                }
            }
        }