/// <summary> /// Adds watermark with rotation angle /// <param name="RotationAngle">Rotation angle</param> /// </summary> public static void AddTextWatermark(int RotationAngle) { try { //ExStart:AddTextWatermarkWithRotationAngle using (Document doc = Document.Load(Utilities.MapSourceFilePath(DOC_FILE_PATH))) { Font font = new Font("Calibri", 8); TextWatermark watermark = new TextWatermark("Test watermark", font); watermark.HorizontalAlignment = HorizontalAlignment.Right; watermark.VerticalAlignment = VerticalAlignment.Top; watermark.SizingType = SizingType.ScaleToParentDimensions; watermark.ScaleFactor = 0.5; // Set rotation angle watermark.RotateAngle = 45; doc.AddWatermark(watermark); doc.Save(); } //ExEnd:AddTextWatermarkWithRotationAngle } catch (Exception exp) { Console.Write(exp.Message); } }
private static void ApplyWatermark() { DirectoryInfo dir = new DirectoryInfo(@"../../Documents/"); FileInfo[] files = dir.GetFiles(); // Iterate through the files foreach (FileInfo file in files) { // Load document using (Document doc = Document.Load(file.FullName)) { // Initialize the font to be used for watermark Font font = new Font("Calibre", 50, FontStyle.Bold | FontStyle.Italic); // Create watermark TextWatermark watermark = new TextWatermark("Protected", font); // Set watermark properties watermark.ForegroundColor = Color.Red; watermark.TextAlignment = TextAlignment.Right; watermark.Opacity = 0.5; watermark.HorizontalAlignment = HorizontalAlignment.Center; watermark.VerticalAlignment = VerticalAlignment.Center; watermark.RotateAngle = -45; // Apply watermark doc.AddWatermark(watermark); // Save document doc.Save(Path.Combine("../../Output", file.Name)); Console.WriteLine("Processed: " + file.Name); } } Console.WriteLine("Documents have been saved to output directory..."); }
//ExEnd:SourceDocumentFilesPath #region Adding Watermark /// <summary> /// Adds text watermark to a supported document /// </summary> public static void AddTextWatermark() { try { //ExStart:AddTextWatermark using (Document doc = Document.Load(Utilities.MapSourceFilePath(PNG_FILE_PATH))) { // Initialize the font to be used for watermark Font font = new Font("Arial", 19, FontStyle.Bold | FontStyle.Italic); TextWatermark watermark = new TextWatermark("Test watermark", font); // Set watermark properties watermark.ForegroundColor = Color.Red; watermark.BackgroundColor = Color.Blue; watermark.TextAlignment = TextAlignment.Right; watermark.Opacity = 0.5; doc.AddWatermark(watermark); doc.Save(); } //ExEnd:AddTextWatermark } catch (Exception exp) { Console.Write(exp.Message); } }
public void TestSeveralTextWatermaks() { m_doc = new Document(); m_doc.Pages.Add(new Page(PaperFormat.A4)); m_doc.Pages.Add(new Page(PaperFormat.A4)); m_doc.Pages.Add(new Page(PaperFormat.A4)); TextWatermark watermark1 = new TextWatermark("Sample test watermark 1"); watermark1.Angle = 45; watermark1.Left = 250; watermark1.Top = 250; watermark1.Font.Size = 15; TextWatermark watermark2 = new TextWatermark("Sample test watermark 2"); watermark2.Left = 00; watermark2.Top = 500; watermark2.Font.Size = 10; TextWatermark watermark3 = new TextWatermark("Sample test watermark 3"); watermark3.Angle = 45; watermark3.Left = 650; watermark3.Top = 150; watermark3.Font.Size = 25; m_doc.Pages[0].Watermarks.Add(watermark1); m_doc.Pages[1].Watermarks.Add(watermark2); m_doc.Pages[2].Watermarks.Add(watermark3); m_doc.Save(OutputFolder + @"\TestSeveralTextWatermaks.pdf"); //Process.Start("TestSeveralTextWatermaks.pdf"); }
/// <summary> /// Adds watermark with a particular size type /// </summary> public static void AddWatermarkWithSizeType() { try { //ExStart:AddWatermarkWithSizeType using (Document doc = Document.Load(Utilities.MapSourceFilePath(PNG_FILE_PATH))) { Font font = new Font("Calibri", 12); TextWatermark watermark = new TextWatermark("This is a test watermark", font); // Set sizing type watermark.SizingType = SizingType.ScaleToParentDimensions; // Set watermark scale watermark.ScaleFactor = 0.5; doc.AddWatermark(watermark); doc.Save(); } //ExEnd:AddWatermarkWithSizeType } catch (Exception exp) { Console.Write(exp.Message); } }
/// <summary> /// Adds watermark according to the parent margins /// </summary> public static void AddWatermarkWithParentMargin() { try { //ExStart:AddWatermarkWithParentMargin using (Document doc = Document.Load(Utilities.MapSourceFilePath(DOC_FILE_PATH))) { var watermark = new TextWatermark("Test watermark", new Font("Arial", 42)); watermark.HorizontalAlignment = HorizontalAlignment.Right; watermark.VerticalAlignment = VerticalAlignment.Top; watermark.SizingType = SizingType.ScaleToParentDimensions; watermark.ScaleFactor = 1; watermark.RotateAngle = 45; watermark.ForegroundColor = Color.Red; watermark.BackgroundColor = Color.Aqua; // Add watermark considering parent margins watermark.ConsiderParentMargins = true; doc.AddWatermark(watermark); doc.Save(); } //ExEnd:AddWatermarkWithParentMargin } catch (Exception exp) { Console.Write(exp.Message); } }
/// <summary> /// Adds watermark with a particular margin type /// </summary> public static void AddWatermarkWithMarginType() { try { //ExStart:AddWatermarkWithMarginType using (Document doc = Document.Load(Utilities.MapSourceFilePath(XLS_FILE_PATH))) { Font font = new Font("Calibri", 12); TextWatermark watermark = new TextWatermark("Test watermark", font); watermark.HorizontalAlignment = HorizontalAlignment.Right; watermark.VerticalAlignment = VerticalAlignment.Bottom; // Set relative margins. Margin value will be interpreted as a portion of appropriate parent dimension. // If this type is chosen, margin value must be between 0.0 and 1.0. watermark.Margins.MarginType = MarginType.RelativeToParentDimensions; watermark.Margins.Right = 0.1; watermark.Margins.Bottom = 0.2; doc.AddWatermark(watermark); doc.Save(); } //ExEnd:AddWatermarkWithMarginType } catch (Exception exp) { Console.Write(exp.Message); } }
/// <summary> /// Adds watermark to relative position /// </summary> public static void AddWatermarkToRelativePosition() { try { //ExStart:AddWatermarkToRelativePosition using (Document doc = Document.Load(Utilities.MapSourceFilePath(XLS_FILE_PATH))) { Font font = new Font("Calibri", 12); TextWatermark watermark = new TextWatermark("Test watermark", font); watermark.HorizontalAlignment = HorizontalAlignment.Right; watermark.VerticalAlignment = VerticalAlignment.Bottom; // Set absolute margins. Values are measured in document units. watermark.Margins.Right = 10; watermark.Margins.Bottom = 5; doc.AddWatermark(watermark); doc.Save(); } //ExEnd:AddWatermarkToRelativePosition } catch (Exception exp) { Console.Write(exp.Message); } }
/// <summary> /// Adds watermark to an absolute position /// </summary> public static void AddWatermarkToAbsolutePosition() { try { //ExStart:AddWatermarkToAbsolutePosition using (Document doc = Document.Load(Utilities.MapSourceFilePath(DOC_FILE_PATH))) { Font font = new Font("Times New Roman", 8); TextWatermark watermark = new TextWatermark("Test watermark", font); // Set watermark coordinates watermark.X = 10; watermark.Y = 20; // Set watermark size watermark.Width = 100; watermark.Height = 40; doc.AddWatermark(watermark); doc.Save(); } //ExEnd:AddWatermarkToAbsolutePosition } catch (Exception exp) { Console.Write(exp.Message); } }
static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // If you wish to load an existing document uncomment the line below and comment the Add page section instead // pdfDocument.Load(@".\existing_document.pdf"); // Add pages pdfDocument.Pages.Add(new Page(PaperFormat.A4)); pdfDocument.Pages.Add(new Page(PaperFormat.A4)); pdfDocument.Pages.Add(new Page(PaperFormat.A4)); // Add tiling watermark TextWatermark watermark1 = new TextWatermark("Tiling Watermark"); watermark1.WatermarkLocation = TextWatermarkLocation.Tiled; watermark1.Angle = 30; SolidBrush brush1 = new SolidBrush(new ColorRGB(0, 0, 255)); brush1.Opacity = 50; // make the brush semitransparent watermark1.Brush = brush1; pdfDocument.Watermarks.Add(watermark1); // Add autosized watermark to every page of the document TextWatermark watermark2 = new TextWatermark("Diagonal Watermark"); watermark2.WatermarkLocation = TextWatermarkLocation.DiagonalFromBottomLeftToTopRight; watermark2.Font = new Font("Times New Roman", 16); SolidBrush brush2 = new SolidBrush(new ColorRGB(255, 0, 0)); brush2.Opacity = 50; // make the brush semitransparent watermark2.Brush = brush2; watermark2.Pen = new SolidPen(new ColorRGB(255, 0, 0)); // outline pen is optional pdfDocument.Watermarks.Add(watermark2); // Add watermark of custom size and location to the first page only TextWatermark watermark3 = new TextWatermark("Simple Watermark"); watermark3.Font = new Font(StandardFonts.HelveticaBold, 24); watermark3.Brush = new SolidBrush(new ColorRGB(0, 128, 0)); watermark3.Left = 350; watermark3.Top = 800; pdfDocument.Pages[0].Watermarks.Add(watermark3); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); }
private void InsertTextWatermark(Section section) { TextWatermark txtWatermark = new TextWatermark(); txtWatermark.Text = "E-iceblue"; txtWatermark.FontSize = 95; txtWatermark.Color = Color.Blue; txtWatermark.Layout = WatermarkLayout.Diagonal; section.Document.Watermark = txtWatermark; }
private void btn_Impose_Click(object sender, RoutedEventArgs e) { TextWatermark txtWatermark = new TextWatermark(); txtWatermark.Text = txb_Watermark.Text; txtWatermark.FontSize = 90; txtWatermark.Layout = WatermarkLayout.Diagonal; document = new Document(document_address); document.Watermark = txtWatermark; MessageBox.Show("Водяной узнак успешно наложен"); }
static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add pages pdfDocument.Pages.Add(new Page(PaperFormat.A4)); pdfDocument.Pages.Add(new Page(PaperFormat.A4)); pdfDocument.Pages.Add(new Page(PaperFormat.A4)); // Add tiling watermark TextWatermark watermark1 = new TextWatermark("Tiling Watermark"); watermark1.WatermarkLocation = TextWatermarkLocation.Tiled; watermark1.Angle = 30; SolidBrush brush1 = new SolidBrush(new ColorRGB(0, 0, 255)); brush1.Opacity = 50; // make the brush semitransparent watermark1.Brush = brush1; pdfDocument.Watermarks.Add(watermark1); // Add autosized watermark to every page of the document TextWatermark watermark2 = new TextWatermark("Diagonal Watermark"); watermark2.WatermarkLocation = TextWatermarkLocation.DiagonalFromBottomLeftToTopRight; watermark2.Font = new Font("Times New Roman", 16); SolidBrush brush2 = new SolidBrush(new ColorRGB(255, 0, 0)); brush2.Opacity = 50; // make the brush semitransparent watermark2.Brush = brush2; watermark2.Pen = new SolidPen(new ColorRGB(255, 0, 0)); // outline pen is optional pdfDocument.Watermarks.Add(watermark2); // Add watermark of custom size and location to the first page only TextWatermark watermark3 = new TextWatermark("Simple Watermark"); watermark3.Font = new Font(StandardFonts.HelveticaBold, 24); watermark3.Brush = new SolidBrush(new ColorRGB(0, 128, 0)); watermark3.Left = 350; watermark3.Top = 800; pdfDocument.Pages[0].Watermarks.Add(watermark3); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open document in default PDF viewer app Process.Start("result.pdf"); }
public void TestTextWatermark() { TextWatermark mark = new TextWatermark("This is a test"); Watermarker.EmbedWatermark(file, mark, "password", "results/TextMark.png"); PNGFile file2 = new PNGFile("results/TextMark.png"); TextWatermark extract = Watermarker.ExtractWatermark <TextWatermark>(file2, "password"); Expect(extract.Text, Is.EqualTo("This is a test")); }
internal ShapeObject method_5(TextWatermark A_0) { int num = 6; if (A_0 == null) { return(null); } ShapeObject obj2 = new ShapeObject(A_0.Document, ShapeType.TextPlainText); if (A_0.Semitransparent) { obj2.SetShapeAttribute(0x182, 0x8000); } obj2.SetShapeAttribute(0xc0, A_0.Text); obj2.SetShapeAttribute(0xc5, A_0.FontName); obj2.SetShapeAttribute(0xc3, ((int)A_0.FontSize) * 0x10000); if (A_0.Color != Color.Empty) { obj2.SetShapeAttribute(0x181, A_0.Color); } if (A_0.ShapeWidthInPixels != -1) { obj2.Width = ((float)A_0.ShapeWidthInPixels) / 20f; } else { obj2.Width = A_0.ShapeSize.Width * 0.6934f; } if (A_0.ShapeHeightInPixels != -1) { obj2.Height = ((float)A_0.ShapeHeightInPixels) / 20f; } else { obj2.Height = A_0.ShapeSize.Height * 0.67f; } if (A_0.Layout == WatermarkLayout.Diagonal) { obj2.SetShapeAttribute(4, 0x13b0000); } int num2 = this.method_9(); obj2.Id = num2; obj2.SetShapeAttribute(0xf1, true); obj2.SetShapeAttribute(0xf5, true); obj2.SetShapeAttribute(0x1fc, false); obj2.Name = BookmarkStart.b("簫䄭䜯圱䘳昵吷伹伻椽ℿ㙁⅃㑅Շ⭉㹋╍け㹓㍕㭗⹙", num) + num2.ToString(); obj2.TextWrappingStyle = TextWrappingStyle.InFrontOfText; obj2.SetShapeAttribute(0x3ba, true); return(obj2); }
public void Almosana() { TextWatermark tw1 = new TextWatermark(); tw1.Color = System.Drawing.Color.LightGray; tw1.Font.Bold = true; tw1.Font.Italic = false; tw1.Font.Name = "B Titr"; tw1.Font.Size = Telerik.Reporting.Drawing.Unit.Point(100D); tw1.Orientation = Telerik.Reporting.Drawing.WatermarkOrientation.Diagonal; tw1.Text = "المثنی"; this.PageSettings.Watermarks.Add(tw1); }
private void InsertWatermark(Section section) { Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph(); paragraph.AppendText("The sample demonstrates how to insert a watermark into a document."); paragraph.ApplyStyle(BuiltinStyle.Heading2); TextWatermark txtWatermark = new TextWatermark(); txtWatermark.Text = "Watermark Demo"; txtWatermark.FontSize = 90; txtWatermark.Layout = WatermarkLayout.Diagonal; section.Document.Watermark = txtWatermark; }
/// <summary> /// Adds watermark to the images inside a document /// </summary> public static void AddWatermarkToImages() { try { //ExStart:AddWatermarkToImages using (Document doc = Document.Load(Utilities.MapSourceFilePath(PPT_FILE_PATH))) { // Initialize text watermark TextWatermark textWatermark = new TextWatermark("Protected image", new Font("Arial", 8)); textWatermark.HorizontalAlignment = HorizontalAlignment.Center; textWatermark.VerticalAlignment = VerticalAlignment.Center; textWatermark.RotateAngle = 45; textWatermark.SizingType = SizingType.ScaleToParentDimensions; textWatermark.ScaleFactor = 1; // Initialize image watermark using (ImageWatermark imageWatermark = new ImageWatermark(@"D:\protect.jpg")) { imageWatermark.HorizontalAlignment = HorizontalAlignment.Center; imageWatermark.VerticalAlignment = VerticalAlignment.Center; imageWatermark.RotateAngle = -45; imageWatermark.SizingType = SizingType.ScaleToParentDimensions; imageWatermark.ScaleFactor = 1; // Find all images in a document WatermarkableImageCollection images = doc.FindImages(); for (int i = 0; i < images.Count; i++) { if (images[i].Width > 100 && images[i].Height > 100) { if (i % 2 == 0) { images[i].AddWatermark(textWatermark); } else { images[i].AddWatermark(imageWatermark); } } } } doc.Save(); } //ExEnd:AddWatermarkToImages } catch (Exception exp) { Console.Write(exp.Message); } }
protected override void LoadImageProcessingActions(ImageProcessingActionLoadArgs args) { // Filter #1 args.LoadImageProcessingActions(new FixedCropConstraint(300, 200)); // Filter #2 TextWatermark watermark = new TextWatermark(this.Text, ContentAlignment.TopCenter); watermark.Font.Size = 12; watermark.ForeColor = Color.Black; args.LoadImageProcessingActions(watermark); // Filter #3 args.LoadImageProcessingActions(DefaultColorFilters.Sepia); }
private void InsertWatermark(Document document) { Paragraph paragraph = document.AddSection().AddParagraph(); paragraph.AppendText("The sample demonstrates how to insert a watermark into a document."); paragraph.ApplyStyle(BuiltinStyle.Heading2); TextWatermark txtWatermark = new TextWatermark(); txtWatermark.Text = "Watermark Demo"; txtWatermark.FontSize = 90; txtWatermark.Layout = WatermarkLayout.Diagonal; document.Watermark = txtWatermark; }
protected override void LoadImageProcessingActions(ImageProcessingActionLoadArgs args) { // Filter #1 args.LoadImageProcessingActions(new FixedCropConstraint(300, 200)); // Filter #2 TextWatermark watermark = new TextWatermark(this.Text, ContentAlignment.TopCenter); watermark.Font.Size = 12; watermark.ForeColor = Color.Black; args.LoadImageProcessingActions(watermark); // Filter #3 args.LoadImageProcessingActions(DefaultColorFilters.Sepia); }
private void InsertTextWatermark(Section section) { Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph(); paragraph.AppendText("The sample demonstrates how to insert text watermark into a document."); paragraph.ApplyStyle(BuiltinStyle.Heading2); TextWatermark txtWatermark = new TextWatermark(); txtWatermark.Text = "Watermark Demo"; txtWatermark.FontSize = 90; txtWatermark.Color = Color.Red; txtWatermark.Layout = WatermarkLayout.Diagonal; section.Document.Watermark = txtWatermark; }
public void TestScrambling() { TextWatermark mark = new TextWatermark("This is a test"); Watermarker.EmbedWatermark(file, mark, "password", "results/Scrambling.png"); PNGFile file2 = new PNGFile("results/TextMark.png"); TextWatermark extracted = Watermarker.ExtractWatermark <TextWatermark>(file2, "password"); extracted = Watermarker.ExtractWatermark <TextWatermark>(file2, "foobar"); Expect(extracted, Is.Null); }
protected void ProcessImage() { // Setup the source file name and the output file name string sourceImageFileName = this.imgSource.ImageUrl; string outputImageFileName = "~/repository/output/Ex_A_101.jpg"; switch (this.ddlFilter.SelectedIndex) { case 0: // Fixed Size Crop Constraint int cropWidth = 160; int cropHeight = 350; new FixedCropConstraint(cropWidth, cropHeight).SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); break; case 1: // Scaled Resize Constraint int maxWidth = 160; int maxHeight = 350; new ScaledResizeConstraint(maxWidth, maxHeight).SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); break; case 2: // Grayscale Color Filter DefaultColorFilters.Grayscale.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); break; case 3: // Text Watermark TextWatermark watermark = new TextWatermark(); watermark.Text = DateTime.Now.ToString(); watermark.ContentAlignment = ContentAlignment.TopRight; watermark.Font.Name = "Arial"; watermark.Font.Size = 20; watermark.ForeColor = Color.Yellow; watermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); break; } // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser) this.imgOutput.ImageUrl = outputImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString(); // Display the generated image this.phOutputContainer.Visible = true; }
public static void SetTextWatermark() { string name = "setTextWatermark.docx"; string folder = "input"; string storage = null; string password = null; TextWatermark body = new TextWatermark("E-iceblue") { Layout = TextWatermark.LayoutEnum.Horizontal, Font = new Font(60, "Arial") { Color = new Color(100, 100, 100) } }; string destFilePath = "output/setTextWatermark_output.docx"; watermarksApi.SetTextWatermark(name, body, destFilePath, folder, storage, password); }
public void TestDefaultTextWatermaks() { m_doc = new Document(); m_doc.Pages.Add(new Page(PaperFormat.A4)); TextWatermark watermark = new TextWatermark("Sample test watermark"); Assert.AreEqual("Sample test watermark", watermark.Text); Assert.AreEqual(0.0f, watermark.Left); Assert.AreEqual(0.0f, watermark.Top); Assert.AreEqual(0.0f, watermark.Angle); Assert.AreEqual(16f, watermark.Font.Size); Assert.AreEqual(StandardFonts.Helvetica.ToString(), watermark.Font.Name); m_doc.Pages[0].Watermarks.Add(watermark); m_doc.Save(OutputFolder + @"\TestDefaultTextWatermaks.pdf"); //Process.Start("TestDefaultTextWatermaks.pdf"); }
public void TestCompositeWatermark() { EncryptedWatermark.Algorithm = aes; CompositeWatermark comp = new CompositeWatermark(); TextWatermark mark1 = new TextWatermark("This is mark #1"); TextWatermark mark2 = new TextWatermark("This is mark #2"); EncryptedWatermark enc = new EncryptedWatermark(mark1, "supersecret"); comp.AddWatermark(mark1); comp.AddWatermark(mark2); Expect(comp.Watermarks.Count, Is.EqualTo(2)); comp.AddWatermark(enc); Expect(comp.Watermarks.Count, Is.EqualTo(3)); Watermarker.EmbedWatermark(file, comp, "password", "results/CompositeMark.png"); PNGFile file2 = new PNGFile("results/CompositeMark.png"); CompositeWatermark extract = (CompositeWatermark)Watermarker.ExtractWatermark(file2, "password"); System.Collections.Generic.List <Watermark> marks = extract.Watermarks; Expect(marks.Count, Is.EqualTo(3)); Assert.IsInstanceOf <TextWatermark>(marks[0]); Assert.IsInstanceOf <TextWatermark>(marks[1]); Assert.IsInstanceOf <EncryptedWatermark>(marks[2]); ((EncryptedWatermark)marks[2]).Decrypt("supersecret"); Expect(((TextWatermark)marks[0]).Text, Is.EqualTo("This is mark #1")); Expect(((TextWatermark)marks[1]).Text, Is.EqualTo("This is mark #2")); Expect(((EncryptedWatermark)marks[2]).Decrypt <TextWatermark>("supersecret").Text, Is.EqualTo("This is mark #1")); }
public void TestEncryptedWatermark() { EncryptedWatermark.Algorithm = aes; TextWatermark mark = new TextWatermark("This should be encrypted"); EncryptedWatermark encrypted = new EncryptedWatermark(mark, "super-secret"); Watermarker.EmbedWatermark(file, encrypted, "password", "results/EncryptedMark.png"); PNGFile file2 = new PNGFile("results/EncryptedMark.png"); EncryptedWatermark extract = (EncryptedWatermark)Watermarker.ExtractWatermark(file2, "password"); mark = extract.Decrypt <TextWatermark>("super-secret"); Expect(mark, Is.Not.Null); Expect(mark.Text, Is.EqualTo("This should be encrypted")); }
/// <summary> /// 根据分节符进行分割方法 /// </summary> /// <param name="obj"></param> private void SplitSectionBreak(object obj) { try { FileSplitModel splitModel = obj as FileSplitModel; //实例化Document对象 Document doc = new Document(); //载入待拆分的Word文档 doc.LoadFromFile(splitModel.filePath); Document newWord; int index = 0; foreach (Section item in doc.Sections) { newWord = new Document(); //每有一个section就创建一个新的文档 newWord.Sections.Add(item.Clone()); //复制section内容到新文档 if (splitModel.fileWaterMark != null) { TextWatermark txtWatermark = new TextWatermark();//新建一个TextWatermark对象,设置文本水印字样 txtWatermark.Text = splitModel.fileWaterMark.waterMarkContent; //设置文本水印字体大小、颜色和文本排列方式 txtWatermark.FontSize = splitModel.fileWaterMark.waterMarkFontSize; txtWatermark.Color = Color.FromName(splitModel.fileWaterMark.waterMarkColor); if (splitModel.fileWaterMark.waterMarkLayout == 0) { txtWatermark.Layout = WatermarkLayout.Diagonal; } else { txtWatermark.Layout = WatermarkLayout.Horizontal; } newWord.Watermark = txtWatermark; //将文本应用到Word文档水印 } newWord.SaveToFile(splitModel.fileOutPath + @"\" + splitModel.fileName + index + splitModel.fileExtension, FileFormat.Auto); //保存文档 index++; } ShowMessage.ShowInfomation(ChangeLanguage.getLanguage("ExecutionCompleted"), showTitle); } catch (Exception ex) { ShowMessage.ShowError(ex.Message, showTitle); } }
protected void ProcessImage() { // Setup the source file name and the output file name string sourceImageFileName = this.imgSource.ImageUrl; string outputImageFileName = "~/repository/output/Ex_A_101.jpg"; switch (this.ddlFilter.SelectedIndex) { case 0: // Fixed Size Crop Constraint int cropWidth = 160; int cropHeight = 350; new FixedCropConstraint(cropWidth, cropHeight).SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); break; case 1: // Scaled Resize Constraint int maxWidth = 160; int maxHeight = 350; new ScaledResizeConstraint(maxWidth, maxHeight).SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); break; case 2: // Grayscale Color Filter DefaultColorFilters.Grayscale.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); break; case 3: // Text Watermark TextWatermark watermark = new TextWatermark(); watermark.Text = DateTime.Now.ToString(); watermark.ContentAlignment = ContentAlignment.TopRight; watermark.Font.Name = "Arial"; watermark.Font.Size = 20; watermark.ForeColor = Color.Yellow; watermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); break; } // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser) this.imgOutput.ImageUrl = outputImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString(); // Display the generated image this.phOutputContainer.Visible = true; }
/// <summary> /// Adds watermark to all the documents in a folder /// </summary> public static void AddWatermarkToAllDocumentsInFolder() { try { //ExStart:AddWatermarkToAllDocumentsInFolder var inputFolder = SourceFolderPath; var outputFolder = SourceFolderPath + "/output"; var files = Directory.GetFiles(inputFolder); var font = new Font("Arial", 8, FontStyle.Bold); var watermark = new TextWatermark("CONFIDENTIAL", font); watermark.HorizontalAlignment = HorizontalAlignment.Center; watermark.VerticalAlignment = VerticalAlignment.Center; watermark.RotateAngle = -45; watermark.SizingType = SizingType.ScaleToParentDimensions; watermark.ScaleFactor = 0.8; watermark.Opacity = 0.5; watermark.ForegroundColor = Color.Red; foreach (var file in files) { try { using (var doc = Document.Load(file)) { doc.AddWatermark(watermark); doc.Save(Path.Combine(outputFolder, Path.GetFileName(file))); } } catch (UnsupportedFileTypeException) { Console.WriteLine("File format is not supported. File = {0}", Path.GetFileName(file)); } } //ExEnd:AddWatermarkToAllDocumentsInFolder } catch (Exception exp) { Console.Write(exp.Message); } }
protected void ProcessImage() { // Setup the source file name and the output file name string sourceImageFileName = this.imgSource.ImageUrl; string outputImageFileName = "~/repository/output/Ex_A_223.jpg"; TextWatermark textWatermark = new TextWatermark(); textWatermark.Text = this.txtText.Text; textWatermark.ContentAlignment = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), this.ddlContentAlignment.SelectedValue); textWatermark.Unit = (GfxUnit)Enum.Parse(typeof(GfxUnit), this.ddlMainUnit.SelectedValue); textWatermark.ContentDisplacement = new Point(int.Parse(this.ddlContentDisplacementX.SelectedValue, CultureInfo.InvariantCulture), int.Parse(this.ddlContentDisplacementY.SelectedValue, CultureInfo.InvariantCulture)); textWatermark.ForeColor = Color.FromArgb(int.Parse(this.ddlForeColorAlpha.SelectedValue, CultureInfo.InvariantCulture), ColorTranslator.FromHtml(this.txtForeColor.Text)); textWatermark.Font.Name = this.ddlFontName.SelectedValue; textWatermark.Font.Size = float.Parse(this.ddlFontSize.SelectedValue, CultureInfo.InvariantCulture); textWatermark.Font.Bold = this.cbFontBold.Checked; textWatermark.Font.Italic = this.cbFontItalic.Checked; textWatermark.Font.Underline = this.cbFontUnderline.Checked; textWatermark.Font.Strikeout = this.cbFontStrikeout.Checked; textWatermark.TextRenderingHint = (System.Drawing.Text.TextRenderingHint)Enum.Parse(typeof(System.Drawing.Text.TextRenderingHint), this.ddlTextRenderingHint.SelectedValue); textWatermark.TextContrast = int.Parse(this.ddlTextContrast.SelectedValue, CultureInfo.InvariantCulture); using (StringFormat stringFormat = new StringFormat()) { // Setup the string format parameters if (this.cbStringFormatFlags_DirectionVertical.Checked) { stringFormat.FormatFlags |= StringFormatFlags.DirectionVertical; } textWatermark.StringFormat = stringFormat; // Process the image textWatermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); } // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser) this.imgOutput.ImageUrl = outputImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString(); // Display the generated image this.phOutputContainer.Visible = true; }
public static void SetPageTemplate() { // Uncomment the line below to add a layout grid to the title header page //headerTemplate.Elements.Add( new LayoutGrid() ); // Create Text watermark TextWatermark textWatermark = new TextWatermark("Draft"); textWatermark.TextOutlineColor = textWatermark.TextColor; textWatermark.TextColor = null; // Add Text watermark to the template template.Elements.Add(textWatermark); //uncomment the below lines to add image watermark // Create Image watermark ImageWatermark imageWatermark = new ImageWatermark(Util.GetResourcePath("Images/DPDFLogo.png")); // Add Text watermark to the template template.Elements.Add(imageWatermark); }
protected void ProcessImage() { // Setup the source file name and the output file name string sourceImageFileName = this.imgSource.ImageUrl; string outputImageFileName = "~/repository/output/Ex_A_223.jpg"; TextWatermark textWatermark = new TextWatermark(); textWatermark.Text = this.txtText.Text; textWatermark.ContentAlignment = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), this.ddlContentAlignment.SelectedValue); textWatermark.Unit = (GfxUnit)Enum.Parse(typeof(GfxUnit), this.ddlMainUnit.SelectedValue); textWatermark.ContentDisplacement = new Point(int.Parse(this.ddlContentDisplacementX.SelectedValue, CultureInfo.InvariantCulture), int.Parse(this.ddlContentDisplacementY.SelectedValue, CultureInfo.InvariantCulture)); textWatermark.ForeColor = Color.FromArgb(int.Parse(this.ddlForeColorAlpha.SelectedValue, CultureInfo.InvariantCulture), ColorTranslator.FromHtml(this.txtForeColor.Text)); textWatermark.Font.Name = this.ddlFontName.SelectedValue; textWatermark.Font.Size = float.Parse(this.ddlFontSize.SelectedValue, CultureInfo.InvariantCulture); textWatermark.Font.Bold = this.cbFontBold.Checked; textWatermark.Font.Italic = this.cbFontItalic.Checked; textWatermark.Font.Underline = this.cbFontUnderline.Checked; textWatermark.Font.Strikeout = this.cbFontStrikeout.Checked; textWatermark.TextRenderingHint = (System.Drawing.Text.TextRenderingHint)Enum.Parse(typeof(System.Drawing.Text.TextRenderingHint), this.ddlTextRenderingHint.SelectedValue); textWatermark.TextContrast = int.Parse(this.ddlTextContrast.SelectedValue, CultureInfo.InvariantCulture); using (StringFormat stringFormat = new StringFormat()) { // Setup the string format parameters if (this.cbStringFormatFlags_DirectionVertical.Checked) { stringFormat.FormatFlags |= StringFormatFlags.DirectionVertical; } textWatermark.StringFormat = stringFormat; // Process the image textWatermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); } // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser) this.imgOutput.ImageUrl = outputImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString(); // Display the generated image this.phOutputContainer.Visible = true; }
protected void processImages() { // Delete the previously generated files string[] oldOutputImages = System.IO.Directory.GetFiles(Server.MapPath(OutputImagesFolder)); foreach (string oldOutputImage in oldOutputImages) { System.IO.File.Delete(oldOutputImage); } // Create a new image processing job ImageProcessingJob job = new ImageProcessingJob(); if (this.cbFilterCrop.Checked) { // Add the crop filter job.Filters.Add(new FixedCropConstraint(380, 320)); } if (this.cbFilterColor.Checked) { job.Filters.Add(DefaultColorFilters.Sepia); } if (this.cbFilterWatermark.Checked) { // Add the watermark TextWatermark textWatermark = new TextWatermark(); textWatermark.ContentAlignment = ContentAlignment.BottomRight; textWatermark.ForeColor = Color.FromArgb(230, Color.Black); textWatermark.Text = "Image processed by Piczard"; textWatermark.Font.Size = 12; job.Filters.Add(textWatermark); } // Get the files to process string[] sourceImages = System.IO.Directory.GetFiles(Server.MapPath(SourceImagesFolder)); for (int i = 0; i < sourceImages.Length; i++) { string sourceFilePath = sourceImages[i]; string sourceFileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(sourceFilePath); // Get the output image format FormatEncoderParams outputFormat; if (this.rbFormatCustom.Checked) { // Custom format outputFormat = ImageArchiver.GetFormatEncoderParamsFromFileExtension(this.ddlImageFormat.SelectedValue); } else { // Same format as the source image outputFormat = ImageArchiver.GetFormatEncoderParamsFromFilePath(sourceFilePath); } string outputFileName = sourceFileNameWithoutExtension + outputFormat.FileExtension; string outputFilePath = System.IO.Path.Combine(OutputImagesFolder, outputFileName); // Process the image job.SaveProcessedImageToFileSystem(sourceFilePath, outputFilePath); } }