internal WatermarkBase method_62() { PictureWatermark watermark = new PictureWatermark(base.m_doc) { WordPicture = this.ImageData }; if (!base.ShapePr.method_6(0x108) && !base.ShapePr.method_6(0x109)) { watermark.IsWashout = false; } if (this.ImageData.Image.Size.Width != this.ImageData.Width) { watermark.Scaling = (this.ImageData.Width / ((float)this.ImageData.Image.Size.Width)) * 100f; } else if (this.ImageData.Image.Size.Height != this.ImageData.Height) { watermark.Scaling = (this.ImageData.Height / ((float)this.ImageData.Image.Size.Height)) * 100f; } else { watermark.ScalingAuto = false; } this.ImageData.Width = this.ImageData.Image.Size.Width; this.ImageData.Height = this.ImageData.Image.Size.Height; return(watermark); }
internal ShapeObject method_4(PictureWatermark A_0) { int num = 4; if (A_0 == null) { return(null); } ShapeObject obj2 = A_0.WordPicture.Clone() as ShapeObject; if (A_0.IsWashout && (!obj2.ShapePr.method_6(0x108) || !obj2.ShapePr.method_6(0x109))) { obj2.SetShapeAttribute(0x108, 0x4ccd); obj2.SetShapeAttribute(0x109, 0x599a); } else if (!A_0.IsWashout) { obj2.ShapePr.Remove(0x108); obj2.ShapePr.Remove(0x109); } int num2 = this.method_9(); obj2.Id = num2; obj2.Name = BookmarkStart.b("紩䌫尭启戱崳唵䰷伹主嬽⍁ぃ⍅㩇❉ⵋ㱍㭏", num) + num2.ToString(); obj2.TextWrappingStyle = TextWrappingStyle.InFrontOfText; obj2.SetShapeAttribute(0x3ba, true); return(obj2); }
//Url https://help.syncfusion.com/file-formats/docio/applying-watermark public void AddWatermarkWork() { ////Creates a new Word document //WordDocument document = new WordDocument(); ////Adds a section and a paragraph in the document //document.EnsureMinimal(); //IWParagraph paragraph = document.LastParagraph; //paragraph.AppendText("AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."); string strDoc = @"E:\MEDRAR\docs examples\pruebas para marca de agua.doc"; Stream stream = File.Open(strDoc, FileMode.Open); // Loads an existing Word document. WordDocument wordDocument = new WordDocument(stream, FormatType.Doc); // Gets the image from file. Image image = Image.FromFile(@"E:\MEDRAR\docs examples\watermaktest.png"); //Creates a new picture watermark PictureWatermark picWatermark = new PictureWatermark(); //Sets the scaling to picture picWatermark.Scaling = 120f; picWatermark.Washout = true; //Sets the picture watermark to document wordDocument.Watermark = picWatermark; // Sets the image to the picture watermark ,Saves Word document and closes WordDocument instance. picWatermark.Picture = Image.FromFile(@"E:\MEDRAR\docs examples\watermaktest.png"); //save documento whit watermark string strDocWatermark = @"E:\MEDRAR\docs examples\watermaktest.doc"; Stream streamDocWatermark = File.Open(strDocWatermark, FileMode.Open); wordDocument.Save(streamDocWatermark, FormatType.Docx); wordDocument.Close(); //string strDocWatermark = @"E:\MEDRAR\docs examples\DocWhitWaterMark.doc"; //Stream streamDocWatermark = File.Open(strDocWatermark, FileMode.Open); //wordDocument.Save(streamDocWatermark, FormatType.Doc); //wordDocument.Close(); //using (Image image = Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg")) //using (Image watermarkImage = Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\watermark.png")) //using (Graphics imageGraphics = Graphics.FromImage(image)) //using (TextureBrush watermarkBrush = new TextureBrush(watermarkImage)) //{ // int x = (image.Width / 2 - watermarkImage.Width / 2); // int y = (image.Height / 2 - watermarkImage.Height / 2); // watermarkBrush.TranslateTransform(x, y); // imageGraphics.FillRectangle(watermarkBrush, new Rectangle(new Point(x, y), new Size(watermarkImage.Width + 1, watermarkImage.Height))); // image.Save(@"C:\Users\Public\Pictures\Sample Pictures\Desert_watermark.jpg"); //} }
private void InsertImageWatermark(Document document) { PictureWatermark picture = new PictureWatermark(); picture.Picture = System.Drawing.Image.FromFile(@"..\..\..\..\..\..\..\Data\ImageWatermark.png"); picture.Scaling = 250; picture.IsWashout = false; document.Watermark = picture; }
private void btn_Impose_Click(object sender, RoutedEventArgs e) { PictureWatermark picture = new PictureWatermark(); picture.Picture = Image.FromFile(image_address); picture.Scaling = 250; document = new Document(document_address); document.Watermark = picture; MessageBox.Show("Водяной узнак успешно наложен"); }
static void Main(string[] args) { Document document = new Document(); document.LoadFromFile(@"E:\Visual Studio\Sample\How to Make a Cake.docx"); PictureWatermark picture = new PictureWatermark(); picture.Picture = System.Drawing.Image.FromFile(@"C:\Users\Administrator\Pictures\cake.jpg"); picture.Scaling = 180; document.Watermark = picture; document.SaveToFile("result.docx"); }
/// <summary>生成水印文件</summary> public void Process(string docPath, string savePath, bool useText, string text, string imgPath) { var doc = new Document(); doc.LoadFromFile(docPath); var ext = savePath.GetFileExtension(); if (ext.Contains("pdf")) { // 更改逻辑,先生成pdf,再打水印(这样可以实现每页都打上水印图片) doc.SaveToFile(savePath, FileFormat.PDF); doc.Close(); new PdfWatermarker().Process(savePath, savePath, useText, text, imgPath); } else { // 统一用图片水印 var size = new SizeF(800, 800); Image img = useText ? DrawHelper.CreateTextImage(text, size, Config.TextFont, Config.TextColor, Config.Padding, Config.Angle) : Painter.LoadImage(imgPath) ; // 内置水印功能,会被前景挡住 var picture = new PictureWatermark(); picture.Picture = img; picture.Scaling = 80; doc.Watermark = picture; /* * // 想给每页word都添加图片,现阶段实现不了。 * DocPicture picture = doc.Sections[0].Paragraphs[0].AppendPicture(img); * picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; * picture.HorizontalPosition = 0f; * picture.VerticalPosition = 0f; * picture.Width = img.Width; * picture.Height = img.Height; */ doc.SaveToFile(savePath); doc.Close(); } }
static void Main() { // If using Professional version, put your serial key below. ComponentInfo.SetLicense("FREE-LIMITED-KEY"); var document = new DocumentModel(); // First section var section1 = new Section(document); document.Sections.Add(section1); var header1 = new HeaderFooter(document, HeaderFooterType.HeaderDefault); section1.HeadersFooters.Add(header1); var pictureWatermark = new PictureWatermark(document, new Picture(document, "Acme.jpg")); header1.Watermark = pictureWatermark; // Assign watermark to the header. pictureWatermark.AutoScale(); // Scale the picture to fit the page. pictureWatermark.Washout = true; // Second section var section2 = new Section(document); document.Sections.Add(section2); var header2 = new HeaderFooter(document, HeaderFooterType.HeaderDefault); section2.HeadersFooters.Add(header2); var textWatermark = new TextWatermark(document, "Acme corporation"); header2.Watermark = textWatermark; textWatermark.SetDiagonal(); textWatermark.Color = Color.Red; textWatermark.Semitransparent = true; document.Save("Watermarks.docx"); }
private void button1_Click(object sender, EventArgs e) { //Create Word document1. Document document1 = new Document(); //Load the file from disk. document1.LoadFromFile(@"..\..\..\..\..\..\Data\Template_Docx_5.docx"); //Create a new document. Document document2 = new Document(); //Get paragraph 1 and paragraph 2 in document1. Section s = document1.Sections[0]; Paragraph p1 = s.Paragraphs[0]; Paragraph p2 = s.Paragraphs[1]; //Copy p1 and p2 to document2. Section s2 = document2.AddSection(); Paragraph NewPara1 = (Paragraph)p1.Clone(); s2.Paragraphs.Add(NewPara1); Paragraph NewPara2 = (Paragraph)p2.Clone(); s2.Paragraphs.Add(NewPara2); //Add watermark. PictureWatermark WM = new PictureWatermark(); WM.Picture = Image.FromFile(@"..\..\..\..\..\..\Data\Logo.jpg"); document2.Watermark = WM; String result = "Result-CopyWordParagraph.docx"; //Save the file. document2.SaveToFile(result, FileFormat.Docx2013); //Launch the MS Word file. WordDocViewer(result); }
private void button1_Click(object sender, System.EventArgs e) { try { if (!(rdbPicWatermark.Checked) && !(rdbTextWatermark.Checked)) { MessageBoxAdv.Show("Please select a watermark type"); } else { //Open an existing word document WordDocument doc = new WordDocument(@"..\..\..\..\..\..\..\Common\Data\DocIO\Watermark.doc"); if (rdbTextWatermark.Checked) { //Add text watermark. TextWatermark textWatermark = new TextWatermark(); doc.Watermark = textWatermark; //Set the text for the watermark. textWatermark.Text = "Demo"; //Set the color for the watermark text. textWatermark.Color = Color.Gray; //Set the size. textWatermark.Size = 120; } else if (rdbPicWatermark.Checked) { //Add Picture watermark to the word document. PictureWatermark picWatermark = new PictureWatermark(); doc.Watermark = picWatermark; //Set the picture. picWatermark.Picture = Image.FromFile(@"..\..\..\..\..\..\..\Common\Images\DocIO\Northwind_logo.png"); //Set the properties for the watermark. picWatermark.Scaling = 100.0f; picWatermark.Washout = false; } //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. doc.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] System.Diagnostics.Process.Start("Sample.doc"); //Exit this.Close(); } } //Save as docx format else if (wordDocxRadioBtn.Checked) { //Saving the document as .docx doc.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] System.Diagnostics.Process.Start("Sample.docx"); //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as pdf format else if (pdfRadioBtn.Checked) { DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(doc); //Save the pdf file pdfDoc.Save("Sample.pdf"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { System.Diagnostics.Process.Start("Sample.pdf"); //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
public ActionResult Watermark(string Group1, string Group2) { if (Group2 == null) { return(View()); } //Open an existing word document WordDocument doc = new WordDocument(ResolveApplicationDataPath("Watermark.doc", "Data\\DocIO")); if (Group2 != "Picture") { //Add text watermark. TextWatermark textWatermark = new TextWatermark(); doc.Watermark = textWatermark; //Set the text for the watermark. textWatermark.Text = "Demo"; //Set the color for the watermark text. textWatermark.Color = Color.Gray; //Set the size. textWatermark.Size = 120; } else { //Add Picture watermark to the word document. PictureWatermark picWatermark = new PictureWatermark(); doc.Watermark = picWatermark; //Set the picture. picWatermark.Picture = System.Drawing.Image.FromFile(ResolveApplicationDataPath("Northwind_logo.png", "Images\\DocIO")); //Set the properties for the watermark. picWatermark.Scaling = 100.0f; picWatermark.Washout = false; } #region Document Save Option //Save as .doc format if (Group1 == "WordDoc") { return(doc.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx format else if (Group1 == "WordDocx") { return(doc.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(doc.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .pdf format else if (Group1 == "Pdf") { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(doc); return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } #endregion Document Save Option return(View()); }
public ActionResult Watermark(string Group1, string Group2) { if (Group2 == null) { return(View()); } string basePath = _hostingEnvironment.WebRootPath; string dataPath = basePath + @"/DocIO/Watermark.doc"; //Open an existing word document FileStream fileStream = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); WordDocument doc = new WordDocument(fileStream, FormatType.Doc); fileStream.Dispose(); fileStream = null; if (Group2 != "Picture") { //Add text watermark. TextWatermark textWatermark = new TextWatermark("Demo", "Arial", 160, 160); doc.Watermark = textWatermark; //Set the color for the watermark text. textWatermark.Color = Syncfusion.Drawing.Color.Gray; //Set the size. textWatermark.Size = 120; } else { //Add Picture watermark to the word document. PictureWatermark picWatermark = new PictureWatermark(); doc.Watermark = picWatermark; FileStream imageStream = new FileStream(basePath + @"/images/DocIO/Northwind_logo.png", FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(imageStream); byte[] image = br.ReadBytes((int)imageStream.Length); //Set the picture. picWatermark.LoadPicture(image); //Set the properties for the watermark. picWatermark.Scaling = 100.0f; picWatermark.Washout = false; } FormatType type = FormatType.Docx; string filename = "Sample.docx"; string contenttype = "application/vnd.ms-word.document.12"; #region Document SaveOption //Save as .doc format if (Group1 == "WordDoc") { type = FormatType.Doc; filename = "Sample.doc"; contenttype = "application/msword"; } //Save as .xml format else if (Group1 == "WordML") { type = FormatType.WordML; filename = "Sample.xml"; contenttype = "application/msword"; } #endregion Document SaveOption MemoryStream ms = new MemoryStream(); doc.Save(ms, type); doc.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }