public static void Run()
        {
            //ExStart:SetFontsFoldersSystemAndCustomFolder
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting();

            Document     doc          = new Document(dataDir + "Rendering.doc");
            FontSettings FontSettings = new FontSettings();

            // Retrieve the array of environment-dependent font sources that are searched by default. For example this will contain a "Windows\Fonts\" source on a Windows machines.
            // We add this array to a new ArrayList to make adding or removing font entries much easier.
            ArrayList fontSources = new ArrayList(FontSettings.GetFontsSources());

            // Add a new folder source which will instruct Aspose.Words to search the following folder for fonts.
            FolderFontSource folderFontSource = new FolderFontSource("C:\\MyFonts\\", true);

            // Add the custom folder which contains our fonts to the list of existing font sources.
            fontSources.Add(folderFontSource);

            // Convert the Arraylist of source back into a primitive array of FontSource objects.
            FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));

            // Apply the new set of font sources to use.
            FontSettings.SetFontsSources(updatedFontSources);
            dataDir = dataDir + "Rendering.SetFontsFolders_out_.pdf";
            doc.Save(dataDir);
            //ExEnd:SetFontsFoldersSystemAndCustomFolder
            Console.WriteLine("\nFonts system and coustom folder is setup.\nFile saved at " + dataDir);
        }
Esempio n. 2
0
        public static void GetListOfAvailableFonts(string dataDir)
        {
            // ExStart:GetListOfAvailableFonts
            // The path to the documents directory.
            Document doc = new Document(dataDir + "TestFile.docx");

            FontSettings fontSettings = new FontSettings();
            ArrayList    fontSources  = new ArrayList(fontSettings.GetFontsSources());

            // Add a new folder source which will instruct Aspose.Words to search the following folder for fonts.
            FolderFontSource folderFontSource = new FolderFontSource(dataDir, true);

            // Add the custom folder which contains our fonts to the list of existing font sources.
            fontSources.Add(folderFontSource);

            // Convert the Arraylist of source back into a primitive array of FontSource objects.
            FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));

            foreach (PhysicalFontInfo fontInfo in updatedFontSources[0].GetAvailableFonts())
            {
                Console.WriteLine("FontFamilyName : " + fontInfo.FontFamilyName);
                Console.WriteLine("FullFontName  : " + fontInfo.FullFontName);
                Console.WriteLine("Version  : " + fontInfo.Version);
                Console.WriteLine("FilePath : " + fontInfo.FilePath);
            }

            // ExEnd:GetListOfAvailableFonts
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                ImportLicense();

                var folderFontSource = new FolderFontSource("./fonts", true);
                var fontSettings     = new FontSettings();
                fontSettings.SetFontsSources(new FontSourceBase[]
                {
                    new SystemFontSource(),
                    folderFontSource
                });

                var loadOptions = new LoadOptions {
                    FontSettings = fontSettings
                };
                var wrdf = new Aspose.Words.Document("./input.html", loadOptions);
                var Dir  = "./output/";
                if (Directory.Exists(Dir))
                {
                    Directory.Delete(Dir, true);
                }

                Aspose.Words.Saving.PdfSaveOptions pdfSaveOptions = new Aspose.Words.Saving.PdfSaveOptions {
                    FontEmbeddingMode = Aspose.Words.Saving.PdfFontEmbeddingMode.EmbedAll
                };
                wrdf.Save(Dir + "output.pdf", pdfSaveOptions);
                wrdf.Save(Dir + "output.jpeg", Aspose.Words.SaveFormat.Jpeg);
                wrdf.Save(Dir + "output.html", Aspose.Words.SaveFormat.Html);
                wrdf.Save(Dir + "output.docx", Aspose.Words.SaveFormat.Docx);
            }
        }
        public static void Run()
        {
            // ExStart:SetFontsFoldersSystemAndCustomFolder
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting(); 

            Document doc = new Document(dataDir + "Rendering.doc");
            FontSettings FontSettings = new FontSettings();

            // Retrieve the array of environment-dependent font sources that are searched by default. For example this will contain a "Windows\Fonts\" source on a Windows machines.
            // We add this array to a new ArrayList to make adding or removing font entries much easier.
            ArrayList fontSources = new ArrayList(FontSettings.GetFontsSources());

            // Add a new folder source which will instruct Aspose.Words to search the following folder for fonts.
            FolderFontSource folderFontSource = new FolderFontSource("C:\\MyFonts\\", true);

            // Add the custom folder which contains our fonts to the list of existing font sources.
            fontSources.Add(folderFontSource);

            // Convert the Arraylist of source back into a primitive array of FontSource objects.
            FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));
            
            // Apply the new set of font sources to use.
            FontSettings.SetFontsSources(updatedFontSources);
            // Set font settings
            doc.FontSettings = FontSettings;
            dataDir = dataDir + "Rendering.SetFontsFolders_out.pdf";
            doc.Save(dataDir);
            // ExEnd:SetFontsFoldersSystemAndCustomFolder 
            Console.WriteLine("\nFonts system and coustom folder is setup.\nFile saved at " + dataDir);
                     
        }
