コード例 #1
0
        public static void CutImage(DataPool pool, Field sourceField, Document targetDocument)
        {
            if (sourceField.State == DataState.Empty)
            {
                return;
            }
            if (sourceField.Zone.Height == 0 && sourceField.Zone.Width == 0)
            {
                return;
            }
            OCCSinglePage pageRef = null;
            OCCSinglePage pageOcr = null;

            foreach (ImageSource ims in sourceField.ParentDocument.Sources)
            {
                if (ims.Url != sourceField.Sources[0].Url)
                {
                    continue;
                }
                pageRef = new OCCSinglePage(ims.SelectInstance("ref").Url,
                                            (ims.SelectInstance("ref") as ImageVariantInstance).Orientation);
                pageOcr = new OCCSinglePage(ims.SelectInstance("ocr").Url,
                                            (ims.SelectInstance("ocr") as ImageVariantInstance).Orientation);
            }

            byte[] tmpImageRef = pageRef.GetSnippet(sourceField.Zone);
            byte[] tmpImageOcr = pageOcr.GetSnippet(sourceField.Zone);
            string name        = sourceField.Name;
            string extension   = "tif";
            string cacheFolder = DataPool.CacheFolder;

            // Save image twice
            // 1) als original
            string destFileName = Path.Combine(cacheFolder, String.Format("{0}.{1}", name, extension));

            File.WriteAllBytes(destFileName, tmpImageRef);
            string destFileNameRef = Path.Combine(cacheFolder, String.Format("{0}_REF.{1}", name, extension));

            File.WriteAllBytes(destFileNameRef, tmpImageRef);
            // 2) als default ("ocr") to bring it into the PDF
            string destFileNameOcr = Path.Combine(cacheFolder, String.Format("{0}_OCR.{1}", name, extension));

            File.WriteAllBytes(destFileNameOcr, tmpImageOcr);

            ImageSourceInstance instance = new ImageSourceInstance(targetDocument.OwnerDataPool, destFileName);

            targetDocument.OwnerDataPool.RootNode.SourceInstances.Add(instance);
            PageInstance         pageInstance = instance.CreatePageInstance(1);
            ImageVariantInstance variantRef   = new ImageVariantInstance(targetDocument.OwnerDataPool, destFileNameRef);

            variantRef.VariantName = "ref";
            pageInstance.Variants.Add(variantRef);
            ImageVariantInstance varianOcr = new ImageVariantInstance(targetDocument.OwnerDataPool, destFileNameOcr);

            varianOcr.VariantName = "ocr";
            pageInstance.Variants.Add(varianOcr);
            targetDocument.Sources.Add(pageInstance.GetSource());
        }
コード例 #2
0
        public void ExifExtraction()
        {
            string image = @"C:\01_Work\01_OCC\dev\OCC_Head\occ_b\Samples\ScriptingUtilities\SampleDocuments\ExifData.JPG";
            //string image = @"C:\01_Work\01_OCC\dev\OCC_Head\occ_b\Samples\ScriptingUtilities\SampleDocuments\BlankPage.docx";

            IImageMetadataExtraction extractor = ImageMetadataExtraction_Manager.GetExtractor();
            var x1 = extractor.Extract(image);

            string   repository   = @"\\JSCHACHTGXY3JC2\DOKuStarDispatchData\Repositories\Standard\ImagData.jc28.0000";
            string   dataPoolFile = Path.Combine(repository, "35401_o86406_wj5_Rec.data");
            DataPool data         = new DataPool();

            data.Load(dataPoolFile);

            Document            doc       = data.RootNode.Documents[0];
            Source              source    = doc.Sources[0];
            ImageSourceInstance isi       = (ImageSourceInstance)source.Instance.ParentInstance;
            string              inputFile = isi.Url;

            x1 = extractor.Extract(inputFile);

            string x2 = ScriptingUtilities.GetImageMetaData(doc, "Exif SubIFD", "Exposure Time");
        }
コード例 #3
0
        public static string GetImageMetaData(Document doc, string group, string tag)
        {
            ImageSourceInstance isi = (ImageSourceInstance)doc.Sources[0].Instance.ParentInstance;
            string inputFile        = isi.Url;

            IImageMetadataExtraction extractor = ImageMetadataExtraction_Manager.GetExtractor();

            try
            {
                Dictionary <string, string> tags = extractor.Extract(inputFile, group);
                trace.WriteInfo("tags.Count=" + tags.Count);
                if (tags.ContainsKey(tag))
                {
                    return(tags[tag]);
                }
                return(string.Empty);
            }
            catch (Exception e)
            {
                trace.WriteError("extractor.Extract(" + inputFile + ", " + group + ") failed: " + e.Message);
                return(string.Empty);
            }
        }