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

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

            FontSettings FontSettings = new FontSettings();

            // We can choose the default font to use in the case of any missing fonts.
            FontSettings.DefaultFontName = "Arial";
            // For testing we will set Aspose.Words to look for fonts only in a folder which doesn't exist. Since Aspose.Words won't
            // find any fonts in the specified directory, then during rendering the fonts in the document will be subsuited with the default
            // font specified under FontSettings.DefaultFontName. We can pick up on this subsuition using our callback.
            FontSettings.SetFontsFolder(string.Empty, false);

            // Create a new class implementing IWarningCallback which collect any warnings produced during document save.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;
            string path = dataDir + "Rendering.MissingFontNotification_out_.pdf";

            // Pass the save options along with the save path to the save method.
            doc.Save(path);
            //ExEnd:ReceiveNotificationsOfFonts
            Console.WriteLine("\nReceive notifications of font substitutions by using IWarningCallback processed.\nFile saved at " + path);

            ReceiveWarningNotification(doc, dataDir);
        }
Exemplo n.º 2
0
        public void FontSubstitutionWarnings()
        {
            Document doc = new Document(MyDir + "Rendering.doc");

            // Create a new class implementing IWarningCallback and assign it to the PdfSaveOptions class.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;

            FontSettings fontSettings = new FontSettings();

            fontSettings.DefaultFontName = "Arial";
            fontSettings.SetFontSubstitutes("Arial", new string[] { "Arvo", "Slab" });
            fontSettings.SetFontsFolder(MyDir + @"MyFonts\", false);

            doc.FontSettings = fontSettings;

            doc.Save(MyDir + @"\Artifacts\Rendering.MissingFontNotification.pdf");

            Assert.True(callback.mFontWarnings[0].Description
                        .Equals("Font substitutes: 'Arial' replaced with 'Arvo'."));
            Assert.True(callback.mFontWarnings[1].Description
                        .Equals(
                            "Font 'Times New Roman' has not been found. Using 'Noticia Text' font instead. Reason: closest match according to font info from the document."));
        }
        public static void Run()
        {
            // ExStart:ReceiveNotificationsOfFonts 
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting(); 

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

            FontSettings FontSettings = new FontSettings();          

            // We can choose the default font to use in the case of any missing fonts.
            FontSettings.DefaultFontName = "Arial";
            // For testing we will set Aspose.Words to look for fonts only in a folder which doesn't exist. Since Aspose.Words won't
            // Find any fonts in the specified directory, then during rendering the fonts in the document will be subsuited with the default
            // Font specified under FontSettings.DefaultFontName. We can pick up on this subsuition using our callback.
            FontSettings.SetFontsFolder(string.Empty, false);

            // Create a new class implementing IWarningCallback which collect any warnings produced during document save.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;
            // Set font settings
            doc.FontSettings = FontSettings;
            string path = dataDir + "Rendering.MissingFontNotification_out.pdf";
            // Pass the save options along with the save path to the save method.
            doc.Save(path);
            // ExEnd:ReceiveNotificationsOfFonts 
            Console.WriteLine("\nReceive notifications of font substitutions by using IWarningCallback processed.\nFile saved at " + path);

            ReceiveWarningNotification(doc, dataDir);
        }
Exemplo n.º 4
0
        public void SetFontsFolder()
        {
            //ExStart:SetFontsFolder
            FontSettings fontSettings = new FontSettings();

            fontSettings.SetFontsFolder(MyDir + "Fonts", false);

            LoadOptions loadOptions = new LoadOptions();

            loadOptions.FontSettings = fontSettings;

            Document doc = new Document(MyDir + "Rendering.docx", loadOptions);
            //ExEnd:SetFontsFolder
        }
Exemplo n.º 5
0
        static void SetFontsFolder()
        {
            // ExStart:SetFontsFolder
            // The path to the documents directory.
            string       dataDir      = RunExamples.GetDataDir_WorkingWithDocument();
            FontSettings fontSettings = new FontSettings();

            fontSettings.SetFontsFolder(dataDir + "Fonts", false);
            LoadOptions lo = new LoadOptions();

            lo.FontSettings = fontSettings;
            Document doc = new Document(dataDir + "myfile.html", lo);
            // ExEnd:SetFontsFolder
        }
        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);
        }