Esempio n. 5
0
        public void SetFontsFoldersSystemAndCustomFolder()
        {
            //ExStart:SetFontsFoldersSystemAndCustomFolder
            Document doc = new Document(MyDir + "Rendering.docx");

            FontSettings fontSettings = new FontSettings();
            // Retrieve the array of environment-dependent font sources that are searched by default.
            // For example this will contain a "Windows\Fonts\" source on a Windows machines.
            // We add this array to a new ArrayList to make adding or removing font entries much easier.
            ArrayList fontSources = new ArrayList(fontSettings.GetFontsSources());

            // Add a new folder source which will instruct Aspose.Words to search the following folder for fonts.
            FolderFontSource folderFontSource = new FolderFontSource("C:\\MyFonts\\", true);

            // Add the custom folder which contains our fonts to the list of existing font sources.
            fontSources.Add(folderFontSource);

            FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));
            fontSettings.SetFontsSources(updatedFontSources);

            doc.FontSettings = fontSettings;

            doc.Save(ArtifactsDir + "WorkingWithFonts.SetFontsFoldersSystemAndCustomFolder.pdf");
            //ExEnd:SetFontsFoldersSystemAndCustomFolder
        }
Esempio n. 6
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Defining string variables to store paths to font folders & font file
            string fontFolder1 = dataDir + "Arial";
            string fontFolder2 = dataDir + "Calibri";
            string fontFile    = dataDir + "arial.ttf";

            // Setting first font folder with SetFontFolder method
            // Second parameter directs the API to search the subfolders for font files
            FontConfigs.SetFontFolder(fontFolder1, true);

            // Setting both font folders with SetFontFolders method
            // Second parameter prohibits the API to search the subfolders for font files
            FontConfigs.SetFontFolders(new string[] { fontFolder1, fontFolder2 }, false);

            // Defining FolderFontSource
            FolderFontSource sourceFolder = new FolderFontSource(fontFolder1, false);

            // Defining FileFontSource
            FileFontSource sourceFile = new FileFontSource(fontFile);

            // Defining MemoryFontSource
            MemoryFontSource sourceMemory = new MemoryFontSource(System.IO.File.ReadAllBytes(fontFile));

            // Setting font sources
            FontConfigs.SetFontSources(new FontSourceBase[] { sourceFolder, sourceFile, sourceMemory });
            // ExEnd:1
        }
Esempio n. 7
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            // Defining string variables to store paths to font folders & font file
            string fontFolder1 = sourceDir + "Arial";
            string fontFolder2 = sourceDir + "Calibri";
            string fontFile    = sourceDir + "Arial.ttf";

            // Setting first font folder with SetFontFolder method
            // Second parameter directs the API to search the subfolders for font files
            FontConfigs.SetFontFolder(fontFolder1, true);

            // Setting both font folders with SetFontFolders method
            // Second parameter prohibits the API to search the subfolders for font files
            FontConfigs.SetFontFolders(new string[] { fontFolder1, fontFolder2 }, false);

            // Defining FolderFontSource
            FolderFontSource sourceFolder = new FolderFontSource(fontFolder1, false);

            // Defining FileFontSource
            FileFontSource sourceFile = new FileFontSource(fontFile);

            // Defining MemoryFontSource
            MemoryFontSource sourceMemory = new MemoryFontSource(System.IO.File.ReadAllBytes(fontFile));

            // Setting font sources
            FontConfigs.SetFontSources(new FontSourceBase[] { sourceFolder, sourceFile, sourceMemory });

            Console.WriteLine("SetCustomFontFolders executed successfully.");
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Defining string variables to store paths to font folders & font file
            string fontFolder1 =  dataDir + "Arial";
            string fontFolder2 =  dataDir + "Calibri";
            string fontFile = dataDir + "arial.ttf"; 

            // Setting first font folder with SetFontFolder method
            // Second parameter directs the API to search the subfolders for font files
            FontConfigs.SetFontFolder(fontFolder1, true);

            // Setting both font folders with SetFontFolders method
            // Second parameter prohibits the API to search the subfolders for font files
            FontConfigs.SetFontFolders(new string[] { fontFolder1, fontFolder2 }, false);

            // Defining FolderFontSource
            FolderFontSource sourceFolder = new FolderFontSource(fontFolder1, false);

            // Defining FileFontSource
            FileFontSource sourceFile = new FileFontSource(fontFile);

            // Defining MemoryFontSource
            MemoryFontSource sourceMemory = new MemoryFontSource(System.IO.File.ReadAllBytes(fontFile));

            // Setting font sources
            FontConfigs.SetFontSources(new FontSourceBase[] { sourceFolder, sourceFile, sourceMemory });
            // ExEnd:1          
            
        }
