Пример #1
0
        public void EnableFontSubstitutionTrue()
        {
            //ExStart
            //ExFor:FontSettings.EnableFontSubstitution
            //ExSummary:Shows how to set the property for finding the closest match font among the available font sources instead missing font.
            Document doc = new Document(MyDir + "Font.EnableFontSubstitution.docx");

            // 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.EnableFontSubstitution = true;
            //ExEnd

            doc.FontSettings = fontSettings;

            doc.Save(MyDir + @"\Artifacts\Font.EnableFontSubstitution.pdf");

            Assert.True(callback.mFontWarnings[0].Description
                        .Equals(
                            "Font '28 Days Later' has not been found. Using 'Franklin Gothic Medium' 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);
        }
Пример #3
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."));
        }
        // ExStart:PdfRenderWarnings
        public void PdfRenderWarnings()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

            // Load the document from disk.
            Document doc = new Document(dataDir + "PdfRenderWarnings.doc");

            // Set a SaveOptions object to not emulate raster operations.
            PdfSaveOptions saveOptions = new PdfSaveOptions();

            saveOptions.MetafileRenderingOptions = new MetafileRenderingOptions
            {
                EmulateRasterOperations = false,
                RenderingMode           = MetafileRenderingMode.VectorWithFallback
            };

            // If Aspose.Words cannot correctly render some of the metafile records to vector graphics then Aspose.Words renders this metafile to a bitmap.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;

            doc.Save(dataDir + "PdfRenderWarnings.pdf", saveOptions);

            // While the file saves successfully, rendering warnings that occurred during saving are collected here.
            foreach (WarningInfo warningInfo in callback.mWarnings)
            {
                Console.WriteLine(warningInfo.Description);
            }
        }
Пример #5
0
        //ExStart:PdfRenderWarnings
        public void PdfRenderWarnings()
        {
            Document doc = new Document(MyDir + "WMF with image.docx");

            MetafileRenderingOptions metafileRenderingOptions = new MetafileRenderingOptions
            {
                EmulateRasterOperations = false, RenderingMode = MetafileRenderingMode.VectorWithFallback
            };

            PdfSaveOptions saveOptions = new PdfSaveOptions {
                MetafileRenderingOptions = metafileRenderingOptions
            };

            // If Aspose.Words cannot correctly render some of the metafile records
            // to vector graphics then Aspose.Words renders this metafile to a bitmap.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;

            doc.Save(ArtifactsDir + "WorkingWithPdfSaveOptions.PdfRenderWarnings.pdf", saveOptions);

            // While the file saves successfully, rendering warnings that occurred during saving are collected here.
            foreach (WarningInfo warningInfo in callback.mWarnings)
            {
                Console.WriteLine(warningInfo.Description);
            }
        }
        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);
        }
Пример #7
0
        public void HandleBinaryRasterWarnings()
        {
            //ExStart
            //ExFor:MetafileRenderingMode.VectorWithFallback
            //ExFor:IWarningCallback
            //ExFor:PdfSaveOptions.MetafileRenderingOptions
            //ExSummary:Shows added fallback to bitmap rendering and changing type of warnings about unsupported metafile records
            Document doc = new Document(MyDir + "PdfSaveOptions.HandleRasterWarnings.doc");

            MetafileRenderingOptions metafileRenderingOptions =
                new MetafileRenderingOptions
            {
                EmulateRasterOperations = false,
                RenderingMode           = MetafileRenderingMode.VectorWithFallback
            };

            //If Aspose.Words cannot correctly render some of the metafile records to vector graphics then Aspose.Words renders this metafile to a bitmap.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;

            PdfSaveOptions saveOptions = new PdfSaveOptions {
                MetafileRenderingOptions = metafileRenderingOptions
            };

            doc.Save(MyDir + @"\Artifacts\PdfSaveOptions.HandleRasterWarnings.pdf", saveOptions);

            Assert.AreEqual(1, callback.mWarnings.Count);
            Assert.True(callback.mWarnings[0].Description.Contains("R2_XORPEN"));
        }
