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 }
[Test] //ExSkip public void RegisterDictionary() { // Set up a callback that tracks warnings that occur during hyphenation dictionary registration WarningInfoCollection warningInfoCollection = new WarningInfoCollection(); Hyphenation.WarningCallback = warningInfoCollection; // Register an English (US) hyphenation dictionary by stream Stream dictionaryStream = new FileStream(MyDir + "hyph_en_US.dic", FileMode.Open, FileAccess.Read); Hyphenation.RegisterDictionary("en-US", dictionaryStream); // No warnings detected Assert.AreEqual(0, warningInfoCollection.Count); // Open a document with a German locale that might not get automatically hyphenated by Microsoft Word an english machine Document doc = new Document(MyDir + "German text.docx"); // To hyphenate that document upon saving, we need a hyphenation dictionary for the "de-CH" language code // This callback will handle the automatic request for that dictionary Hyphenation.Callback = new CustomHyphenationDictionaryRegister(); // When we save the document, it will be hyphenated according to rules defined by the dictionary known by our callback doc.Save(ArtifactsDir + "Hyphenation.RegisterDictionary.pdf"); // This dictionary contains two identical patterns, which will trigger a warning Assert.AreEqual(1, warningInfoCollection.Count); Assert.AreEqual(WarningType.MinorFormattingLoss, warningInfoCollection[0].WarningType); Assert.AreEqual(WarningSource.Layout, warningInfoCollection[0].Source); Assert.AreEqual("Hyphenation dictionary contains duplicate patterns. The only first found pattern will be used. " + "Content can be wrapped differently.", warningInfoCollection[0].Description); }
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 HyphenateWordsOfLanguages() { //ExStart:HyphenateWordsOfLanguages Document doc = new Document(MyDir + "German text.docx"); Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic"); Hyphenation.RegisterDictionary("de-CH", MyDir + "hyph_de_CH.dic"); doc.Save(ArtifactsDir + "WorkingWithHyphenation.HyphenateWordsOfLanguages.pdf"); //ExEnd:HyphenateWordsOfLanguages }
public void IsDictionaryRegisteredEx() { //ExStart //ExFor:Hyphenation.IsDictionaryRegistered(String) //ExSummary:Shows how to open check if some dictionary is registered. Document doc = new Document(MyDir + "Document.doc"); Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic"); Assert.AreEqual(true, Hyphenation.IsDictionaryRegistered("en-US")); //ExEnd }
public void IsDictionaryRegisteredEx() { //ExStart //ExFor:Hyphenation.IsDictionaryRegistered(string) //ExSummary:Shows how to open check if some dictionary is registered. Document doc = new Document(MyDir + "Document.doc"); Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic"); Console.WriteLine(Hyphenation.IsDictionaryRegistered("en-US")); // True //ExEnd }
public void LoadHyphenationDictionaryForLanguage() { //ExStart:LoadHyphenationDictionaryForLanguage Document doc = new Document(MyDir + "German text.docx"); Stream stream = File.OpenRead(MyDir + "hyph_de_CH.dic"); Hyphenation.RegisterDictionary("de-CH", stream); doc.Save(ArtifactsDir + "WorkingWithHyphenation.LoadHyphenationDictionaryForLanguage.pdf"); //ExEnd:LoadHyphenationDictionaryForLanguage }
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 }
public static void Run() { //ExStart:HyphenateWordsOfLanguages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_RenderingAndPrinting(); // Load the documents which store the shapes we want to render. Document doc = new Document(dataDir + "TestFile RenderShape.doc"); Hyphenation.RegisterDictionary("en-US", dataDir + @"hyph_en_US.dic"); Hyphenation.RegisterDictionary("de-CH", dataDir + @"hyph_de_CH.dic"); dataDir = dataDir + "HyphenateWordsOfLanguages_out_.pdf"; doc.Save(dataDir); //ExEnd:HyphenateWordsOfLanguages Console.WriteLine("\nWords of special languages hyphenate successfully.\nFile saved at " + dataDir); }
public void RegisterDictionaryEx() { //ExStart //ExFor:Hyphenation.RegisterDictionary(String, Stream) //ExFor:Hyphenation.RegisterDictionary(String, String) //ExSummary:Shows how to open and register a dictionary from a file. Document doc = new Document(MyDir + "Document.doc"); // Register by String Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic"); // Register by stream Stream dictionaryStream = new FileStream(MyDir + "hyph_de_CH.dic", FileMode.Open); Hyphenation.RegisterDictionary("de-CH", dictionaryStream); //ExEnd }
public static void Run() { //ExStart:LoadHyphenationDictionaryForLanguage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_RenderingAndPrinting(); // Load the documents which store the shapes we want to render. Document doc = new Document(dataDir + "TestFile RenderShape.doc"); Stream stream = File.OpenRead(dataDir + @"hyph_de_CH.dic"); Hyphenation.RegisterDictionary("de-CH", stream); dataDir = dataDir + "LoadHyphenationDictionaryForLanguage_out_.pdf"; doc.Save(dataDir); //ExEnd:LoadHyphenationDictionaryForLanguage Console.WriteLine("\nHyphenation dictionary for special language loaded successfully.\nFile saved at " + dataDir); }
public void RequestDictionary(string language) { Console.Write("Hyphenation dictionary requested: " + language); if (Hyphenation.IsDictionaryRegistered(language)) { Console.WriteLine(", is already registered."); return; } if (mHyphenationDictionaryFiles.ContainsKey(language)) { Hyphenation.RegisterDictionary(language, mHyphenationDictionaryFiles[language]); Console.WriteLine(", successfully registered."); return; } Console.WriteLine(", no respective dictionary file known by this Callback."); }
public void SuppressHyphens(bool suppressAutoHyphens) { //ExStart //ExFor:ParagraphFormat.SuppressAutoHyphens //ExSummary:Shows how to suppress hyphenation for a paragraph. 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. // When we save this document to a fixed page save format, its text will have hyphenation. Document doc = new Document(MyDir + "German text.docx"); // We can set the "SuppressAutoHyphens" property to "true" to disable hyphenation // for a specific paragraph while keeping it enabled for the rest of the document. // The default value for this property is "false", // which means every paragraph by default uses hyphenation if any is available. doc.FirstSection.Body.FirstParagraph.ParagraphFormat.SuppressAutoHyphens = suppressAutoHyphens; doc.Save(ArtifactsDir + "ParagraphFormat.SuppressHyphens.pdf"); //ExEnd #if NET462 || NETCOREAPP2_1 || JAVA Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(ArtifactsDir + "ParagraphFormat.SuppressHyphens.pdf"); TextAbsorber textAbsorber = new TextAbsorber(); textAbsorber.Visit(pdfDoc); if (suppressAutoHyphens) { 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.")); } else { 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.")); } #endif }
public void RequestDictionary(string language) { string dictionaryFolder = MyDir; string dictionaryFullFileName; switch (language) { case "en-US": dictionaryFullFileName = Path.Combine(dictionaryFolder, "hyph_en_US.dic"); break; case "de-CH": dictionaryFullFileName = Path.Combine(dictionaryFolder, "hyph_de_CH.dic"); break; default: throw new Exception($"Missing hyphenation dictionary for {language}."); } // Register dictionary for requested language. Hyphenation.RegisterDictionary(language, dictionaryFullFileName); }