Skip to content

Commit

Permalink
Updated documentation examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vderyushev committed Jul 10, 2024
1 parent be15c22 commit 12e1e57
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 61 deletions.
8 changes: 6 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3038,8 +3038,12 @@ public void DoNotIgnoreHeaderFooter()
//ExFor:ImportFormatOptions.IgnoreHeaderFooter
//ExSummary:Shows how to specifies ignoring or not source formatting of headers/footers content.
Document dstDoc = new Document(MyDir + "Document.docx");
Document srcDoc = new Document(MyDir + "Header and footer types.docx");

Document srcDoc = new Document(MyDir + "Header and footer types.docx");

// If 'IgnoreHeaderFooter' is false then the original formatting for header/footer content
// from "Header and footer types.docx" will be used.
// If 'IgnoreHeaderFooter' is true then the formatting for header/footer content
// from "Document.docx" will be used.
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.IgnoreHeaderFooter = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ namespace DocsExamples.File_Formats_and_Conversions.Save_Options
public class WorkingWithImageSaveOptions : DocsExamplesBase
{
[Test]
public void ExposeThresholdControlForTiffBinarization()
public void ExposeThresholdControl()
{
//ExStart:ExposeThresholdControlForTiffBinarization
//ExStart:ExposeThresholdControl
//GistId:b20a0ec0e1ff0556aa20d12f486e1963
Document doc = new Document(MyDir + "Rendering.docx");

ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.Tiff)
Expand All @@ -20,19 +21,21 @@ public void ExposeThresholdControlForTiffBinarization()
ThresholdForFloydSteinbergDithering = 254
};

doc.Save(ArtifactsDir + "WorkingWithImageSaveOptions.ExposeThresholdControlForTiffBinarization.tiff", saveOptions);
//ExEnd:ExposeThresholdControlForTiffBinarization
doc.Save(ArtifactsDir + "WorkingWithImageSaveOptions.ExposeThresholdControl.tiff", saveOptions);
//ExEnd:ExposeThresholdControl
}

[Test]
public void GetTiffPageRange()
{
//ExStart:GetTiffPageRange
//GistId:b20a0ec0e1ff0556aa20d12f486e1963
Document doc = new Document(MyDir + "Rendering.docx");
//ExStart:SaveAsTIFF
//ExStart:SaveAsTiff
//GistId:b20a0ec0e1ff0556aa20d12f486e1963
doc.Save(ArtifactsDir + "WorkingWithImageSaveOptions.MultipageTiff.tiff");
//ExEnd:SaveAsTIFF
//ExEnd:SaveAsTiff

//ExStart:SaveAsTIFFUsingImageSaveOptions
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.Tiff)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Linq;
using Aspose.Words;
using Aspose.Words.DigitalSignatures;
using Aspose.Words.Fields;
using Aspose.Words.Saving;
using NUnit.Framework;

Expand Down Expand Up @@ -375,5 +377,33 @@ public void OptimizeOutput()
doc.Save(ArtifactsDir + "WorkingWithPdfSaveOptions.OptimizeOutput.pdf", saveOptions);
//ExEnd:OptimizeOutput
}

[Test]
public void UpdateScreenTip()
{
//ExStart:UpdateScreenTip
//GistId:8b0ab362f95040ada1255a0473acefe2
Document doc = new Document(MyDir + "Table of contents.docx");

var tocHyperLinks = doc.Range.Fields
.Where(f => f.Type == FieldType.FieldHyperlink)
.Cast<FieldHyperlink>()
.Where(f => f.SubAddress.StartsWith("#_Toc"));

foreach (FieldHyperlink link in tocHyperLinks)
link.ScreenTip = link.DisplayResult;

PdfSaveOptions saveOptions = new PdfSaveOptions()
{
Compliance = PdfCompliance.PdfUa1,
DisplayDocTitle = true,
ExportDocumentStructure = true,
};
saveOptions.OutlineOptions.HeadingsOutlineLevels = 3;
saveOptions.OutlineOptions.CreateMissingOutlineLevels = true;

doc.Save(ArtifactsDir + "WorkingWithPdfSaveOptions.UpdateScreenTip.pdf", saveOptions);
//ExEnd:UpdateScreenTip
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,6 @@ public void SetFontEmphasisMark()
//ExEnd:SetFontEmphasisMark
}

[Test]
public void SetFontsFolders()
{
//ExStart:SetFontsFolders
FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[]
{
new SystemFontSource(), new FolderFontSource("C:\\MyFonts\\", true)
});

