Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
falleretic committed Nov 2, 2023
1 parent 18baa3f commit f112a99
Show file tree
Hide file tree
Showing 21 changed files with 172 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Examples/ApiExamples/ApiExamples/CustomBarcodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public Image GetBarcodeImage(BarcodeParameters parameters)
generator.Parameters.AutoSizeMode = AutoSizeMode.None;
}

#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
return generator.GenerateBarCodeImage();
#elif NET5_0_OR_GREATER
generator.GenerateBarCodeImage().Save(ArtifactsDir + "GetBarcodeImage.png");
Expand All @@ -200,7 +200,7 @@ public Image GetOldBarcodeImage(BarcodeParameters parameters)
};

// Hardcode type for old-fashioned Barcode
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
return generator.GenerateBarCodeImage();
#elif NET5_0_OR_GREATER
generator.GenerateBarCodeImage().Save(ArtifactsDir + "OldBarcodeImage.png");
Expand Down
30 changes: 23 additions & 7 deletions Examples/ApiExamples/ApiExamples/ExCharts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2001-2023 Aspose Pty Ltd. All Rights Reserved.
// Copyright (c) 2001-2023 Aspose Pty Ltd. All Rights Reserved.
//
// This file is part of Aspose.Words. The source code in this file
// is only intended as a supplement to the documentation, and is provided
Expand Down Expand Up @@ -1280,7 +1280,6 @@ public void LegendEntries()
//ExFor:ChartLegendEntryCollection
//ExFor:ChartLegend.LegendEntries
//ExFor:ChartLegendEntry.IsHidden
//ExFor:ChartLegendEntry.Font
//ExSummary:Shows how to work with a legend entry for chart series.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Expand All @@ -1301,15 +1300,32 @@ public void LegendEntries()
ChartLegendEntryCollection legendEntries = chart.Legend.LegendEntries;
legendEntries[3].IsHidden = true;

foreach (ChartLegendEntry legendEntry in legendEntries)
legendEntry.Font.Size = 12;

series1.LegendEntry.Font.Italic = true;

doc.Save(ArtifactsDir + "Charts.LegendEntries.docx");
//ExEnd
}

[Test]
public void LegendFont()
{
//ExStart:LegendFont
//ReleaseVersion:23.11
//ExFor:ChartLegendEntry.Font
//ExFor:ChartLegend.Font
//ExSummary:Shows how to work with a legend font.
Document doc = new Document(MyDir + "Reporting engine template - Chart series.docx");
Chart chart = ((Shape)doc.GetChild(NodeType.Shape, 0, true)).Chart;

ChartLegend chartLegend = chart.Legend;
// Set default font size all legend entries.
chartLegend.Font.Size = 14;
// Change font for specific legend entry.
chartLegend.LegendEntries[1].Font.Italic = true;
chartLegend.LegendEntries[1].Font.Size = 12;

doc.Save(ArtifactsDir + "Charts.LegendFont.docx");
//ExEnd:LegendFont
}

