public virtual void UriTest01() { String outFileName = destinationFolder + "uriTest01.pdf"; String cmpFileName = sourceFolder + "cmp_uriTest01.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName)); Document document = new Document(pdfDoc, new PageSize(140, 500)); Hyphenator hyphenator = new Hyphenator("en", "en", 3, 3); HyphenationConfig hyphenationConfig = new HyphenationConfig(hyphenator); document.SetHyphenation(hyphenationConfig); Paragraph p = new Paragraph("https://stackoverflow.com/"); document.Add(p); p = new Paragraph("http://stackoverflow.com/"); document.Add(p); p = new Paragraph("m://iiiiiiii.com/"); document.Add(p); document.Add(new AreaBreak()); p = new Paragraph("https://stackoverflow.com/"); p.SetHyphenation(null); document.Add(p); p = new Paragraph("http://stackoverflow.com/"); p.SetHyphenation(null); document.Add(p); p = new Paragraph("m://iiiiiiii.com/"); p.SetHyphenation(null); document.Add(p); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
private void TryHyphenate(String lang, String testWorld, bool shouldPass) { String[] parts = iText.IO.Util.StringUtil.Split(lang, "_"); lang = parts[0]; String country = (parts.Length == 2) ? parts[1] : null; HyphenationConfig config = new HyphenationConfig(lang, country, 3, 3); iText.Layout.Hyphenation.Hyphenation result = config.Hyphenate(testWorld); if ((result == null) == shouldPass) { errors.Add(MessageFormatUtil.Format("\nLanguage: {0}, error on hyphenate({1}), shouldPass: {2}", lang, testWorld , shouldPass)); } }
private void TestHyphenateResult(String lang, String testWorld, int[] expectedHyphenatePoints) { String[] parts = iText.IO.Util.StringUtil.Split(lang, "_"); lang = parts[0]; String country = (parts.Length == 2) ? parts[1] : null; HyphenationConfig config = new HyphenationConfig(lang, country, 3, 3); iText.Layout.Hyphenation.Hyphenation result = config.Hyphenate(testWorld); if (result != null) { NUnit.Framework.Assert.AreEqual(expectedHyphenatePoints, result.GetHyphenationPoints()); } else { NUnit.Framework.Assert.IsNull(expectedHyphenatePoints); } }
public virtual void ParenthesisTest01() { String outFileName = destinationFolder + "parenthesisTest01.pdf"; String cmpFileName = sourceFolder + "cmp_parenthesisTest01.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName)); Document document = new Document(pdfDoc, new PageSize(300, 500)); Hyphenator hyphenator = new Hyphenator("de", "de", 3, 3); HyphenationConfig hyphenationConfig = new HyphenationConfig(hyphenator); document.SetHyphenation(hyphenationConfig); document.Add(new Paragraph("1 (((\"|Annuitätendarlehen|\")))")); document.Add(new Paragraph("2 ((\"|Annuitätendarlehen|\"))")); document.Add(new Paragraph("3 (\"|Annuitätendarlehen|\")")); document.Add(new Paragraph("4 \"|Annuitätendarlehen|\"")); document.Add(new Paragraph("5 \"Annuitätendarlehen\"")); document.Add(new Paragraph("6 Annuitätendarlehen")); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
/// <summary> /// Sets a custom hyphenation configuration which will hyphenate words automatically accordingly to the /// language and country. /// </summary> /// <param name="hyphenationConfig">The hyphenation configuration</param> /// <returns>this element</returns> public virtual T SetHyphenation(HyphenationConfig hyphenationConfig) { SetProperty(Property.HYPHENATION, hyphenationConfig); return((T)(Object)this); }
public bool ConvertToPdf(FileModel file) { var pdfOutputPath = $"{settings.PdfDownloadPath}\\Converted_{file.FileName.Split('.')[0]}.pdf"; var fileToConvert = file.File; string fileType = fileToConvert.ContentType; if (file.File.Length > 0) { try { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(pdfOutputPath)); Document document = new Document(pdfDoc); PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN); HyphenationConfig hyphenConfig = new HyphenationConfig("en", null, 3, 3); document.SetTextAlignment(TextAlignment.JUSTIFIED).SetFont(font).SetFontSize(11).SetHyphenation(hyphenConfig); using (FileStream fs = new FileStream(file.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { //fileToConvert.CopyToAsync(fs); string line; Paragraph p; bool title = true; switch (fileType) { case KnownMimeTypes.Txt: using (StreamReader sr = new StreamReader(fs)) { while ((line = sr.ReadLine()) != null) { p = new Paragraph(line); p.SetKeepTogether(true); if (title) { p.SetFont(PdfFontFactory.CreateFont(StandardFonts.COURIER_BOLD)); title = false; } else { p.SetFirstLineIndent(36); } if (string.IsNullOrEmpty(line)) { p.SetMarginBottom(12); title = true; } else { p.SetMarginBottom(0); } document.Add(p); } } document.Close(); return(true); case KnownMimeTypes.Html: return(true); case KnownMimeTypes.Img: return(true); default: break; } } } catch (Exception ex) { Debug.WriteLine($"{ex.Message}"); throw ex; } } return(false); }