Пример #8
0
        public void FontSubstitutionWarningsClosestMatch()
        {
            Document doc = new Document(MyDir + "Font.DisapearingBulletPoints.doc");

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

            doc.WarningCallback = callback;

            doc.Save(MyDir + @"\Artifacts\Font.DisapearingBulletPoints.pdf");

            Assert.True(callback.mFontWarnings[0].Description.Equals("Font 'SymbolPS' has not been found. Using 'Wingdings' font instead. Reason: closest match according to font info from the document."));
        }
        private static void ReceiveWarningNotification(Document doc, string dataDir)
        {
            //ExStart:ReceiveWarningNotification
            // 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();

            doc.WarningCallback = callback;
            dataDir             = dataDir + "Rendering.FontsNotificationUpdatePageLayout_out_.pdf";
            // Even though the document was rendered previously, any save warnings are notified to the user during document save.
            doc.Save(dataDir);
            //ExEnd:ReceiveWarningNotification
        }
        private static void ReceiveWarningNotification(Document doc, string dataDir)
        {
            // ExStart:ReceiveWarningNotification 
            // 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();

            doc.WarningCallback = callback;
            dataDir = dataDir + "Rendering.FontsNotificationUpdatePageLayout_out.pdf";
            // Even though the document was rendered previously, any save warnings are notified to the user during document save.
            doc.Save(dataDir);
            // ExEnd:ReceiveWarningNotification  
        }
Пример #11
0
        public void ReceiveWarningNotification()
        {
            //ExStart:ReceiveWarningNotification
            Document doc = new Document(MyDir + "Rendering.docx");

            // 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();

            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;

            // Even though the document was rendered previously, any save warnings are notified to the user during document save.
            doc.Save(ArtifactsDir + "WorkingWithFonts.ReceiveWarningNotification.pdf");
            //ExEnd:ReceiveWarningNotification
        }
Пример #12
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);
        }
Пример #13
0
        public void RecieveFontSubstitutionNotification()
        {
            // Store the font sources currently used so we can restore them later.
            FontSourceBase[] origFontSources = FontSettings.DefaultInstance.GetFontsSources();

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

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

            doc.WarningCallback = callback;

            // We can choose the default font to use in the case of any missing fonts.
            FontSettings.DefaultInstance.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 substituted with the default
            // font specified under FontSettings.DefaultFontName. We can pick up on this substitution using our callback.
            FontSettings.DefaultInstance.SetFontsFolder(String.Empty, false);

            // Pass the save options along with the save path to the save method.
            doc.Save(MyDir + @"\Artifacts\Rendering.MissingFontNotification.pdf");
            //ExEnd

            Assert.Greater(callback.mFontWarnings.Count, 0);
            Assert.True(callback.mFontWarnings[0].WarningType == WarningType.FontSubstitution);
            Assert.True(callback.mFontWarnings[0].Description
                        .Equals(
                            "Font 'Times New Roman' has not been found. Using 'Fanwood' font instead. Reason: first available font."));

            // Restore default fonts.
            FontSettings.DefaultInstance.SetFontsSources(origFontSources);
        }
Пример #14
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);
        }
Пример #15
0
        public void EnableFontSubstitutionFalse()
        {
            Document doc = new Document(MyDir + "Font.EnableFontSubstitution.docx");

            // 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.EnableFontSubstitution = false;

            doc.FontSettings = fontSettings;

            doc.Save(MyDir + @"\Artifacts\Font.EnableFontSubstitution.pdf");

            Assert.True(callback.mFontWarnings[0].Description
                        .Equals(
                            "Font '28 Days Later' has not been found. Using 'Arial' font instead. Reason: default font setting."));
        }
Пример #16
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
        }
Пример #17
0
        // ExEnd:PdfRenderWarnings

        public static void RenderMetafileToBitmap(string dataDir)
        {
            // Load the document from disk.
            Document doc = new Document(dataDir + "PdfRenderWarnings.doc");

            MetafileRenderingOptions metafileRenderingOptions =
                new MetafileRenderingOptions
            {
                EmulateRasterOperations = false,
                RenderingMode           = MetafileRenderingMode.VectorWithFallback
            };

            // If Aspose.Words cannot correctly render some of the metafile records to vector graphics then Aspose.Words renders this metafile to a bitmap.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;

            PdfSaveOptions saveOptions = new PdfSaveOptions();

            saveOptions.MetafileRenderingOptions = metafileRenderingOptions;

            doc.Save(dataDir + "PdfSaveOptions.HandleRasterWarnings.pdf", saveOptions);
        }
        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.
            Document doc = new 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 void RecieveFontSubstitutionUpdatePageLayout()
        {
            // Store the font sources currently used so we can restore them later.
            FontSourceBase[] origFontSources = FontSettings.GetFontsSources();

            // Load the document to render.
            Document doc = new 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);
        }