[Test]
public void RemoveSpecificChartSeries()
{
Expand Down
4 changes: 2 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void SaveToImageStream()

builder.InsertImage(ImageDir + "Logo.jpg");

#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
using (MemoryStream stream = new MemoryStream())
{
doc.Save(stream, SaveFormat.Bmp);
Expand Down Expand Up @@ -2639,7 +2639,7 @@ public void ImageWatermark()
imageWatermarkOptions.Scale = 5;
imageWatermarkOptions.IsWashout = false;

#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
doc.Watermark.SetImage(Image.FromFile(ImageDir + "Logo.jpg"), imageWatermarkOptions);
#elif NET5_0_OR_GREATER
using (SKBitmap image = SKBitmap.Decode(ImageDir + "Logo.jpg"))
Expand Down
6 changes: 3 additions & 3 deletions Examples/ApiExamples/ApiExamples/ExDrawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using Aspose.Words.Drawing;
using NUnit.Framework;
using Shape = Aspose.Words.Drawing.Shape;
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
using System.Drawing.Imaging;
#endif

Expand All @@ -24,7 +24,7 @@ namespace ApiExamples
[TestFixture]
public class ExDrawing : ApiExampleBase
{
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
[Test]
public void VariousShapes()
{
Expand Down Expand Up @@ -299,7 +299,7 @@ public void SaveAllImages()
Assert.AreEqual(".Jpeg", fileInfos[0].Extension);
TestUtil.VerifyImage(400, 400, fileInfos[1].FullName);
Assert.AreEqual(".Png", fileInfos[1].Extension);
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
TestUtil.VerifyImage(382, 138, fileInfos[2].FullName);
Assert.AreEqual(".Emf", fileInfos[2].Extension);
TestUtil.VerifyImage(1600, 1600, fileInfos[3].FullName);
Expand Down
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ExField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,7 @@ void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
{
if (mImageFilenames.ContainsKey(args.FieldValue.ToString()))
{
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
args.Image = Image.FromFile(mImageFilenames[args.FieldValue.ToString()]);
#elif NET5_0_OR_GREATER
args.Image = SKBitmap.Decode(mImageFilenames[args.FieldValue.ToString()]);
Expand Down
8 changes: 4 additions & 4 deletions Examples/ApiExamples/ApiExamples/ExFieldOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public void BarcodeGenerator()
};

Image img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
img.Save(ArtifactsDir + "FieldOptions.BarcodeGenerator.QR.jpg");
#elif NET5_0_OR_GREATER
using (SKFileWStream fs = new SKFileWStream(ArtifactsDir + "FieldOptions.BarcodeGenerator.QR.jpg"))
Expand All @@ -457,7 +457,7 @@ public void BarcodeGenerator()
};

img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
img.Save(ArtifactsDir + "FieldOptions.BarcodeGenerator.EAN13.jpg");
#elif NET5_0_OR_GREATER
using (SKFileWStream fs = new SKFileWStream(ArtifactsDir + "FieldOptions.BarcodeGenerator.EAN13.jpg"))
Expand All @@ -476,7 +476,7 @@ public void BarcodeGenerator()
};

img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
img.Save(ArtifactsDir + "FieldOptions.BarcodeGenerator.CODE39.jpg");
#elif NET5_0_OR_GREATER
using (SKFileWStream fs = new SKFileWStream(ArtifactsDir + "FieldOptions.BarcodeGenerator.CODE39.jpg"))
Expand All @@ -495,7 +495,7 @@ public void BarcodeGenerator()
};

img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
img.Save(ArtifactsDir + "FieldOptions.BarcodeGenerator.ITF14.jpg");
#elif NET5_0_OR_GREATER
using (SKFileWStream fs = new SKFileWStream(ArtifactsDir + "FieldOptions.BarcodeGenerator.ITF14.jpg"))
Expand Down
10 changes: 5 additions & 5 deletions Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void ExportTextBoxAsSvgEpub(SaveFormat saveFormat, bool isTextBoxAsSvg)
public void CreateAZW3Toc()
{
//ExStart
//ExFor:HtmlSaveOptions.EpubNavigationMapLevel
//ExFor:HtmlSaveOptions.NavigationMapLevel
//ExSummary:Shows how to generate table of contents for Azw3 documents.
Document doc = new Document(MyDir + "Big document.docx");

Expand All @@ -146,7 +146,7 @@ public void CreateAZW3Toc()
public void CreateMobiToc()
{
//ExStart
//ExFor:HtmlSaveOptions.EpubNavigationMapLevel
//ExFor:HtmlSaveOptions.NavigationMapLevel
//ExSummary:Shows how to generate table of contents for Mobi documents.
Document doc = new Document(MyDir + "Big document.docx");

Expand Down Expand Up @@ -834,7 +834,7 @@ public void ExportXhtmlTransitional(bool showDoctypeDeclaration)
public void EpubHeadings()
{
//ExStart
//ExFor:HtmlSaveOptions.EpubNavigationMapLevel
//ExFor:HtmlSaveOptions.NavigationMapLevel
//ExSummary:Shows how to filter headings that appear in the navigation panel of a saved Epub document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Expand All @@ -857,7 +857,7 @@ public void EpubHeadings()

// Epub readers typically create a table of contents for their documents.
// Each paragraph with a "Heading" style in the document will create an entry in this table of contents.
// We can use the "EpubNavigationMapLevel" property to set a maximum heading level.
// We can use the "NavigationMapLevel" property to set a maximum heading level.
// The Epub reader will not add headings with a level above the one we specify to the contents table.
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Epub);
options.NavigationMapLevel = 2;
Expand Down Expand Up @@ -1744,7 +1744,7 @@ public void ScaleImageToShapeSize(bool scaleImageToShapeSize)
var testedImageLength = new FileInfo(ArtifactsDir + "HtmlSaveOptions.ScaleImageToShapeSize.001.png").Length;

if (scaleImageToShapeSize)
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
Assert.That(testedImageLength, Is.LessThan(3000));
#elif NET5_0_OR_GREATER
Assert.That(testedImageLength, Is.LessThan(6000));
Expand Down
4 changes: 2 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExHyphenation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public void Dictionary()
TextAbsorber textAbsorber = new TextAbsorber();
textAbsorber.Visit(pdfDoc);

Assert.True(textAbsorber.Text.Contains($"La ob storen an deinen am sachen. Dop-{Environment.NewLine}" +
Assert.True(textAbsorber.Text.Replace(" ", " ").Contains($"La ob storen an deinen am sachen. Dop-{Environment.NewLine}" +
$"pelte um da am spateren verlogen ge-{Environment.NewLine}" +
$"kommen achtzehn blaulich."));

pdfDoc = new Aspose.Pdf.Document(ArtifactsDir + "Hyphenation.Dictionary.Unregistered.pdf");
textAbsorber = new TextAbsorber();
textAbsorber.Visit(pdfDoc);

Assert.True(textAbsorber.Text.Contains($"La ob storen an deinen am sachen. {Environment.NewLine}" +
Assert.True(textAbsorber.Text.Replace(" ", " ").Contains($"La ob storen an deinen am sachen. {Environment.NewLine}" +
$"Doppelte um da am spateren verlogen {Environment.NewLine}" +
$"gekommen achtzehn blaulich."));
}
Expand Down
12 changes: 6 additions & 6 deletions Examples/ApiExamples/ApiExamples/ExImageSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using Aspose.Words.Saving;
using NUnit.Framework;
using Aspose.Words.Drawing;
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
using System.Drawing.Drawing2D;
using System.Drawing.Text;
#elif NET5_0_OR_GREATER || __MOBILE__
Expand Down Expand Up @@ -120,7 +120,7 @@ public void PageSet()
Assert.False(File.Exists(ArtifactsDir + "ImageSaveOptions.PageIndex.Page 4.gif"));
}

#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
[Test]
public void GraphicsQuality()
{
Expand Down Expand Up @@ -245,7 +245,7 @@ public void PageByPage()
.Where(item => item.Contains("ImageSaveOptions.PageByPage.") && item.EndsWith(".tiff")).ToList();

Assert.AreEqual(3, imageFileNames.Count);
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
foreach (string imageFileName in imageFileNames)
TestUtil.VerifyImage(2325, 5325, imageFileName);
#endif
Expand Down Expand Up @@ -283,7 +283,7 @@ public void ColorMode(ImageColorMode imageColorMode)

var testedImageLength = new FileInfo(ArtifactsDir + "ImageSaveOptions.ColorMode.png").Length;

#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
switch (imageColorMode)
{
case ImageColorMode.None:
Expand Down Expand Up @@ -387,7 +387,7 @@ public void PixelFormat(ImagePixelFormat imagePixelFormat)

var testedImageLength = new FileInfo(ArtifactsDir + "ImageSaveOptions.PixelFormat.png").Length;

#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
switch (imagePixelFormat)
{
case ImagePixelFormat.Format1bppIndexed:
Expand Down Expand Up @@ -465,7 +465,7 @@ public void FloydSteinbergDithering()
doc.Save(ArtifactsDir + "ImageSaveOptions.FloydSteinbergDithering.tiff", options);
//ExEnd

#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
TestUtil.VerifyImage(816, 1056, ArtifactsDir + "ImageSaveOptions.FloydSteinbergDithering.tiff");
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ExMailMerge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ApiExamples
[TestFixture]
public class ExMailMerge : ApiExampleBase
{
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
[Test]
public void ExecuteArray()
{
Expand Down
8 changes: 4 additions & 4 deletions Examples/ApiExamples/ApiExamples/ExOoxmlSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,16 @@ public void DocumentCompression(CompressionLevel compressionLevel)
switch (compressionLevel)
{
case CompressionLevel.Maximum:
Assert.That(testedFileLength, Is.LessThan(1266000));
Assert.That(testedFileLength, Is.LessThan(1269000));
break;
case CompressionLevel.Normal:
Assert.That(testedFileLength, Is.LessThan(1267000));
Assert.That(testedFileLength, Is.LessThan(1271000));
break;
case CompressionLevel.Fast:
Assert.That(testedFileLength, Is.LessThan(1270000));
Assert.That(testedFileLength, Is.LessThan(1280000));
break;
case CompressionLevel.SuperFast:
Assert.That(testedFileLength, Is.LessThan(1272000));
Assert.That(testedFileLength, Is.LessThan(1276000));
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExParagraphFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,11 @@ public void SuppressHyphens(bool suppressAutoHyphens)
textAbsorber.Visit(pdfDoc);

if (suppressAutoHyphens)
Assert.True(textAbsorber.Text.Contains($"La ob storen an deinen am sachen. {Environment.NewLine}" +
Assert.True(textAbsorber.Text.Replace(" ", " ").Contains($"La ob storen an deinen am sachen. {Environment.NewLine}" +
$"Doppelte um da am spateren verlogen {Environment.NewLine}" +
$"gekommen achtzehn blaulich."));
else
Assert.True(textAbsorber.Text.Contains($"La ob storen an deinen am sachen. Dop-{Environment.NewLine}" +
Assert.True(textAbsorber.Text.Replace(" ", " ").Contains($"La ob storen an deinen am sachen. Dop-{Environment.NewLine}" +
$"pelte um da am spateren verlogen ge-{Environment.NewLine}" +
$"kommen achtzehn blaulich."));
}
Expand Down
4 changes: 2 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExPrinting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using System;
using NUnit.Framework;
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
using System.Drawing.Printing;
using System.Windows.Forms;
using Aspose.Words;
Expand All @@ -19,7 +19,7 @@ namespace ApiExamples
[TestFixture]
public class ExPrinting : ApiExampleBase
{
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
[Test, Ignore("Run only when the printer driver is installed.")]
public void CustomPrint()
{
Expand Down
4 changes: 2 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Aspose.Words.Drawing.Charts;
using Aspose.Words.Rendering;
using NUnit.Framework;
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing.Text;
Expand All @@ -25,7 +25,7 @@ namespace ApiExamples
[TestFixture]
public class ExRendering : ApiExampleBase
{
#if NET48 || JAVA
#if NET461_OR_GREATER || JAVA
//ExStart
//ExFor:NodeRendererBase.RenderToScale(Graphics, Single, Single, Single)
//ExFor:NodeRendererBase.RenderToSize(Graphics, Single, Single, Single, Single)
Expand Down
17 changes: 17 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExReportingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,23 @@ public void InsertComboboxDropdownListItemsDynamically(SdtType sdtType)
}
}

[Test]
public void UpdateFieldsSyntaxAware()
{
//ExStart:UpdateFieldsSyntaxAware
//ReleaseVersion:23.11
Document doc = new Document(MyDir + "Reporting engine template - Fields.docx");

// Note that enabling of the option makes the engine to update fields while building a report,
// so there is no need to update fields separately after that.
ReportingEngine engine = new ReportingEngine();
BuildReport(doc, new string[] { "First topic", "Second topic", "Third topic" }, "topics",
ReportBuildOptions.UpdateFieldsSyntaxAware);

doc.Save(ArtifactsDir + "ReportingEngine.UpdateFieldsSyntaxAware.docx");
//ExEnd:UpdateFieldsSyntaxAware
}

private static void BuildReport(Document document, object dataSource, ReportBuildOptions reportBuildOptions)
{
ReportingEngine engine = new ReportingEngine { Options = reportBuildOptions };
Expand Down
Loading

0 comments on commit f112a99

Please sign in to comment.