private static void rd_redactField(Document doc, string variant, Field f, string color) { if (f.State == DataState.Empty) { return; } if (f.Zone.Height == 0 && f.Zone.Width == 0) { return; } // We need to locate the sources at the document, // only they contain the variants as well as the rotation foreach (ImageSource ims in doc.Sources) { if (ims.Url != f.Sources[0].Url) { continue; // find page } if (pageMap.ContainsKey(f.Sources[0].Id)) { break; // page already loaded } pageMap[f.Sources[0].Id] = rd_createPage(ims.SelectInstance(variant)); } // Redact the zone OCCSinglePage sp = pageMap[f.Sources[0].Id].Bitmap; sp.FillRectangle(new SolidBrush(rd_GetColor(color)), f.Zone); }
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()); }
public void RotatedImage() { Color col = ScriptingUtilities.rd_GetColor("Pink"); string img = Path.Combine(sampleDocumentDir, "Rotate.tif"); OCCSinglePage sp = new OCCSinglePage(img, 270); sp.FillRectangle(new SolidBrush(col), new Rectangle(50, 50, 100, 40)); sp.FillRectangle(new SolidBrush(col), new Rectangle(1000, 1000, 500, 200)); sp.Save(img + ".tif"); }
public void Watermark_1() { string wmPage1Bw = Path.Combine(sampleDocumentDir, "TestDocument_Imaging-P1-BW.tif"); string wmPage1Color = Path.Combine(sampleDocumentDir, "TestDocument_Imaging-P1-Color.tif"); string wmPag2Bw = Path.Combine(sampleDocumentDir, "TestDocument_Imaging-P2-BW.tif"); string wmPage2Color = Path.Combine(sampleDocumentDir, "TestDocument_Imaging-P2-Color.tif"); OCCSinglePage sp; sp = new OCCSinglePage(wmPage1Bw); sp.AddTextToImage("Hello World", 0, 0, 0, 0, 0); sp.Save(@"c:\temp\P1Bw.tif"); }
private static void im_doImprint( SourceInstance si, int imageOrientation, string text, int orientation, int position, int offsetX, int offsetY) { string cacheFolder = DataPool.CacheFolder; string cacheFile = Path.Combine(cacheFolder, "su_" + Path.GetFileName(si.Url)); File.Copy(si.Url, cacheFile); si.Url = cacheFile; si.IsArchived = false; OCCSinglePage sp = new OCCSinglePage(si.Url, imageOrientation); sp.AddTextToImage(text, 0, orientation, position, offsetX, offsetX); sp.Save(si.Url); }