Document doc = new Document(MyDir + "Rendering.docx");
doc.Save(ArtifactsDir + "WorkingWithFonts.SetFontsFolders.pdf");
//ExEnd:SetFontsFolders
}

[Test]
public void EnableDisableFontSubstitution()
{
Expand All @@ -137,24 +123,26 @@ public void EnableDisableFontSubstitution()
}

[Test]
public void SetFontFallbackSettings()
public void FontFallbackSettings()
{
//ExStart:SetFontFallbackSettings
//ExStart:FontFallbackSettings
//GistId:a08698f540d47082b4e2dbb1cb67fc1b
Document doc = new Document(MyDir + "Rendering.docx");

FontSettings fontSettings = new FontSettings();
fontSettings.FallbackSettings.Load(MyDir + "Font fallback rules.xml");

doc.FontSettings = fontSettings;

doc.Save(ArtifactsDir + "WorkingWithFonts.SetFontFallbackSettings.pdf");
//ExEnd:SetFontFallbackSettings
doc.Save(ArtifactsDir + "WorkingWithFonts.FontFallbackSettings.pdf");
//ExEnd:FontFallbackSettings
}

[Test]
public void NotoFallbackSettings()
{
//ExStart:SetPredefinedFontFallbackSettings
//ExStart:NotoFallbackSettings
//GistId:a08698f540d47082b4e2dbb1cb67fc1b
Document doc = new Document(MyDir + "Rendering.docx");

FontSettings fontSettings = new FontSettings();
Expand All @@ -163,24 +151,26 @@ public void NotoFallbackSettings()
doc.FontSettings = fontSettings;

doc.Save(ArtifactsDir + "WorkingWithFonts.NotoFallbackSettings.pdf");
//ExEnd:SetPredefinedFontFallbackSettings
//ExEnd:NotoFallbackSettings
}

[Test]
public void SetFontsFoldersDefaultInstance()
public void DefaultInstance()
{
//ExStart:SetFontsFoldersDefaultInstance
//ExStart:DefaultInstance
//GistId:7e64f6d40825be58a8c12f1307c12964
FontSettings.DefaultInstance.SetFontsFolder("C:\\MyFonts\\", true);
//ExEnd:SetFontsFoldersDefaultInstance
//ExEnd:DefaultInstance

Document doc = new Document(MyDir + "Rendering.docx");
doc.Save(ArtifactsDir + "WorkingWithFonts.SetFontsFoldersDefaultInstance.pdf");
doc.Save(ArtifactsDir + "WorkingWithFonts.DefaultInstance.pdf");
}

[Test]
public void SetFontsFoldersMultipleFolders()
public void MultipleFolders()
{
//ExStart:SetFontsFoldersMultipleFolders
//ExStart:MultipleFolders
//GistId:7e64f6d40825be58a8c12f1307c12964
Document doc = new Document(MyDir + "Rendering.docx");

FontSettings fontSettings = new FontSettings();
Expand All @@ -191,8 +181,8 @@ public void SetFontsFoldersMultipleFolders()

doc.FontSettings = fontSettings;

doc.Save(ArtifactsDir + "WorkingWithFonts.SetFontsFoldersMultipleFolders.pdf");
//ExEnd:SetFontsFoldersMultipleFolders
doc.Save(ArtifactsDir + "WorkingWithFonts.MultipleFolders.pdf");
//ExEnd:MultipleFolders
}

[Test]
Expand Down Expand Up @@ -223,23 +213,25 @@ public void SetFontsFoldersSystemAndCustomFolder()
}

[Test]
public void SetFontsFoldersWithPriority()
public void FontsFoldersWithPriority()
{
//ExStart:SetFontsFoldersWithPriority
//ExStart:FontsFoldersWithPriority
//GistId:7e64f6d40825be58a8c12f1307c12964
FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[]
{
new SystemFontSource(), new FolderFontSource("C:\\MyFonts\\", true,1)
new SystemFontSource(), new FolderFontSource("C:\\MyFonts\\", true, 1)
});
//ExEnd:SetFontsFoldersWithPriority
//ExEnd:FontsFoldersWithPriority

Document doc = new Document(MyDir + "Rendering.docx");
doc.Save(ArtifactsDir + "WorkingWithFonts.SetFontsFoldersWithPriority.pdf");
doc.Save(ArtifactsDir + "WorkingWithFonts.FontsFoldersWithPriority.pdf");
}