Esempio n. 9
0
        internal static void LoadCustomFonts(string path)
        {
            // Add the custom folder which contains our fonts to the list of existing font sources.
            ArrayList        fontSources      = new ArrayList(FontSettings.DefaultInstance.GetFontsSources());
            FolderFontSource folderFontSource = new FolderFontSource(path, true);

            fontSources.Add(folderFontSource);
            FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));
            // "Setting this property resets the cache of all previously loaded fonts."
            FontSettings.DefaultInstance.SetFontsSources(updatedFontSources);
        }
        public void SetSpecifyFontFolder()
        {
            FontSettings fontSettings = new FontSettings();

            fontSettings.SetFontsFolder(MyDir + @"MyFonts\", false);

            // Using load options
            LoadOptions loadOptions = new LoadOptions();

            loadOptions.FontSettings = fontSettings;
            Document doc = new Document(MyDir + "Rendering.doc", loadOptions);

            FolderFontSource folderSource = ((FolderFontSource)doc.FontSettings.GetFontsSources()[0]);

            Assert.AreEqual(MyDir + @"MyFonts\", folderSource.FolderPath);
            Assert.False(folderSource.ScanSubfolders);
        }
        public void SetFontsFoldersSystemAndCustomFolder()
        {
            // Store the font sources currently used so we can restore them later.
            FontSourceBase[] origFontSources = FontSettings.DefaultInstance.GetFontsSources();

            //ExStart
            //ExFor:FontSettings
            //ExFor:FontSettings.GetFontsSources()
            //ExFor:FontSettings.SetFontsSources()
            //ExId:SetFontsFoldersSystemAndCustomFolder
            //ExSummary:Demonstrates how to set Aspose.Words to look for TrueType fonts in system folders as well as a custom defined folder when scanning for fonts.
            Document doc = new Document(MyDir + "Rendering.doc");

            // Retrieve the array of environment-dependent font sources that are searched by default. For example this will contain a "Windows\Fonts\" source on a Windows machines.
            // We add this array to a new ArrayList to make adding or removing font entries much easier.
            ArrayList fontSources = new ArrayList(FontSettings.DefaultInstance.GetFontsSources());

            // Add a new folder source which will instruct Aspose.Words to search the following folder for fonts.
            FolderFontSource folderFontSource = new FolderFontSource("C:\\MyFonts\\", true);

            // Add the custom folder which contains our fonts to the list of existing font sources.
            fontSources.Add(folderFontSource);

            // Convert the Arraylist of source back into a primitive array of FontSource objects.
            FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));

            // Apply the new set of font sources to use.
            FontSettings.DefaultInstance.SetFontsSources(updatedFontSources);

            doc.Save(MyDir + @"\Artifacts\Rendering.SetFontsFolders.pdf");
            //ExEnd

            // Verify that font sources are set correctly.
            Assert.IsInstanceOf(typeof(SystemFontSource), FontSettings.DefaultInstance.GetFontsSources()[0]); // The first source should be a system font source.
            Assert.IsInstanceOf(typeof(FolderFontSource), FontSettings.DefaultInstance.GetFontsSources()[1]); // The second source should be our folder font source.

            FolderFontSource folderSource = ((FolderFontSource)FontSettings.DefaultInstance.GetFontsSources()[1]);

            Assert.AreEqual(@"C:\MyFonts\", folderSource.FolderPath);
            Assert.True(folderSource.ScanSubfolders);

            // Restore the original sources used to search for fonts.
            FontSettings.DefaultInstance.SetFontsSources(origFontSources);
        }
Esempio n. 12
0
        //ExStart:GetSubstitutionWithoutSuffixes
        public static void GetSubstitutionWithoutSuffixes(string dataDir)
        {
            Document doc = new Document(dataDir + "Get substitution without suffixes.docx");

            DocumentSubstitutionWarnings substitutionWarningHandler = new DocumentSubstitutionWarnings();

            doc.WarningCallback = substitutionWarningHandler;

            ArrayList        fontSources      = new ArrayList(FontSettings.DefaultInstance.GetFontsSources());
            FolderFontSource folderFontSource = new FolderFontSource(dataDir + "Fonts/", true);

            fontSources.Add(folderFontSource);

            FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));
            FontSettings.DefaultInstance.SetFontsSources(updatedFontSources);

            doc.Save(dataDir + "GetSubstitutionWithoutSuffixes_out.pdf");

            Assert.AreEqual(
                "Font 'DINOT-Regular' has not been found. Using 'DINOT' font instead. Reason: font name substitution.",
                substitutionWarningHandler.FontWarnings[0].Description);
        }
