Beispiel #1
0
        public void Dictionary()
        {
            //ExStart
            //ExFor:Hyphenation.IsDictionaryRegistered(String)
            //ExFor:Hyphenation.RegisterDictionary(String, String)
            //ExFor:Hyphenation.UnregisterDictionary(String)
            //ExSummary:Shows how to perform and verify hyphenation dictionary registration.
            // Register a dictionary file from the local file system to the "de-CH" locale
            Hyphenation.RegisterDictionary("de-CH", MyDir + "hyph_de_CH.dic");

            // This method can be used to verify that a language has a matching registered hyphenation dictionary
            Assert.True(Hyphenation.IsDictionaryRegistered("de-CH"));

            // The dictionary file contains a long list of words in a specified language, and in this case it is German
            // These words define a set of rules for hyphenating text (splitting words across lines)
            // If we open a document with text of a language matching that of a registered dictionary,
            // that dictionary's hyphenation rules will be applied and visible upon saving
            Document doc = new Document(MyDir + "German text.docx");

            doc.Save(ArtifactsDir + "Hyphenation.Dictionary.Registered.pdf");

            // We can also un-register a dictionary to disable these effects on any documents opened after the operation
            Hyphenation.UnregisterDictionary("de-CH");

            Assert.False(Hyphenation.IsDictionaryRegistered("de-CH"));

            doc = new Document(MyDir + "German text.docx");
            doc.Save(ArtifactsDir + "Hyphenation.Dictionary.Unregistered.pdf");
            //ExEnd
        }
Beispiel #2
0
        public void Dictionary()
        {
            //ExStart
            //ExFor:Hyphenation.IsDictionaryRegistered(String)
            //ExFor:Hyphenation.RegisterDictionary(String, String)
            //ExFor:Hyphenation.UnregisterDictionary(String)
            //ExSummary:Shows how to register a hyphenation dictionary.
            // A hyphenation dictionary contains a list of strings that define hyphenation rules for the dictionary's language.
            // When a document contains lines of text in which a word could be split up and continued on the next line,
            // hyphenation will look through the dictionary's list of strings for that word's substrings.
            // If the dictionary contains a substring, then hyphenation will split the word across two lines
            // by the substring, and add a hyphen to the first half.
            // Register a dictionary file from the local file system to the "de-CH" locale.
            Hyphenation.RegisterDictionary("de-CH", MyDir + "hyph_de_CH.dic");

            Assert.True(Hyphenation.IsDictionaryRegistered("de-CH"));

            // Open a document containing text with a locale matching that of our dictionary,
            // and save it to a fixed-page save format. The text in that document will be hyphenated.
            Document doc = new Document(MyDir + "German text.docx");

            Assert.True(doc.FirstSection.Body.FirstParagraph.Runs.OfType <Run>().All(
                            r => r.Font.LocaleId == new CultureInfo("de-CH").LCID));

            doc.Save(ArtifactsDir + "Hyphenation.Dictionary.Registered.pdf");

            // Re-load the document after un-registering the dictionary,
            // and save it to another PDF, which will not have hyphenated text.
            Hyphenation.UnregisterDictionary("de-CH");

            Assert.False(Hyphenation.IsDictionaryRegistered("de-CH"));

            doc = new Document(MyDir + "German text.docx");
            doc.Save(ArtifactsDir + "Hyphenation.Dictionary.Unregistered.pdf");
            //ExEnd

#if NET462 || NETCOREAPP2_1 || JAVA
            Aspose.Pdf.Document pdfDoc       = new Aspose.Pdf.Document(ArtifactsDir + "Hyphenation.Dictionary.Registered.pdf");
            TextAbsorber        textAbsorber = new TextAbsorber();
            textAbsorber.Visit(pdfDoc);

            Assert.True(textAbsorber.Text.Contains("La ob storen an deinen am sachen. Dop-\r\n" +
                                                   "pelte  um  da  am  spateren  verlogen  ge-\r\n" +
                                                   "kommen  achtzehn  blaulich."));

            pdfDoc       = new Aspose.Pdf.Document(ArtifactsDir + "Hyphenation.Dictionary.Unregistered.pdf");
            textAbsorber = new TextAbsorber();
            textAbsorber.Visit(pdfDoc);

            Assert.True(textAbsorber.Text.Contains("La  ob  storen  an  deinen  am  sachen. \r\n" +
                                                   "Doppelte  um  da  am  spateren  verlogen \r\n" +
                                                   "gekommen  achtzehn  blaulich."));
#endif
        }
        public void UnregisteredDictionaryEx()
        {
            //ExStart
            //ExFor:Hyphenation.UnregisterDictionary(String)
            //ExSummary:Shows how to un-register a dictionary.
            Document doc = new Document(MyDir + "Document.doc");

            Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic");

            Hyphenation.UnregisterDictionary("en-US");

            Assert.AreEqual(false, Hyphenation.IsDictionaryRegistered("en-US"));
            //ExEnd
        }
        public void UnregisterDictionaryEx()
        {
            //ExStart
            //ExFor:Hyphenation.UnregisterDictionary(string)
            //ExSummary:Shows how to un-register a dictionary
            Document doc = new Document(MyDir + "Document.doc");

            Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic");

            Hyphenation.UnregisterDictionary("en-US");

            Console.WriteLine(Hyphenation.IsDictionaryRegistered("en-US")); // False
            //ExEnd
        }