[Test]
public void SetTrueTypeFontsFolder()
public void TrueTypeFontsFolder()
{
//ExStart:SetTrueTypeFontsFolder
//ExStart:TrueTypeFontsFolder
//GistId:7e64f6d40825be58a8c12f1307c12964
Document doc = new Document(MyDir + "Rendering.docx");

FontSettings fontSettings = new FontSettings();
Expand All @@ -250,8 +242,8 @@ public void SetTrueTypeFontsFolder()
// Set font settings
doc.FontSettings = fontSettings;

doc.Save(ArtifactsDir + "WorkingWithFonts.SetTrueTypeFontsFolder.pdf");
//ExEnd:SetTrueTypeFontsFolder
doc.Save(ArtifactsDir + "WorkingWithFonts.TrueTypeFontsFolder.pdf");
//ExEnd:TrueTypeFontsFolder
}

[Test]
Expand Down Expand Up @@ -303,39 +295,44 @@ public void SetFontsFolder()
}

[Test]
public void FontSettingsWithLoadOption()
public void LoadOptionFontSettings()
{
//ExStart:FontSettingsWithLoadOption
//ExStart:LoadOptionFontSettings
//GistId:a08698f540d47082b4e2dbb1cb67fc1b
LoadOptions loadOptions = new LoadOptions();
loadOptions.FontSettings = new FontSettings();

Document doc = new Document(MyDir + "Rendering.docx", loadOptions);
//ExEnd:FontSettingsWithLoadOption
//ExEnd:LoadOptionFontSettings
}

[Test]
public void FontSettingsDefaultInstance()
{
//ExStart:FontsFolders
//GistId:7e64f6d40825be58a8c12f1307c12964
//ExStart:FontSettingsFontSource
//GistId:a08698f540d47082b4e2dbb1cb67fc1b
//ExStart:FontSettingsDefaultInstance
//GistId:a08698f540d47082b4e2dbb1cb67fc1b
FontSettings fontSettings = FontSettings.DefaultInstance;
//ExEnd:FontSettingsDefaultInstance
//ExEnd:FontSettingsDefaultInstance
fontSettings.SetFontsSources(new FontSourceBase[]
{
new SystemFontSource(),
new FolderFontSource("C:\\MyFonts\\", true)
});
//ExEnd:FontSettingsFontSource

LoadOptions loadOptions = new LoadOptions();
loadOptions.FontSettings = fontSettings;
Document doc = new Document(MyDir + "Rendering.docx", loadOptions);
Document doc = new Document(MyDir + "Rendering.docx");
//ExEnd:FontsFolders
}

[Test]
public void GetListOfAvailableFonts()
public void AvailableFonts()
{
//ExStart:GetListOfAvailableFonts
//ExStart:AvailableFonts
//GistId:7e64f6d40825be58a8c12f1307c12964
FontSettings fontSettings = new FontSettings();
List<FontSourceBase> fontSources = new List<FontSourceBase>(fontSettings.GetFontsSources());

Expand All @@ -353,7 +350,7 @@ public void GetListOfAvailableFonts()
Console.WriteLine("Version : " + fontInfo.Version);
Console.WriteLine("FilePath : " + fontInfo.FilePath);
}
//ExEnd:GetListOfAvailableFonts
//ExEnd:AvailableFonts
}

[Test]
Expand Down Expand Up @@ -418,16 +415,17 @@ public void Warning(WarningInfo info)
}
//ExEnd:HandleDocumentWarnings

//ExStart:ResourceSteamFontSourceExample
[Test]
public void ResourceSteamFontSourceExample()
//ExStart:ResourceSteam
//GistId:7e64f6d40825be58a8c12f1307c12964
public void ResourceSteam()
{
Document doc = new Document(MyDir + "Rendering.docx");

FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[]
{ new SystemFontSource(), new ResourceSteamFontSource() });

doc.Save(ArtifactsDir + "WorkingWithFonts.SetFontsFolders.pdf");
doc.Save(ArtifactsDir + "WorkingWithFonts.ResourceSteam.pdf");
}

internal class ResourceSteamFontSource : StreamFontSource
Expand All @@ -437,10 +435,11 @@ public override Stream OpenFontDataStream()
return Assembly.GetExecutingAssembly().GetManifestResourceStream("resourceName");
}
}
//ExEnd:ResourceSteamFontSourceExample
//ExEnd:ResourceSteam

//ExStart:GetSubstitutionWithoutSuffixes
[Test]
//ExStart:GetSubstitutionWithoutSuffixes
//GistId:a08698f540d47082b4e2dbb1cb67fc1b
public void GetSubstitutionWithoutSuffixes()
{
Document doc = new Document(MyDir + "Get substitution without suffixes.docx");
Expand Down

0 comments on commit 12e1e57

Please sign in to comment.