Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
falleretic committed Nov 29, 2023
1 parent d56734e commit 38e2423
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ApiExampleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static ApiExampleBase()
ImageDir = new Uri(new Uri(CodeBaseDir), @"Data/Images/").LocalPath;
DatabaseDir = new Uri(new Uri(CodeBaseDir), @"Data/Database/").LocalPath;
FontsDir = new Uri(new Uri(CodeBaseDir), @"Data/MyFonts/").LocalPath;
ImageUrl = new Uri("https://www.aspose.cloud/templates/aspose/img/products/words/aspose_words.svg").AbsoluteUri;
ImageUrl = new Uri("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png").AbsoluteUri;
}
}
}
34 changes: 33 additions & 1 deletion Examples/ApiExamples/ApiExamples/ExImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void FromUrl()

Assert.AreEqual(2, shapes.Count);
TestUtil.VerifyImageInShape(400, 400, ImageType.Jpeg, (Shape)shapes[0]);
TestUtil.VerifyImageInShape(252, 213, ImageType.Png, (Shape)shapes[1]);
TestUtil.VerifyImageInShape(272, 92, ImageType.Png, (Shape)shapes[1]);
}

[Test]
Expand Down Expand Up @@ -411,5 +411,37 @@ public void ScaleImage()
Assert.AreEqual(300.0d, imageSize.WidthPoints);
Assert.AreEqual(300.0d, imageSize.HeightPoints);
}

#if NET5_0_OR_GREATER
[Test]
public void InsertWebpImage()
{
//ExStart:InsertWebpImage
//ReleaseVersion:23.12
//ExFor:DocumentBuilder.InsertImage(String)
//ExSummary:Shows how to insert WebP image (only .NetStandard)
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertImage(ImageDir + "WebP image.webp");

doc.Save(ArtifactsDir + "Image.InsertWebpImage.docx");
//ExEnd:InsertWebpImage
}

[Test]
public void ReadWebpImage()
{
//ExStart:ReadWebpImage
//ReleaseVersion:23.12
//ExFor:ImageType
//ExSummary:Shows how to read WebP image (only .NetStandard)
Document doc = new Document(MyDir + "Document with WebP image.docx");

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
Assert.AreEqual(ImageType.WebP, shape.ImageData.ImageType);
//ExEnd:ReadWebpImage
}
#endif
}
}
25 changes: 24 additions & 1 deletion Examples/ApiExamples/ApiExamples/ExLowCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// "as is", without warranty of any kind, either expressed or implied.
//////////////////////////////////////////////////////////////////////////

using System;
using System.Drawing;
using System.IO;
using Aspose.Words;
using Aspose.Words.LowCode;
Expand All @@ -17,7 +19,7 @@ namespace ApiExamples
class ExLowCode : ApiExampleBase
{
[Test]
public void MergeDocument()
public void MergeDocuments()
{
//ExStart
//ExFor:Merger.Merge(String, String[])
Expand Down Expand Up @@ -62,5 +64,26 @@ public void MergeStreamDocument()
}
//ExEnd
}

[Test]
public void MergeDocumentInstances()
{
//ExStart:MergeDocumentInstances
//ReleaseVersion:23.12
//ExFor:Merger.Merge(Document[], MergeFormatMode)
//ExSummary:Shows how to merge input documents to a single document instance.
DocumentBuilder firstDoc = new DocumentBuilder();
firstDoc.Font.Size = 16;
firstDoc.Font.Color = Color.Blue;
firstDoc.Write("Hello first word!");

DocumentBuilder secondDoc = new DocumentBuilder();
secondDoc.Write("Hello second word!");

Document mergedDoc = Merger.Merge(new Document[] { firstDoc.Document, secondDoc.Document }, MergeFormatMode.KeepSourceLayout);

Assert.AreEqual("Hello first word!\fHello second word!\f", mergedDoc.GetText());
//ExEnd:MergeDocumentInstances
}
}
}
31 changes: 31 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExOoxmlSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using Aspose.Words;
using Aspose.Words.Drawing;
Expand Down Expand Up @@ -371,5 +372,35 @@ public void Notify(DocumentSavingArgs args)
private const double MaxDuration = 0.01d;
}
//ExEnd

