diff --git a/Examples/ApiExamples/ApiExamples/ExAI.cs b/Examples/ApiExamples/ApiExamples/ExAI.cs index dc483700..d0dfbb57 100644 --- a/Examples/ApiExamples/ApiExamples/ExAI.cs +++ b/Examples/ApiExamples/ApiExamples/ExAI.cs @@ -5,7 +5,6 @@ // "as is", without warranty of any kind, either expressed or implied. ////////////////////////////////////////////////////////////////////////// -using System.Text; using NUnit.Framework; using Aspose.Words; using System; @@ -48,5 +47,23 @@ public void AiSummarize() multiDocumentSummary.Save(ArtifactsDir + "AI.AiSummarize.Multi.docx"); //ExEnd:AiSummarize } + + [Test, Ignore("This test should be run manually to manage API requests amount")] + public void AiTranslate() + { + //ExStart:AiTranslate + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:IAiModelText.Translate(Document, AI.Language) + //ExSummary:Shows how to translate text using Google models. + Document doc = new Document(MyDir + "Document.docx"); + + string apiKey = Environment.GetEnvironmentVariable("API_KEY"); + // Use Google generative language models. + IAiModelText model = (IAiModelText)AiModel.Create(AiModelType.Gemini15Flash).WithApiKey(apiKey); + + Document translatedDoc = model.Translate(doc, Language.Arabic); + translatedDoc.Save(ArtifactsDir + "AI.AiTranslate.docx"); + //ExEnd:AiTranslate + } } } diff --git a/Examples/ApiExamples/ApiExamples/ExCharts.cs b/Examples/ApiExamples/ApiExamples/ExCharts.cs index dc39a8f0..d4f3f142 100644 --- a/Examples/ApiExamples/ApiExamples/ExCharts.cs +++ b/Examples/ApiExamples/ApiExamples/ExCharts.cs @@ -2350,5 +2350,145 @@ public void FormatCode() Assert.AreEqual("#,##0.0#", seriesProperties.BubbleSizes.FormatCode); } } + + [Test] + public void DataLablePosition() + { + //ExStart:DataLablePosition + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:ChartDataLabelCollection.Position + //ExFor:ChartDataLabel.Position + //ExFor:ChartDataLabelPosition + //ExSummary:Shows how to set the position of the data label. + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + // Insert column chart. + Shape shape = builder.InsertChart(ChartType.Column, 432, 252); + Chart chart = shape.Chart; + ChartSeriesCollection seriesColl = chart.Series; + + // Delete default generated series. + seriesColl.Clear(); + + // Add series. + ChartSeries series = seriesColl.Add( + "Series 1", + new string[] { "Category 1", "Category 2", "Category 3" }, + new double[] { 4, 5, 6 }); + + // Show data labels and set font color. + series.HasDataLabels = true; + ChartDataLabelCollection dataLabels = series.DataLabels; + dataLabels.ShowValue = true; + dataLabels.Font.Color = Color.White; + + // Set data label position. + dataLabels.Position = ChartDataLabelPosition.InsideBase; + dataLabels[0].Position = ChartDataLabelPosition.OutsideEnd; + dataLabels[0].Font.Color = Color.DarkRed; + + doc.Save(ArtifactsDir + "Charts.LabelPosition.docx"); + //ExEnd:DataLablePosition + } + + [Test] + public void DoughnutChartLabelPosition() + { + //ExStart:DoughnutChartLabelPosition + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:ChartDataLabel.Left + //ExFor:ChartDataLabel.LeftMode + //ExFor:ChartDataLabel.Top + //ExFor:ChartDataLabel.TopMode + //ExFor:ChartDataLabelLocationMode + //ExSummary:Shows how to place data labels of doughnut chart outside doughnut. + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + const int chartWidth = 432; + const int chartHeight = 252; + Shape shape = builder.InsertChart(ChartType.Doughnut, chartWidth, chartHeight); + Chart chart = shape.Chart; + ChartSeriesCollection seriesColl = chart.Series; + // Delete default generated series. + seriesColl.Clear(); + + // Hide the legend. + chart.Legend.Position = LegendPosition.None; + + // Generate data. + const int dataLength = 20; + double totalValue = 0; + string[] categories = new string[dataLength]; + double[] values = new double[dataLength]; + for (int i = 0; i < dataLength; i++) + { + categories[i] = string.Format("Category {0}", i); + values[i] = dataLength - i; + totalValue += values[i]; + } + + ChartSeries series = seriesColl.Add("Series 1", categories, values); + series.HasDataLabels = true; + + ChartDataLabelCollection dataLabels = series.DataLabels; + dataLabels.ShowValue = true; + dataLabels.ShowLeaderLines = true; + + // The Position property cannot be used for doughnut charts. Let's place data labels using the Left and Top + // properties around a circle outside of the chart doughnut. + // The origin is in the upper left corner of the chart. + + const double titleAreaHeight = 25.5; // This can be calculated using title text and font. + const double doughnutCenterY = titleAreaHeight + (chartHeight - titleAreaHeight) / 2; + const double doughnutCenterX = chartWidth / 2d; + const double labelHeight = 16.5; // This can be calculated using label font. + const double oneCharLabelWidth = 12.75; // This can be calculated for each label using its text and font. + const double twoCharLabelWidth = 17.25; // This can be calculated for each label using its text and font. + const double yMargin = 0.75; + const double labelMargin = 1.5; + const double labelCircleRadius = chartHeight - doughnutCenterY - yMargin - labelHeight / 2; + + // Because the data points start at the top, the X coordinates used in the Left and Top properties of + // the data labels point to the right and the Y coordinates point down, the starting angle is -PI/2. + double totalAngle = -System.Math.PI / 2; + ChartDataLabel previousLabel = null; + + for (int i = 0; i < series.YValues.Count; i++) + { + ChartDataLabel dataLabel = dataLabels[i]; + + double value = series.YValues[i].DoubleValue; + double labelWidth = (value < 10) ? oneCharLabelWidth : twoCharLabelWidth; + double labelSegmentAngle = value / totalValue * 2 * System.Math.PI; + double labelAngle = labelSegmentAngle / 2 + totalAngle; + double labelCenterX = labelCircleRadius * System.Math.Cos(labelAngle) + doughnutCenterX; + double labelCenterY = labelCircleRadius * System.Math.Sin(labelAngle) + doughnutCenterY; + double labelLeft = labelCenterX - labelWidth / 2; + double labelTop = labelCenterY - labelHeight / 2; + + // If the current data label overlaps other labels, move it horizontally. + if ((previousLabel != null) && + (System.Math.Abs(previousLabel.Top - labelTop) < labelHeight) && + (System.Math.Abs(previousLabel.Left - labelLeft) < labelWidth)) + { + // Move right on the top, left on the bottom. + bool isOnTop = (totalAngle < 0) || (totalAngle >= System.Math.PI); + labelLeft = previousLabel.Left + labelWidth * (isOnTop ? 1 : -1) + labelMargin; + } + + dataLabel.Left = labelLeft; + dataLabel.LeftMode = ChartDataLabelLocationMode.Absolute; + dataLabel.Top = labelTop; + dataLabel.TopMode = ChartDataLabelLocationMode.Absolute; + + totalAngle += labelSegmentAngle; + previousLabel = dataLabel; + } + + doc.Save(ArtifactsDir + "Charts.DoughnutChartLabelPosition.docx"); + //ExEnd:DoughnutChartLabelPosition + } } } diff --git a/Examples/ApiExamples/ApiExamples/ExLowCode.cs b/Examples/ApiExamples/ApiExamples/ExLowCode.cs index 4210a01e..d2ab7b0d 100644 --- a/Examples/ApiExamples/ApiExamples/ExLowCode.cs +++ b/Examples/ApiExamples/ApiExamples/ExLowCode.cs @@ -5,7 +5,9 @@ // "as is", without warranty of any kind, either expressed or implied. ////////////////////////////////////////////////////////////////////////// +using System; using System.Collections.Generic; +using System.Data; using System.Drawing; using System.IO; using System.Linq; @@ -13,7 +15,13 @@ using Aspose.Page.XPS; using Aspose.Page.XPS.XpsModel; using Aspose.Words; +using Aspose.Words.Comparing; using Aspose.Words.LowCode; +using Aspose.Words.LowCode.MailMerging; +using Aspose.Words.LowCode.Reporting; +using Aspose.Words.LowCode.Splitting; +using Aspose.Words.Replacing; +using Aspose.Words.Reporting; using Aspose.Words.Saving; using NUnit.Framework; using LoadOptions = Aspose.Words.Loading.LoadOptions; @@ -341,5 +349,697 @@ private static void AssertXpsText(XpsElement element) if (element is XpsGlyphs) Assert.True(new[] { "Heading 1", "Head", "ing 1" }.Any(c => ((XpsGlyphs)element).UnicodeString.Contains(c))); } + + [Test] + public void CompareDocuments() + { + //ExStart:CompareDocuments + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Comparer.Compare(String, String, String, String, DateTime) + //ExFor:Comparer.Compare(String, String, String, SaveFormat, String, DateTime) + //ExFor:Comparer.Compare(String, String, String, String, DateTime, CompareOptions) + //ExFor:Comparer.Compare(String, String, String, SaveFormat, String, DateTime, CompareOptions) + //ExSummary:Shows how to simple compare documents. + // There is a several ways to compare documents: + string firstDoc = MyDir + "Table column bookmarks.docx"; + string secondDoc = MyDir + "Table column bookmarks.doc"; + + Comparer.Compare(firstDoc, secondDoc, ArtifactsDir + "LowCode.CompareDocuments.1.docx", "Author", new DateTime()); + Comparer.Compare(firstDoc, secondDoc, ArtifactsDir + "LowCode.CompareDocuments.2.docx", SaveFormat.Docx, "Author", new DateTime()); + Comparer.Compare(firstDoc, secondDoc, ArtifactsDir + "LowCode.CompareDocuments.3.docx", "Author", new DateTime(), new CompareOptions() { IgnoreCaseChanges = true }); + Comparer.Compare(firstDoc, secondDoc, ArtifactsDir + "LowCode.CompareDocuments.4.docx", SaveFormat.Docx, "Author", new DateTime(), new CompareOptions() { IgnoreCaseChanges = true }); + //ExEnd:CompareDocuments + } + + [Test] + public void CompareStreamDocuments() + { + //ExStart:CompareStreamDocuments + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Comparer.Compare(Stream, Stream, Stream, SaveFormat, String, DateTime) + //ExFor:Comparer.Compare(Stream, Stream, Stream, SaveFormat, String, DateTime, CompareOptions) + //ExSummary:Shows how to compare documents from the stream. + // There is a several ways to compare documents from the stream: + using (FileStream firstStreamIn = new FileStream(MyDir + "Table column bookmarks.docx", FileMode.Open, FileAccess.Read)) + { + using (FileStream secondStreamIn = new FileStream(MyDir + "Table column bookmarks.doc", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.CompareStreamDocuments.1.docx", FileMode.Create, FileAccess.ReadWrite)) + Comparer.Compare(firstStreamIn, secondStreamIn, streamOut, SaveFormat.Docx, "Author", new DateTime()); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.CompareStreamDocuments.2.docx", FileMode.Create, FileAccess.ReadWrite)) + Comparer.Compare(firstStreamIn, secondStreamIn, streamOut, SaveFormat.Docx, "Author", new DateTime(), new CompareOptions() { IgnoreCaseChanges = true }); + } + } + //ExEnd:CompareStreamDocuments + } + + [Test] + public void MailMerge() + { + //ExStart:MailMerge + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMerger.Execute(String, String, String[], Object[]) + //ExFor:MailMerger.Execute(String, String, SaveFormat, String[], Object[]) + //ExFor:MailMerger.Execute(String, String, SaveFormat, MailMergeOptions, String[], Object[]) + //ExSummary:Shows how to do mail merge operation for a single record. + // There is a several ways to do mail merge operation: + string doc = MyDir + "Mail merge.doc"; + + string[] fieldNames = new string[] { "FirstName", "Location", "SpecialCharsInName()" }; + string[] fieldValues = new string[] { "James Bond", "London", "Classified" }; + + MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMerge.1.docx", fieldNames, fieldValues); + MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMerge.2.docx", SaveFormat.Docx, fieldNames, fieldValues); + MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMerge.3.docx", SaveFormat.Docx, new MailMergeOptions() { TrimWhitespaces = true }, fieldNames, fieldValues); + //ExEnd:MailMerge + } + + [Test] + public void MailMergeStream() + { + //ExStart:MailMergeStream + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMerger.Execute(Stream, Stream, SaveFormat, String[], Object[]) + //ExFor:MailMerger.Execute(Stream, Stream, SaveFormat, MailMergeOptions, String[], Object[]) + //ExSummary:Shows how to do mail merge operation for a single record from the stream. + // There is a several ways to do mail merge operation using documents from the stream: + string[] fieldNames = new string[] { "FirstName", "Location", "SpecialCharsInName()" }; + string[] fieldValues = new string[] { "James Bond", "London", "Classified" }; + + using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStream.1.docx", FileMode.Create, FileAccess.ReadWrite)) + MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, fieldNames, fieldValues); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStream.2.docx", FileMode.Create, FileAccess.ReadWrite)) + MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, new MailMergeOptions() { TrimWhitespaces = true }, fieldNames, fieldValues); + } + //ExEnd:MailMergeStream + } + + [Test] + public void MailMergeDataRow() + { + //ExStart:MailMergeDataRow + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMerger.Execute(String, String, DataRow) + //ExFor:MailMerger.Execute(String, String, SaveFormat, DataRow) + //ExFor:MailMerger.Execute(String, String, SaveFormat, MailMergeOptions, DataRow) + //ExSummary:Shows how to do mail merge operation from a DataRow. + // There is a several ways to do mail merge operation from a DataRow: + string doc = MyDir + "Mail merge.doc"; + + DataTable dataTable = new DataTable(); + dataTable.Columns.Add("FirstName"); + dataTable.Columns.Add("Location"); + dataTable.Columns.Add("SpecialCharsInName()"); + + DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" }); + + MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataRow.1.docx", dataRow); + MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataRow.2.docx", SaveFormat.Docx, dataRow); + MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataRow.3.docx", SaveFormat.Docx, new MailMergeOptions() { TrimWhitespaces = true }, dataRow); + //ExEnd:MailMergeDataRow + } + + [Test] + public void MailMergeStreamDataRow() + { + //ExStart:MailMergeStreamDataRow + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMerger.Execute(Stream, Stream, SaveFormat, DataRow) + //ExFor:MailMerger.Execute(Stream, Stream, SaveFormat, MailMergeOptions, DataRow) + //ExSummary:Shows how to do mail merge operation from a DataRow using documents from the stream. + // There is a several ways to do mail merge operation from a DataRow using documents from the stream: + DataTable dataTable = new DataTable(); + dataTable.Columns.Add("FirstName"); + dataTable.Columns.Add("Location"); + dataTable.Columns.Add("SpecialCharsInName()"); + + DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" }); + + using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamDataRow.1.docx", FileMode.Create, FileAccess.ReadWrite)) + MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, dataRow); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamDataRow.2.docx", FileMode.Create, FileAccess.ReadWrite)) + MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, new MailMergeOptions() { TrimWhitespaces = true }, dataRow); + } + //ExEnd:MailMergeStreamDataRow + } + + [Test] + public void MailMergeDataTable() + { + //ExStart:MailMergeDataTable + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMerger.Execute(String, String, DataTable) + //ExFor:MailMerger.Execute(String, String, SaveFormat, DataTable) + //ExFor:MailMerger.Execute(String, String, SaveFormat, MailMergeOptions, DataTable) + //ExSummary:Shows how to do mail merge operation from a DataTable. + // There is a several ways to do mail merge operation from a DataTable: + string doc = MyDir + "Mail merge.doc"; + + DataTable dataTable = new DataTable(); + dataTable.Columns.Add("FirstName"); + dataTable.Columns.Add("Location"); + dataTable.Columns.Add("SpecialCharsInName()"); + + DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" }); + + MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataTable.1.docx", dataTable); + MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataTable.2.docx", SaveFormat.Docx, dataTable); + MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataTable.3.docx", SaveFormat.Docx, new MailMergeOptions() { TrimWhitespaces = true }, dataTable); + //ExEnd:MailMergeDataTable + } + + [Test] + public void MailMergeStreamDataTable() + { + //ExStart:MailMergeStreamDataTable + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMerger.Execute(Stream, Stream, SaveFormat, DataTable) + //ExFor:MailMerger.Execute(Stream, Stream, SaveFormat, MailMergeOptions, DataTable) + //ExSummary:Shows how to do mail merge operation from a DataTable using documents from the stream. + // There is a several ways to do mail merge operation from a DataTable using documents from the stream: + DataTable dataTable = new DataTable(); + dataTable.Columns.Add("FirstName"); + dataTable.Columns.Add("Location"); + dataTable.Columns.Add("SpecialCharsInName()"); + + DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" }); + + using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeDataTable.1.docx", FileMode.Create, FileAccess.ReadWrite)) + MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, dataTable); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeDataTable.2.docx", FileMode.Create, FileAccess.ReadWrite)) + MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, new MailMergeOptions() { TrimWhitespaces = true }, dataTable); + } + //ExEnd:MailMergeStreamDataTable + } + + [Test] + public void MailMergeWithRegionsDataTable() + { + //ExStart:MailMergeWithRegionsDataTable + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMerger.ExecuteWithRegions(String, String, DataTable) + //ExFor:MailMerger.ExecuteWithRegions(String, String, SaveFormat, DataTable) + //ExFor:MailMerger.ExecuteWithRegions(String, String, SaveFormat, MailMergeOptions, DataTable) + //ExSummary:Shows how to do mail merge with regions operation from a DataTable. + // There is a several ways to do mail merge with regions operation from a DataTable: + string doc = MyDir + "Mail merge with regions.docx"; + + DataTable dataTable = new DataTable("MyTable"); + dataTable.Columns.Add("FirstName"); + dataTable.Columns.Add("LastName"); + dataTable.Rows.Add(new object[] { "John", "Doe" }); + dataTable.Rows.Add(new object[] { "", "" }); + dataTable.Rows.Add(new object[] { "Jane", "Doe" }); + + MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataTable.1.docx", dataTable); + MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataTable.2.docx", SaveFormat.Docx, dataTable); + MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataTable.3.docx", SaveFormat.Docx, new MailMergeOptions() { TrimWhitespaces = true }, dataTable); + //ExEnd:MailMergeWithRegionsDataTable + } + + [Test] + public void MailMergeStreamWithRegionsDataTable() + { + //ExStart:MailMergeStreamWithRegionsDataTable + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMerger.ExecuteWithRegions(Stream, Stream, SaveFormat, DataTable) + //ExFor:MailMerger.ExecuteWithRegions(Stream, Stream, SaveFormat, MailMergeOptions, DataTable) + //ExSummary:Shows how to do mail merge with regions operation from a DataTable using documents from the stream. + // There is a several ways to do mail merge with regions operation from a DataTable using documents from the stream: + DataTable dataTable = new DataTable("MyTable"); + dataTable.Columns.Add("FirstName"); + dataTable.Columns.Add("LastName"); + dataTable.Rows.Add(new object[] { "John", "Doe" }); + dataTable.Rows.Add(new object[] { "", "" }); + dataTable.Rows.Add(new object[] { "Jane", "Doe" }); + + using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamWithRegionsDataTable.1.docx", FileMode.Create, FileAccess.ReadWrite)) + MailMerger.ExecuteWithRegions(streamIn, streamOut, SaveFormat.Docx, dataTable); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamWithRegionsDataTable.2.docx", FileMode.Create, FileAccess.ReadWrite)) + MailMerger.ExecuteWithRegions(streamIn, streamOut, SaveFormat.Docx, new MailMergeOptions() { TrimWhitespaces = true }, dataTable); + } + //ExEnd:MailMergeStreamWithRegionsDataTable + } + + [Test] + public void MailMergeWithRegionsDataSet() + { + //ExStart:MailMergeWithRegionsDataSet + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMerger.ExecuteWithRegions(String, String, DataSet) + //ExFor:MailMerger.ExecuteWithRegions(String, String, SaveFormat, DataSet) + //ExFor:MailMerger.ExecuteWithRegions(String, String, SaveFormat, MailMergeOptions, DataSet) + //ExSummary:Shows how to do mail merge with regions operation from a DataSet. + // There is a several ways to do mail merge with regions operation from a DataSet: + string doc = MyDir + "Mail merge with regions data set.docx"; + + DataTable tableCustomers = new DataTable("Customers"); + tableCustomers.Columns.Add("CustomerID"); + tableCustomers.Columns.Add("CustomerName"); + tableCustomers.Rows.Add(new object[] { 1, "John Doe" }); + tableCustomers.Rows.Add(new object[] { 2, "Jane Doe" }); + + DataTable tableOrders = new DataTable("Orders"); + tableOrders.Columns.Add("CustomerID"); + tableOrders.Columns.Add("ItemName"); + tableOrders.Columns.Add("Quantity"); + tableOrders.Rows.Add(new object[] { 1, "Hawaiian", 2 }); + tableOrders.Rows.Add(new object[] { 2, "Pepperoni", 1 }); + tableOrders.Rows.Add(new object[] { 2, "Chicago", 1 }); + + DataSet dataSet = new DataSet(); + dataSet.Tables.Add(tableCustomers); + dataSet.Tables.Add(tableOrders); + dataSet.Relations.Add(tableCustomers.Columns["CustomerID"], tableOrders.Columns["CustomerID"]); + + MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataSet.1.docx", dataSet); + MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataSet.2.docx", SaveFormat.Docx, dataSet); + MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataSet.3.docx", SaveFormat.Docx, new MailMergeOptions() { TrimWhitespaces = true }, dataSet); + //ExEnd:MailMergeWithRegionsDataSet + } + + [Test] + public void MailMergeStreamWithRegionsDataSet() + { + //ExStart:MailMergeStreamWithRegionsDataSet + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMerger.ExecuteWithRegions(Stream, Stream, SaveFormat, DataSet) + //ExFor:MailMerger.ExecuteWithRegions(Stream, Stream, SaveFormat, MailMergeOptions, DataSet) + //ExSummary:Shows how to do mail merge with regions operation from a DataSet using documents from the stream. + // There is a several ways to do mail merge with regions operation from a DataSet using documents from the stream: + DataTable tableCustomers = new DataTable("Customers"); + tableCustomers.Columns.Add("CustomerID"); + tableCustomers.Columns.Add("CustomerName"); + tableCustomers.Rows.Add(new object[] { 1, "John Doe" }); + tableCustomers.Rows.Add(new object[] { 2, "Jane Doe" }); + + DataTable tableOrders = new DataTable("Orders"); + tableOrders.Columns.Add("CustomerID"); + tableOrders.Columns.Add("ItemName"); + tableOrders.Columns.Add("Quantity"); + tableOrders.Rows.Add(new object[] { 1, "Hawaiian", 2 }); + tableOrders.Rows.Add(new object[] { 2, "Pepperoni", 1 }); + tableOrders.Rows.Add(new object[] { 2, "Chicago", 1 }); + + DataSet dataSet = new DataSet(); + dataSet.Tables.Add(tableCustomers); + dataSet.Tables.Add(tableOrders); + dataSet.Relations.Add(tableCustomers.Columns["CustomerID"], tableOrders.Columns["CustomerID"]); + + using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamWithRegionsDataTable.1.docx", FileMode.Create, FileAccess.ReadWrite)) + MailMerger.ExecuteWithRegions(streamIn, streamOut, SaveFormat.Docx, dataSet); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamWithRegionsDataTable.2.docx", FileMode.Create, FileAccess.ReadWrite)) + MailMerger.ExecuteWithRegions(streamIn, streamOut, SaveFormat.Docx, new MailMergeOptions() { TrimWhitespaces = true }, dataSet); + } + //ExEnd:MailMergeStreamWithRegionsDataSet + } + + [Test] + public void Replace() + { + //ExStart:Replace + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Replacer.Replace(String, String, String, String) + //ExFor:Replacer.Replace(String, String, SaveFormat, String, String) + //ExFor:Replacer.Replace(String, String, SaveFormat, String, String, FindReplaceOptions) + //ExSummary:Shows how to replace string in the document. + // There is a several ways to replace string in the document: + string doc = MyDir + "Footer.docx"; + string pattern = "(C)2006 Aspose Pty Ltd."; + string replacement = "Copyright (C) 2024 by Aspose Pty Ltd."; + + Replacer.Replace(doc, ArtifactsDir + "LowCode.Replace.1.docx", pattern, replacement); + Replacer.Replace(doc, ArtifactsDir + "LowCode.Replace.2.docx", SaveFormat.Docx, pattern, replacement); + Replacer.Replace(doc, ArtifactsDir + "LowCode.Replace.3.docx", SaveFormat.Docx, pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false }); + //ExEnd:Replace + } + + [Test] + public void ReplaceStream() + { + //ExStart:ReplaceStream + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Replacer.Replace(Stream, Stream, SaveFormat, String, String) + //ExFor:Replacer.Replace(Stream, Stream, SaveFormat, String, String, FindReplaceOptions) + //ExSummary:Shows how to replace string in the document using documents from the stream. + // There is a several ways to replace string in the document using documents from the stream: + string pattern = "(C)2006 Aspose Pty Ltd."; + string replacement = "Copyright (C) 2024 by Aspose Pty Ltd."; + + using (FileStream streamIn = new FileStream(MyDir + "Footer.docx", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceStream.1.docx", FileMode.Create, FileAccess.ReadWrite)) + Replacer.Replace(streamIn, streamOut, SaveFormat.Docx, pattern, replacement); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceStream.2.docx", FileMode.Create, FileAccess.ReadWrite)) + Replacer.Replace(streamIn, streamOut, SaveFormat.Docx, pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false }); + } + //ExEnd:ReplaceStream + } + + [Test] + public void ReplaceRegex() + { + //ExStart:ReplaceRegex + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Replacer.Replace(String, String, Regex, String) + //ExFor:Replacer.Replace(String, String, SaveFormat, Regex, String) + //ExFor:Replacer.Replace(String, String, SaveFormat, Regex, String, FindReplaceOptions) + //ExSummary:Shows how to replace string with regex in the document. + // There is a several ways to replace string with regex in the document: + string doc = MyDir + "Footer.docx"; + Regex pattern = new Regex("gr(a|e)y"); + string replacement = "lavender"; + + Replacer.Replace(doc, ArtifactsDir + "LowCode.ReplaceRegex.1.docx", pattern, replacement); + Replacer.Replace(doc, ArtifactsDir + "LowCode.ReplaceRegex.2.docx", SaveFormat.Docx, pattern, replacement); + Replacer.Replace(doc, ArtifactsDir + "LowCode.ReplaceRegex.3.docx", SaveFormat.Docx, pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false }); + //ExEnd:ReplaceRegex + } + + [Test] + public void ReplaceStreamRegex() + { + //ExStart:ReplaceStreamRegex + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Replacer.Replace(Stream, Stream, SaveFormat, Regex, String) + //ExFor:Replacer.Replace(Stream, Stream, SaveFormat, Regex, String, FindReplaceOptions) + //ExSummary:Shows how to replace string with regex in the document using documents from the stream. + // There is a several ways to replace string with regex in the document using documents from the stream: + Regex pattern = new Regex("gr(a|e)y"); + string replacement = "lavender"; + + using (FileStream streamIn = new FileStream(MyDir + "Replace regex.docx", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceStreamRegex.1.docx", FileMode.Create, FileAccess.ReadWrite)) + Replacer.Replace(streamIn, streamOut, SaveFormat.Docx, pattern, replacement); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceStreamRegex.2.docx", FileMode.Create, FileAccess.ReadWrite)) + Replacer.Replace(streamIn, streamOut, SaveFormat.Docx, pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false }); + } + //ExEnd:ReplaceStreamRegex + } + + //ExStart:BuildReportData + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:ReportBuilder.BuildReport(String, String, Object) + //ExFor:ReportBuilder.BuildReport(String, String, Object, ReportBuilderOptions) + //ExFor:ReportBuilder.BuildReport(String, String, SaveFormat, Object) + //ExFor:ReportBuilder.BuildReport(String, String, SaveFormat, Object, ReportBuilderOptions) + //ExSummary:Shows how to populate document with data. + [Test] //ExSkip + public void BuildReportData() + { + // There is a several ways to populate document with data: + string doc = MyDir + "Reporting engine template - If greedy.docx"; + + AsposeData obj = new AsposeData { List = new List { "abc" } }; + + ReportBuilder.BuildReport(doc, ArtifactsDir + "LowCode.BuildReportWithObject.1.docx", obj); + ReportBuilder.BuildReport(doc, ArtifactsDir + "LowCode.BuildReportWithObject.2.docx", obj, new ReportBuilderOptions() { Options = ReportBuildOptions.AllowMissingMembers }); + ReportBuilder.BuildReport(doc, ArtifactsDir + "LowCode.BuildReportWithObject.3.docx", SaveFormat.Docx, obj); + ReportBuilder.BuildReport(doc, ArtifactsDir + "LowCode.BuildReportWithObject.4.docx", SaveFormat.Docx, obj, new ReportBuilderOptions() { Options = ReportBuildOptions.AllowMissingMembers }); + } + + public class AsposeData + { + public List List { get; set; } + } + //ExEnd:BuildReportData + + [Test] + public void BuildReportDataStream() + { + //ExStart:BuildReportDataStream + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:ReportBuilder.BuildReport(Stream, Stream, SaveFormat, Object) + //ExFor:ReportBuilder.BuildReport(Stream, Stream, SaveFormat, Object, ReportBuilderOptions) + //ExSummary:Shows how to populate document with data using documents from the stream. + // There is a several ways to populate document with data using documents from the stream: + AsposeData obj = new AsposeData { List = new List { "abc" } }; + + using (FileStream streamIn = new FileStream(MyDir + "Reporting engine template - If greedy.docx", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.BuildReportDataStream.1.docx", FileMode.Create, FileAccess.ReadWrite)) + ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, obj); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.BuildReportDataStream.2.docx", FileMode.Create, FileAccess.ReadWrite)) + ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, obj, new ReportBuilderOptions() { Options = ReportBuildOptions.AllowMissingMembers }); + } + //ExEnd:BuildReportDataStream + } + + //ExStart:BuildReportDataSource + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:ReportBuilder.BuildReport(String, String, Object, String) + //ExFor:ReportBuilder.BuildReport(String, String, Object[], String[]) + //ExFor:ReportBuilder.BuildReport(String, String, Object, String, ReportBuilderOptions) + //ExFor:ReportBuilder.BuildReport(String, String, SaveFormat, Object, String) + //ExFor:ReportBuilder.BuildReport(String, String, SaveFormat, Object, String, ReportBuilderOptions) + //ExSummary:Shows how to populate document with data sources. + [Test] //ExSkip + public void BuildReportDataSource() + { + // There is a several ways to populate document with data sources: + string doc = MyDir + "Report building.docx"; + + MessageTestClass sender = new MessageTestClass("LINQ Reporting Engine", "Hello World"); + + ReportBuilder.BuildReport(doc, ArtifactsDir + "LowCode.BuildReportDataSource.1.docx", sender, "s"); + ReportBuilder.BuildReport(doc, ArtifactsDir + "LowCode.BuildReportDataSource.2.docx", new object[] { sender }, new[] { "s" }); + ReportBuilder.BuildReport(doc, ArtifactsDir + "LowCode.BuildReportDataSource.3.docx", sender, "s", new ReportBuilderOptions() { Options = ReportBuildOptions.AllowMissingMembers }); + ReportBuilder.BuildReport(doc, ArtifactsDir + "LowCode.BuildReportDataSource.4.docx", SaveFormat.Docx, sender, "s"); + ReportBuilder.BuildReport(doc, ArtifactsDir + "LowCode.BuildReportDataSource.5.docx", SaveFormat.Docx, sender, "s", new ReportBuilderOptions() { Options = ReportBuildOptions.AllowMissingMembers }); + } + + public class MessageTestClass + { + public string Name { get; set; } + public string Message { get; set; } + + public MessageTestClass(string name, string message) + { + Name = name; + Message = message; + } + } + //ExEnd:BuildReportDataSource + + [Test] + public void BuildReportDataSourceStream() + { + //ExStart:BuildReportDataSourceStream + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:ReportBuilder.BuildReport(Stream, Stream, SaveFormat, Object[], String[]) + //ExFor:ReportBuilder.BuildReport(Stream, Stream, SaveFormat, Object, String) + //ExFor:ReportBuilder.BuildReport(Stream, Stream, SaveFormat, Object, String, ReportBuilderOptions) + //ExSummary:Shows how to populate document with data sources using documents from the stream. + // There is a several ways to populate document with data sources using documents from the stream: + MessageTestClass sender = new MessageTestClass("LINQ Reporting Engine", "Hello World"); + + using (FileStream streamIn = new FileStream(MyDir + "Report building.docx", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.BuildReportDataSourceStream.1.docx", FileMode.Create, FileAccess.ReadWrite)) + ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, new object[] { sender }, new[] { "s" }); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.BuildReportDataSourceStream.2.docx", FileMode.Create, FileAccess.ReadWrite)) + ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, sender, "s"); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.BuildReportDataSourceStream.3.docx", FileMode.Create, FileAccess.ReadWrite)) + ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, sender, "s", new ReportBuilderOptions() { Options = ReportBuildOptions.AllowMissingMembers }); + } + //ExEnd:BuildReportDataSourceStream + } + + [Test] + public void RemoveBlankPages() + { + //ExStart:RemoveBlankPages + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Splitter.RemoveBlankPages(String, String) + //ExFor:Splitter.RemoveBlankPages(String, String, SaveFormat) + //ExSummary:Shows how to remove empty pages from the document. + // There is a several ways to remove empty pages from the document: + string doc = MyDir + "Blank pages.docx"; + + Splitter.RemoveBlankPages(doc, ArtifactsDir + "LowCode.RemoveBlankPages.1.docx"); + Splitter.RemoveBlankPages(doc, ArtifactsDir + "LowCode.RemoveBlankPages.2.docx", SaveFormat.Docx); + //ExEnd:RemoveBlankPages + } + + [Test] + public void RemoveBlankPagesStream() + { + //ExStart:RemoveBlankPagesStream + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Splitter.RemoveBlankPages(Stream, Stream, SaveFormat) + //ExSummary:Shows how to remove empty pages from the document from the stream. + using (FileStream streamIn = new FileStream(MyDir + "Blank pages.docx", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.RemoveBlankPagesStream.docx", FileMode.Create, FileAccess.ReadWrite)) + Splitter.RemoveBlankPages(streamIn, streamOut, SaveFormat.Docx); + } + //ExEnd:RemoveBlankPagesStream + } + + [Test] + public void ExtractPages() + { + //ExStart:ExtractPages + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Splitter.ExtractPages(String, String, int, int) + //ExFor:Splitter.ExtractPages(String, String, SaveFormat, int, int) + //ExSummary:Shows how to extract pages from the document. + // There is a several ways to extract pages from the document: + string doc = MyDir + "Big document.docx"; + + Splitter.ExtractPages(doc, ArtifactsDir + "LowCode.ExtractPages.1.docx", 0, 2); + Splitter.ExtractPages(doc, ArtifactsDir + "LowCode.ExtractPages.2.docx", SaveFormat.Docx, 0, 2); + //ExEnd:ExtractPages + } + + [Test] + public void ExtractPagesStream() + { + //ExStart:ExtractPagesStream + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Splitter.ExtractPages(Stream, Stream, SaveFormat, int, int) + //ExSummary:Shows how to extract pages from the document from the stream. + using (FileStream streamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ExtractPagesStream.docx", FileMode.Create, FileAccess.ReadWrite)) + Splitter.ExtractPages(streamIn, streamOut, SaveFormat.Docx, 0, 2); + } + //ExEnd:ExtractPagesStream + } + + [Test] + public void SplitDocument() + { + //ExStart:SplitDocument + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Splitter.Split(String, String, SplitOptions) + //ExFor:Splitter.Split(String, String, SaveFormat, SplitOptions) + //ExSummary:Shows how to split document by pages. + string doc = MyDir + "Big document.docx"; + + Splitter.Split(doc, ArtifactsDir + "LowCode.SplitDocument.1.docx", new SplitOptions() { SplitCriteria = SplitCriteria.Page }); + Splitter.Split(doc, ArtifactsDir + "LowCode.SplitDocument.2.docx", SaveFormat.Docx, new SplitOptions() { SplitCriteria = SplitCriteria.Page }); + //ExEnd:SplitDocument + } + + [Test] + public void SplitDocumentStream() + { + //ExStart:SplitDocumentStream + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Splitter.Split(Stream, SaveFormat, SplitOptions) + //ExSummary:Shows how to split document from the stream by pages. + using (FileStream streamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read)) + { + Stream[] stream = Splitter.Split(streamIn, SaveFormat.Docx, new SplitOptions() { SplitCriteria = SplitCriteria.Page }); + } + //ExEnd:SplitDocumentStream + } + + [Test] + public void WatermarkText() + { + //ExStart:WatermarkText + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Watermarker.SetText(String, String, String) + //ExFor:Watermarker.SetText(String, String, SaveFormat, String) + //ExFor:Watermarker.SetText(String, String, String, TextWatermarkOptions) + //ExFor:Watermarker.SetText(String, String, SaveFormat, String, TextWatermarkOptions) + //ExSummary:Shows how to insert watermark text to the document. + string doc = MyDir + "Big document.docx"; + string watermarkText = "This is a watermark"; + + Watermarker.SetText(doc, ArtifactsDir + "LowCode.WatermarkText.1.docx", watermarkText); + Watermarker.SetText(doc, ArtifactsDir + "LowCode.WatermarkText.2.docx", SaveFormat.Docx, watermarkText); + Watermarker.SetText(doc, ArtifactsDir + "LowCode.WatermarkText.3.docx", watermarkText, new TextWatermarkOptions() { Color = Color.Red }); + Watermarker.SetText(doc, ArtifactsDir + "LowCode.WatermarkText.4.docx", SaveFormat.Docx, watermarkText, new TextWatermarkOptions() { Color = Color.Red }); + //ExEnd:WatermarkText + } + + [Test] + public void WatermarkTextStream() + { + //ExStart:WatermarkTextStream + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Watermarker.SetText(Stream, Stream, SaveFormat, String) + //ExFor:Watermarker.SetText(Stream, Stream, SaveFormat, String, TextWatermarkOptions) + //ExSummary:Shows how to insert watermark text to the document from the stream. + string watermarkText = "This is a watermark"; + + using (FileStream streamIn = new FileStream(MyDir + "Document.docx", FileMode.Open, FileAccess.Read)) + { + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.WatermarkTextStream.1.docx", FileMode.Create, FileAccess.ReadWrite)) + Watermarker.SetText(streamIn, streamOut, SaveFormat.Docx, watermarkText); + + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.WatermarkTextStream.2.docx", FileMode.Create, FileAccess.ReadWrite)) + Watermarker.SetText(streamIn, streamOut, SaveFormat.Docx, watermarkText, new TextWatermarkOptions() { Color = Color.Red }); + } + //ExEnd:WatermarkTextStream + } + + [Test] + public void WatermarkImage() + { + //ExStart:WatermarkImage + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Watermarker.SetImage(String, String, String) + //ExFor:Watermarker.SetImage(String, String, SaveFormat, String) + //ExFor:Watermarker.SetImage(String, String, String, ImageWatermarkOptions) + //ExFor:Watermarker.SetImage(String, String, SaveFormat, String, ImageWatermarkOptions) + //ExSummary:Shows how to insert watermark image to the document. + string doc = MyDir + "Document.docx"; + string watermarkImage = ImageDir + "Logo.jpg"; + + Watermarker.SetImage(doc, ArtifactsDir + "LowCode.SetWatermarkImage.1.docx", watermarkImage); + Watermarker.SetImage(doc, ArtifactsDir + "LowCode.SetWatermarkText.2.docx", SaveFormat.Docx, watermarkImage); + Watermarker.SetImage(doc, ArtifactsDir + "LowCode.SetWatermarkText.3.docx", watermarkImage, new ImageWatermarkOptions() { Scale = 50 }); + Watermarker.SetImage(doc, ArtifactsDir + "LowCode.SetWatermarkText.4.docx", SaveFormat.Docx, watermarkImage, new ImageWatermarkOptions() { Scale = 50 }); + //ExEnd:WatermarkImage + } + + [Test] + public void WatermarkImageStream() + { + //ExStart:WatermarkImageStream + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:Watermarker.SetImage(Stream, Stream, SaveFormat, Image) + //ExFor:Watermarker.SetImage(Stream, Stream, SaveFormat, Image, ImageWatermarkOptions) + //ExSummary:Shows how to insert watermark image to the document from a stream. + using (FileStream streamIn = new FileStream(MyDir + "Document.docx", FileMode.Open, FileAccess.Read)) + { +#if NET461_OR_GREATER || JAVA //ExSkip + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.SetWatermarkText.1.docx", FileMode.Create, FileAccess.ReadWrite)) + Watermarker.SetImage(streamIn, streamOut, SaveFormat.Docx, System.Drawing.Image.FromFile(ImageDir + "Logo.jpg")); +#endif //ExSkip + +#if NET461_OR_GREATER || JAVA //ExSkip + using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.SetWatermarkText.2.docx", FileMode.Create, FileAccess.ReadWrite)) + Watermarker.SetImage(streamIn, streamOut, SaveFormat.Docx, System.Drawing.Image.FromFile(ImageDir + "Logo.jpg"), new ImageWatermarkOptions() { Scale = 50 }); +#endif //ExSkip + } + //ExEnd:WatermarkImageStream + } } } diff --git a/Examples/ApiExamples/ApiExamples/ExMailMerge.cs b/Examples/ApiExamples/ApiExamples/ExMailMerge.cs index 913453b4..4f9c7b7c 100644 --- a/Examples/ApiExamples/ApiExamples/ExMailMerge.cs +++ b/Examples/ApiExamples/ApiExamples/ExMailMerge.cs @@ -1891,5 +1891,35 @@ public void MustacheTags() } //ExEnd } + + [Test] + public void RemoveEmptyTables() + { + //ExStart:RemoveEmptyTables + //GistId:695136dbbe4f541a8a0a17b3d3468689 + //ExFor:MailMergeCleanupOptions + //ExSummary:Shows how to remove whole empty table during mail merge. + DataTable tableCustomers = new DataTable("A"); + tableCustomers.Columns.Add("CustomerID"); + tableCustomers.Columns.Add("CustomerName"); + tableCustomers.Rows.Add(new object[] { 1, "John Doe" }); + tableCustomers.Rows.Add(new object[] { 2, "Jane Doe" }); + + DataSet ds = new DataSet(); + ds.Tables.Add(tableCustomers); + + Document doc = new Document(MyDir + "Mail merge tables.docx"); + Assert.AreEqual(2, doc.GetChildNodes(NodeType.Table, true).Count); + + doc.MailMerge.MergeDuplicateRegions = false; + doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyTables | MailMergeCleanupOptions.RemoveUnusedRegions; + doc.MailMerge.ExecuteWithRegions(ds.Tables["A"]); + + doc.Save(ArtifactsDir + "MailMerge.RemoveEmptyTables.docx"); + + doc = new Document(ArtifactsDir + "MailMerge.RemoveEmptyTables.docx"); + Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count); + //ExEnd:RemoveEmptyTables + } } } diff --git a/Examples/Data/Blank pages.docx b/Examples/Data/Blank pages.docx new file mode 100644 index 00000000..9ca2dd72 Binary files /dev/null and b/Examples/Data/Blank pages.docx differ diff --git a/Examples/Data/Mail merge tables.docx b/Examples/Data/Mail merge tables.docx new file mode 100644 index 00000000..3625c964 Binary files /dev/null and b/Examples/Data/Mail merge tables.docx differ diff --git a/Examples/Data/Mail merge with regions data set.docx b/Examples/Data/Mail merge with regions data set.docx new file mode 100644 index 00000000..f56f02bc Binary files /dev/null and b/Examples/Data/Mail merge with regions data set.docx differ diff --git a/Examples/Data/Mail merge with regions.docx b/Examples/Data/Mail merge with regions.docx new file mode 100644 index 00000000..e205a037 Binary files /dev/null and b/Examples/Data/Mail merge with regions.docx differ diff --git a/Examples/Data/Mail merge.doc b/Examples/Data/Mail merge.doc new file mode 100644 index 00000000..853e2bdd Binary files /dev/null and b/Examples/Data/Mail merge.doc differ diff --git a/Examples/Data/Replace regex.docx b/Examples/Data/Replace regex.docx new file mode 100644 index 00000000..2f1f9dee Binary files /dev/null and b/Examples/Data/Replace regex.docx differ diff --git a/Examples/Data/Report building.docx b/Examples/Data/Report building.docx new file mode 100644 index 00000000..7a0ba377 Binary files /dev/null and b/Examples/Data/Report building.docx differ