Esempio n. 13
0
        public void GetListOfAvailableFonts()
        {
            //ExStart:GetListOfAvailableFonts
            FontSettings fontSettings = new FontSettings();
            ArrayList    fontSources  = new ArrayList(fontSettings.GetFontsSources());

            // Add a new folder source which will instruct Aspose.Words to search the following folder for fonts.
            FolderFontSource folderFontSource = new FolderFontSource(MyDir, true);

            // Add the custom folder which contains our fonts to the list of existing font sources.
            fontSources.Add(folderFontSource);

            FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));

            foreach (PhysicalFontInfo fontInfo in updatedFontSources[0].GetAvailableFonts())
            {
                Console.WriteLine("FontFamilyName : " + fontInfo.FontFamilyName);
                Console.WriteLine("FullFontName  : " + fontInfo.FullFontName);
                Console.WriteLine("Version  : " + fontInfo.Version);
                Console.WriteLine("FilePath : " + fontInfo.FilePath);
            }
            //ExEnd:GetListOfAvailableFonts
        }
Esempio n. 14
0
        public void GetSubstitutionWithoutSuffixes()
        {
            Document doc = new Document(MyDir + "Get substitution without suffixes.docx");

            DocumentSubstitutionWarnings substitutionWarningHandler = new DocumentSubstitutionWarnings();

            doc.WarningCallback = substitutionWarningHandler;

            List <FontSourceBase> fontSources = new List <FontSourceBase>(FontSettings.DefaultInstance.GetFontsSources());

            FolderFontSource folderFontSource = new FolderFontSource(FontsDir, true);

            fontSources.Add(folderFontSource);

            FontSourceBase[] updatedFontSources = fontSources.ToArray();
            FontSettings.DefaultInstance.SetFontsSources(updatedFontSources);

            doc.Save(ArtifactsDir + "WorkingWithFonts.GetSubstitutionWithoutSuffixes.pdf");

            Assert.AreEqual(
                "Font 'DINOT-Regular' has not been found. Using 'DINOT' font instead. Reason: font name substitution.",
                substitutionWarningHandler.FontWarnings[0].Description);
        }
        public void SetFontsFoldersSystemAndCustomFolder()
        {
            // Store the font sources currently used so we can restore them later.
            FontSourceBase[] origFontSources = FontSettings.GetFontsSources();

            //ExStart
            //ExFor:FontSettings
            //ExFor:FontSettings.GetFontsSources()
            //ExFor:FontSettings.SetFontsSources()
            //ExId:SetFontsFoldersSystemAndCustomFolder
            //ExSummary:Demonstrates how to set Aspose.Words to look for TrueType fonts in system folders as well as a custom defined folder when scanning for fonts.
            Document doc = new Document(MyDir + "Rendering.doc");

            // Retrieve the array of environment-dependent font sources that are searched by default. For example this will contain a "Windows\Fonts\" source on a Windows machines.
            // We add this array to a new ArrayList to make adding or removing font entries much easier.
            ArrayList fontSources = new ArrayList(FontSettings.GetFontsSources());

            // Add a new folder source which will instruct Aspose.Words to search the following folder for fonts.
            FolderFontSource folderFontSource = new FolderFontSource("C:\\MyFonts\\", true);

            // Add the custom folder which contains our fonts to the list of existing font sources.
            fontSources.Add(folderFontSource);

            // Convert the Arraylist of source back into a primitive array of FontSource objects.
            FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));

            // Apply the new set of font sources to use.
            FontSettings.SetFontsSources(updatedFontSources);

            doc.Save(MyDir + "Rendering.SetFontsFolders Out.pdf");
            //ExEnd

            // Verify that font sources are set correctly.
            Assert.IsInstanceOf(typeof(SystemFontSource), FontSettings.GetFontsSources()[0]); // The first source should be a system font source.
            Assert.IsInstanceOf(typeof(FolderFontSource), FontSettings.GetFontsSources()[1]); // The second source should be our folder font source.

            FolderFontSource folderSource = ((FolderFontSource)FontSettings.GetFontsSources()[1]);
            Assert.AreEqual(@"C:\MyFonts\", folderSource.FolderPath);
            Assert.True(folderSource.ScanSubfolders);

            // Restore the original sources used to search for fonts.
            FontSettings.SetFontsSources(origFontSources);
        }