[Test]
public void Zip64ModeOption()
{
//ExStart:Zip64ModeOption
//ReleaseVersion:23.12
//ExFor:OoxmlSaveOptions.Zip64Mode
//ExFor:Zip64Mode
//ExSummary:Shows how to use ZIP64 format extensions.
Random random = new Random();
DocumentBuilder builder = new DocumentBuilder();

for (int i = 0; i < 10000; i++)
{
using (Bitmap bmp = new Bitmap(5, 5))
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(Color.FromArgb(random.Next(0, 254), random.Next(0, 254), random.Next(0, 254)));
using (MemoryStream ms = new MemoryStream())
{
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
builder.InsertImage(ms.ToArray());
}
}
}

builder.Document.Save(ArtifactsDir + "OoxmlSaveOptions.Zip64ModeOption.docx",
new OoxmlSaveOptions { Zip64Mode = Zip64Mode.Always });
//ExEnd:Zip64ModeOption
}
}
}
18 changes: 18 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExPdfSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2309,5 +2309,23 @@ public void ExportParagraphGraphicsToArtifact()
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(ArtifactsDir + "PdfSaveOptions.ExportParagraphGraphicsToArtifact.pdf");
Assert.AreEqual(3, pdfDocument.Pages[1].Artifacts.Count());
}

[Test]
public void PageLayout()
{
//ExStart:PageLayout
//ReleaseVersion:23.12
//ExFor:PdfSaveOptions.PageLayout
//ExFor:PdfPageLayout
//ExSummary:Shows how to display pages when opened in a PDF reader.
Document doc = new Document(MyDir + "Big document.docx");

// Display the pages two at a time, with odd-numbered pages on the left.
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.PageLayout = PdfPageLayout.TwoPageLeft;

doc.Save(ArtifactsDir + "PdfSaveOptions.PageLayout.pdf", saveOptions);
//ExEnd:PageLayout
}
}
}
30 changes: 27 additions & 3 deletions Examples/ApiExamples/ApiExamples/ExReportingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using NUnit.Framework;
#if NET5_0_OR_GREATER || __MOBILE__
using SkiaSharp;
using static System.Runtime.InteropServices.JavaScript.JSType;
#endif

namespace ApiExamples
Expand Down Expand Up @@ -1187,12 +1188,35 @@ public void UpdateFieldsSyntaxAware()
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();
// so there is no need to update fields separately after that.
BuildReport(doc, new string[] { "First topic", "Second topic", "Third topic" }, "topics",
ReportBuildOptions.UpdateFieldsSyntaxAware);

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

[Test]
public void DollarTextFormat()
{
//ExStart:DollarTextFormat
//ReleaseVersion:23.12
//ExFor:ReportingEngine.BuildReport(Document, object, string)
//ExSummary:Shows how to display values as dollar text.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("<<[ds.Value1]:dollarText>>\r<<[ds.Value2]:dollarText>>");

NumericTestClass testData = new NumericTestBuilder().WithValues(1234, 5621718.589).Build();

ReportingEngine report = new ReportingEngine();
report.KnownTypes.Add(typeof(NumericTestClass));
report.BuildReport(doc, testData, "ds");

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

Assert.AreEqual("one thousand two hundred thirty-four and 00/100\rfive million six hundred twenty-one thousand seven hundred eighteen and 59/100\r\f", doc.GetText());
}

private static void BuildReport(Document document, object dataSource, ReportBuildOptions reportBuildOptions)
Expand Down
Loading

0 comments on commit 38e2423

Please sign in to comment.