Exemplo n.º 7
0
        public void SetTrueTypeFontsFolder()
        {
            //ExStart:SetTrueTypeFontsFolder
            Document doc = new Document(MyDir + "Rendering.docx");

            FontSettings fontSettings = new FontSettings();

            // Note that this setting will override any default font sources that are being searched by default. Now only these folders will be searched for
            // Fonts when rendering or embedding fonts. To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and
            // FontSettings.SetFontSources instead
            fontSettings.SetFontsFolder(@"C:\MyFonts\", false);
            // Set font settings
            doc.FontSettings = fontSettings;

            doc.Save(ArtifactsDir + "WorkingWithFonts.SetTrueTypeFontsFolder.pdf");
            //ExEnd:SetTrueTypeFontsFolder
        }
Exemplo n.º 8
0
        public static void Run()
        {
            //ExStart:SetTrueTypeFontsFolder
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting();

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

            FontSettings FontSettings = new FontSettings();

            // Note that this setting will override any default font sources that are being searched by default. Now only these folders will be searched for
            // fonts when rendering or embedding fonts. To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and
            // FontSettings.SetFontSources instead.
            FontSettings.SetFontsFolder(@"C:\MyFonts\", false);
            dataDir = dataDir + "Rendering.SetFontsFolder_out_.pdf";
            doc.Save(dataDir);
            //ExEnd:SetTrueTypeFontsFolder
            Console.WriteLine("\nTrue type fonts folder setup successfully.\nFile saved at " + dataDir);
        }
Exemplo n.º 9
0
        public void RecieveFontSubstitutionNotification()
        {
            // Store the font sources currently used so we can restore them later.
            FontSourceBase[] origFontSources = FontSettings.GetFontsSources();

            //ExStart
            //ExFor:IWarningCallback
            //ExFor:SaveOptions.WarningCallback
            //ExId:FontSubstitutionNotification
            //ExSummary:Demonstrates how to recieve notifications of font substitutions by using IWarningCallback.
            // Load the document to render.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.doc");

            // We can choose the default font to use in the case of any missing fonts.
            FontSettings.DefaultFontName = "Arial";

            // For testing we will set Aspose.Words to look for fonts only in a folder which doesn't exist. Since Aspose.Words won't
            // find any fonts in the specified directory, then during rendering the fonts in the document will be subsuited with the default
            // font specified under FontSettings.DefaultFontName. We can pick up on this subsuition using our callback.
            FontSettings.SetFontsFolder(string.Empty, false);

            // Create a new class implementing IWarningCallback which collect any warnings produced during document save.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            // We assign the callback to the appropriate save options class. In this case, we are going to save to PDF
            // so we create a PdfSaveOptions class and assign the callback there.
            PdfSaveOptions saveOptions = new PdfSaveOptions();

            saveOptions.WarningCallback = callback;

            // Pass the save options along with the save path to the save method.
            doc.Save(MyDir + "Rendering.MissingFontNotification Out.pdf", saveOptions);
            //ExEnd

            Assert.Greater(callback.mFontWarnings.Count, 0);
            Assert.True(callback.mFontWarnings[0].WarningType == WarningType.FontSubstitution);
            Assert.True(callback.mFontWarnings[0].Description.Contains("has not been found"));

            // Restore default fonts.
            FontSettings.SetFontsSources(origFontSources);
        }
        public static void Run()
        {
            // ExStart:SetTrueTypeFontsFolder
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting(); 

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

            FontSettings FontSettings = new FontSettings();

            // Note that this setting will override any default font sources that are being searched by default. Now only these folders will be searched for
            // Fonts when rendering or embedding fonts. To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and
            // FontSettings.SetFontSources instead.
            FontSettings.SetFontsFolder(@"C:MyFonts\", false);
            // Set font settings
            doc.FontSettings = FontSettings;
            dataDir = dataDir + "Rendering.SetFontsFolder_out.pdf";
            doc.Save(dataDir);
            // ExEnd:SetTrueTypeFontsFolder
            Console.WriteLine("\nTrue type fonts folder setup successfully.\nFile saved at " + dataDir);
        }
Exemplo n.º 11
0
        public void RecieveFontSubstitutionUpdatePageLayout()
        {
            // Store the font sources currently used so we can restore them later.
            FontSourceBase[] origFontSources = FontSettings.GetFontsSources();

            // Load the document to render.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.doc");

            // We can choose the default font to use in the case of any missing fonts.
            FontSettings.DefaultFontName = "Arial";

            // For testing we will set Aspose.Words to look for fonts only in a folder which doesn't exist. Since Aspose.Words won't
            // find any fonts in the specified directory, then during rendering the fonts in the document will be subsuited with the default
            // font specified under FontSettings.DefaultFontName. We can pick up on this subsuition using our callback.
            FontSettings.SetFontsFolder(string.Empty, false);

            //ExStart
            //ExId:FontSubstitutionUpdatePageLayout
            //ExSummary:Demonstrates how IWarningCallback will still recieve warning notifcations even if UpdatePageLayout is called before document save.
            // When you call UpdatePageLayout the document is rendered in memory. Any warnings that occured during rendering
            // are stored until the document save and then sent to the appropriate WarningCallback.
            doc.UpdatePageLayout();

            // Create a new class implementing IWarningCallback and assign it to the PdfSaveOptions class.
            HandleDocumentWarnings callback    = new HandleDocumentWarnings();
            PdfSaveOptions         saveOptions = new PdfSaveOptions();

            saveOptions.WarningCallback = callback;

            // Even though the document was rendered previously, any save warnings are notified to the user during document save.
            doc.Save(MyDir + "Rendering.FontsNotificationUpdatePageLayout Out.pdf", saveOptions);
            //ExEnd

            Assert.Greater(callback.mFontWarnings.Count, 0);
            Assert.True(callback.mFontWarnings[0].WarningType == WarningType.FontSubstitution);
            Assert.True(callback.mFontWarnings[0].Description.Contains("has not been found"));

            // Restore default fonts.
            FontSettings.SetFontsSources(origFontSources);
        }
Exemplo n.º 12
0
        public void FontSettings()
        {
            //ExStart
            //ExFor:LoadOptions.FontSettings
            //ExSummary:Shows how to apply font substitution settings while loading a document.
            // Create a FontSettings object that will substitute the "Times New Roman" font
            // with the font "Arvo" from our "MyFonts" folder.
            FontSettings fontSettings = new FontSettings();

            fontSettings.SetFontsFolder(FontsDir, false);
            fontSettings.SubstitutionSettings.TableSubstitution.AddSubstitutes("Times New Roman", "Arvo");

            // Set that FontSettings object as a property of a newly created LoadOptions object.
            LoadOptions loadOptions = new LoadOptions();

            loadOptions.FontSettings = fontSettings;

            // Load the document, then render it as a PDF with the font substitution.
            Document doc = new Document(MyDir + "Document.docx", loadOptions);

            doc.Save(ArtifactsDir + "LoadOptions.FontSettings.pdf");
            //ExEnd
        }
Exemplo n.º 13
0
        public void ReceiveNotificationsOfFonts()
        {
            //ExStart:ReceiveNotificationsOfFonts
            Document doc = new Document(MyDir + "Rendering.docx");

            FontSettings fontSettings = new FontSettings();

            // We can choose the default font to use in the case of any missing fonts.
            fontSettings.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName = "Arial";
            // For testing we will set Aspose.Words to look for fonts only in a folder which doesn't exist. Since Aspose.Words won't
            // find any fonts in the specified directory, then during rendering the fonts in the document will be subsuited with the default
            // font specified under FontSettings.DefaultFontName. We can pick up on this subsuition using our callback.
            fontSettings.SetFontsFolder(string.Empty, false);

            // Create a new class implementing IWarningCallback which collect any warnings produced during document save.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;
            doc.FontSettings    = fontSettings;

            doc.Save(ArtifactsDir + "WorkingWithFonts.ReceiveNotificationsOfFonts.pdf");
            //ExEnd:ReceiveNotificationsOfFonts
        }
Exemplo n.º 14
0
        public void SetTrueTypeFontsFolder()
        {
            // Store the font sources currently used so we can restore them later.
            FontSourceBase[] fontSources = FontSettings.GetFontsSources();

            //ExStart
            //ExFor:FontSettings
            //ExFor:FontSettings.SetFontsFolder(String, Boolean)
            //ExId:SetFontsFolderCustomFolder
            //ExSummary:Demonstrates how to set the folder Aspose.Words uses to look for TrueType fonts during rendering or embedding of fonts.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Rendering.doc");

            // Note that this setting will override any default font sources that are being searched by default. Now only these folders will be searched for
            // fonts when rendering or embedding fonts. To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and
            // FontSettings.SetFontSources instead.
            FontSettings.SetFontsFolder(@"C:\MyFonts\", false);

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

            // Restore the original sources used to search for fonts.
            FontSettings.SetFontsSources(fontSources);
        }
Exemplo n.º 15
0
        public void FontSubstitutionWarnings()
        {
            Document doc = new Document(MyDir + "Rendering.doc");

            // Create a new class implementing IWarningCallback and assign it to the PdfSaveOptions class.
            ExRendering.HandleDocumentWarnings callback = new ExRendering.HandleDocumentWarnings();
            doc.WarningCallback = callback;

            FontSettings fontSettings = new FontSettings();
            fontSettings.DefaultFontName = "Arial";
            fontSettings.SetFontSubstitutes("Arial", new string[] { "Arvo", "Slab" });
            fontSettings.SetFontsFolder(MyDir + @"MyFonts\", false);

            doc.FontSettings = fontSettings;

            doc.Save(MyDir + @"\Artifacts\Rendering.MissingFontNotification.pdf");
            
            Assert.True(callback.mFontWarnings[0].Description.Equals("Font substitutes: 'Arial' replaced with 'Arvo'."));
            Assert.True(callback.mFontWarnings[1].Description.Equals("Font 'Times New Roman' has not been found. Using 'Arvo' font instead. Reason: default font setting."));
        }
        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);
        }