From 12e1e571d8e80506e71c5e96bf375f3f7fb8dcf4 Mon Sep 17 00:00:00 2001 From: vderyushev Date: Wed, 10 Jul 2024 13:54:37 +0300 Subject: [PATCH] Updated documentation examples --- .../ApiExamples/ExDocumentBuilder.cs | 8 +- .../Working with ImageSaveOptions.cs | 17 +-- .../Working with PdfSaveOptions.cs | 30 +++++ .../Working with Fonts.cs | 103 +++++++++--------- 4 files changed, 97 insertions(+), 61 deletions(-) diff --git a/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs b/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs index 3db7bef32..0a7f257d5 100644 --- a/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs +++ b/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs @@ -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; diff --git a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with ImageSaveOptions.cs b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with ImageSaveOptions.cs index 832eeea1c..968445ba4 100644 --- a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with ImageSaveOptions.cs +++ b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with ImageSaveOptions.cs @@ -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) @@ -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) { diff --git a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with PdfSaveOptions.cs b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with PdfSaveOptions.cs index 8a4cdee84..c0b657965 100644 --- a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with PdfSaveOptions.cs +++ b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with PdfSaveOptions.cs @@ -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; @@ -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() + .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 + } } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fonts.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fonts.cs index b6205a0e4..9de63daff 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fonts.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fonts.cs @@ -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() { @@ -137,9 +123,10 @@ 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(); @@ -147,14 +134,15 @@ public void SetFontFallbackSettings() 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(); @@ -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(); @@ -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] @@ -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(); @@ -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] @@ -303,23 +295,28 @@ 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(), @@ -327,15 +324,15 @@ public void FontSettingsDefaultInstance() }); //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 fontSources = new List(fontSettings.GetFontsSources()); @@ -353,7 +350,7 @@ public void GetListOfAvailableFonts() Console.WriteLine("Version : " + fontInfo.Version); Console.WriteLine("FilePath : " + fontInfo.FilePath); } - //ExEnd:GetListOfAvailableFonts + //ExEnd:AvailableFonts } [Test] @@ -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 @@ -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");