public virtual void SearchNames() { FontProvider sel = new FontProvider(); NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "NotoSans-Regular.ttf")); NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "FreeSans.ttf")); NUnit.Framework.Assert.IsTrue(sel.GetFontSet().AddFont(fontsFolder + "Puritan2.otf", PdfEncodings.IDENTITY_H , "Puritan42")); ICollection <FontInfo> fonts = sel.GetFontSet().Get("puritan2"); NUnit.Framework.Assert.IsTrue(fonts.Count != 0, "Puritan not found!"); FontInfo puritan = GetFirst(fonts); NUnit.Framework.Assert.IsFalse(sel.GetFontSet().AddFont(puritan, "Puritan42"), "Replace existed font"); NUnit.Framework.Assert.IsFalse(sel.GetFontSet().AddFont(puritan), "Replace existed font"); NUnit.Framework.Assert.IsTrue(sel.GetFontSet().Contains("NotoSans"), "NotoSans not found!"); NUnit.Framework.Assert.IsTrue(sel.GetFontSet().Contains("Noto Sans"), "NotoSans not found!"); NUnit.Framework.Assert.IsTrue(sel.GetFontSet().Contains("FreeSans"), "FreeSans not found!"); NUnit.Framework.Assert.IsTrue(sel.GetFontSet().Contains("Free Sans"), "FreeSans not found!"); NUnit.Framework.Assert.IsTrue(sel.GetFontSet().Contains("puritan 2.0 regular"), "Puritan 2.0 not found!"); NUnit.Framework.Assert.IsTrue(sel.GetFontSet().Contains("puritan2"), "Puritan 2.0 not found!"); NUnit.Framework.Assert.IsFalse(sel.GetFontSet().Contains("puritan42"), "Puritan42 found!"); NUnit.Framework.Assert.AreEqual(puritan, GetFirst(sel.GetFontSet().Get("puritan 2.0 regular")), "Puritan 2.0 not found!" ); NUnit.Framework.Assert.AreEqual(puritan, GetFirst(sel.GetFontSet().Get("puritan2")), "Puritan 2.0 not found!" ); NUnit.Framework.Assert.IsTrue(GetFirst(sel.GetFontSet().Get("puritan42")) == null, "Puritan42 found!"); }
public virtual void CyrillicAndLatinGroup() { String fileName = "cyrillicAndLatinGroup"; String outFileName = destinationFolder + "cyrillicAndLatinGroup.pdf"; String cmpFileName = sourceFolder + "cmp_" + fileName + ".pdf"; FontProvider sel = new FontProvider(); NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "NotoSans-Regular.ttf")); NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "FreeSans.ttf")); NUnit.Framework.Assert.IsTrue(sel.GetFontSet().AddFont(fontsFolder + "Puritan2.otf", PdfEncodings.IDENTITY_H , "Puritan42")); String s = "Hello world! Здравствуй мир! Hello world! Здравствуй мир!"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create))); Document doc = new Document(pdfDoc); doc.SetFontProvider(sel); doc.SetProperty(Property.FONT, new String[] { "Puritan42" }); Text text = new Text(s).SetBackgroundColor(ColorConstants.LIGHT_GRAY); Paragraph paragraph = new Paragraph(text); doc.Add(paragraph); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff" + fileName)); }
public virtual void WriteTextInFontWhichAliasWithUnicodeChars() { String fileName = "writeTextInFontWhichAliasWithUnicodeChars"; String outFileName = destinationFolder + fileName + ".pdf"; String cmpFileName = sourceFolder + "cmp_" + fileName + ".pdf"; // フォント3 String japaneseAlias = "\u30D5\u30A9\u30F3\u30C83"; FontProvider provider = new FontProvider(); provider.AddFont(fontsFolder + "NotoSans-Regular.ttf"); provider.GetFontSet().AddFont(fontsFolder + "Puritan2.otf", PdfEncodings.IDENTITY_H, japaneseAlias); provider.AddFont(fontsFolder + "FreeSans.ttf"); String s = "Hello world!"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create))); Document doc = new Document(pdfDoc); doc.SetFontProvider(provider); Paragraph paragraph = new Paragraph(new Text(s).SetBackgroundColor(ColorConstants.LIGHT_GRAY)); paragraph.SetFontFamily(japaneseAlias); doc.Add(paragraph); doc.Close(); // Text shall be written in Puritan 2.0 NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder )); }
public virtual void TestReusingFontProvider() { String testName = "testReusingFontProvider"; String path = PdfHelper.GetDefaultImagePath(); String pdfPathA3u = PdfHelper.GetTargetDirectory() + testName + "_a3u.pdf"; String pdfPath = PdfHelper.GetTargetDirectory() + testName + ".pdf"; FileInfo file = new FileInfo(path); FontProvider fontProvider = new FontProvider("FreeSans"); fontProvider.AddFont(PdfHelper.GetFreeSansFontPath()); PdfOcrFontProvider pdfOcrFontProvider = new PdfOcrFontProvider(fontProvider.GetFontSet(), "FreeSans"); OcrPdfCreatorProperties ocrPdfCreatorProperties = new OcrPdfCreatorProperties(); ocrPdfCreatorProperties.SetPdfLang("en-US"); ocrPdfCreatorProperties.SetFontProvider(pdfOcrFontProvider); PdfHelper.CreatePdfA(pdfPathA3u, file, ocrPdfCreatorProperties, PdfHelper.GetCMYKPdfOutputIntent()); PdfHelper.CreatePdf(pdfPath, file, ocrPdfCreatorProperties); ExtractionStrategy strategy = PdfHelper.GetExtractionStrategy(pdfPathA3u); PdfFont font = strategy.GetPdfFont(); String fontName = font.GetFontProgram().GetFontNames().GetFontName(); NUnit.Framework.Assert.IsTrue(fontName.Contains("FreeSans")); NUnit.Framework.Assert.IsTrue(font.IsEmbedded()); NUnit.Framework.Assert.AreEqual(PdfHelper.DEFAULT_TEXT, strategy.GetResultantText()); strategy = PdfHelper.GetExtractionStrategy(pdfPath); font = strategy.GetPdfFont(); fontName = font.GetFontProgram().GetFontNames().GetFontName(); NUnit.Framework.Assert.IsTrue(fontName.Contains("FreeSans")); NUnit.Framework.Assert.IsTrue(font.IsEmbedded()); NUnit.Framework.Assert.AreEqual(PdfHelper.DEFAULT_TEXT, strategy.GetResultantText()); }
public virtual void TestCompliantThaiPdfA() { String testName = "testCompliantThaiPdfA"; String path = PdfHelper.GetThaiImagePath(); String pdfPath = PdfHelper.GetTargetDirectory() + testName + ".pdf"; OcrPdfCreatorProperties ocrPdfCreatorProperties = new OcrPdfCreatorProperties(); ocrPdfCreatorProperties.SetPdfLang("en-US"); ocrPdfCreatorProperties.SetTextColor(DeviceRgb.BLACK); FontProvider fontProvider = new FontProvider("Kanit"); fontProvider.AddFont(PdfHelper.GetKanitFontPath()); PdfOcrFontProvider pdfOcrFontProvider = new PdfOcrFontProvider(fontProvider.GetFontSet(), "Kanit"); ocrPdfCreatorProperties.SetFontProvider(pdfOcrFontProvider); PdfHelper.CreatePdfA(pdfPath, new FileInfo(path), ocrPdfCreatorProperties, PdfHelper.GetRGBPdfOutputIntent ()); String resultWithActualText = PdfHelper.GetTextFromPdfLayerUseActualText(pdfPath, null); NUnit.Framework.Assert.AreEqual(PdfHelper.THAI_TEXT, resultWithActualText); String resultWithoutUseActualText = PdfHelper.GetTextFromPdfLayer(pdfPath, null); NUnit.Framework.Assert.AreEqual(PdfHelper.THAI_TEXT, resultWithoutUseActualText); NUnit.Framework.Assert.AreEqual(resultWithoutUseActualText, resultWithActualText); ExtractionStrategy strategy = PdfHelper.GetExtractionStrategy(pdfPath); PdfFont font = strategy.GetPdfFont(); String fontName = font.GetFontProgram().GetFontNames().GetFontName(); NUnit.Framework.Assert.IsTrue(fontName.Contains("Kanit")); NUnit.Framework.Assert.IsTrue(font.IsEmbedded()); }
public virtual void ResolveFirstPdfFontWithGlyphsAvailableOnlyInSecondaryFont() { // Test that in TextRenderer the #resolveFirstPdfFont method is overloaded in such way // that yielded font contains at least some of the glyphs for the text characters. Text text = new Text("\u043A\u0456\u0440\u044B\u043B\u0456\u0446\u0430"); // "кірыліца" // Puritan doesn't contain cyrillic symbols, while Noto Sans does. text.SetFontFamily(JavaUtil.ArraysAsList("Puritan 2.0", "Noto Sans")); FontProvider fontProvider = new FontProvider(); fontProvider.AddFont(FONTS_FOLDER + "Puritan2.otf"); fontProvider.AddFont(FONTS_FOLDER + "NotoSans-Regular.ttf"); text.SetProperty(Property.FONT_PROVIDER, fontProvider); TextRenderer renderer = (TextRenderer) new TextRenderer(text); PdfFont pdfFont = renderer.ResolveFirstPdfFont(); NUnit.Framework.Assert.AreEqual("NotoSans", pdfFont.GetFontProgram().GetFontNames().GetFontName()); }
public virtual void SetTextException() { String val = "other text"; String fontName = "Helvetica"; TextRenderer rend = (TextRenderer) new Text("basic text").GetRenderer(); FontProvider fp = new FontProvider(); fp.AddFont(fontName); rend.SetProperty(Property.FONT_PROVIDER, fp); rend.SetProperty(Property.FONT, fontName); rend.SetText(val); NUnit.Framework.Assert.AreEqual(val, rend.GetText().ToString()); }
public void fromHtml() { PdfDocument pdf = new PdfDocument( new PdfWriter(dest)); //we use a PdfDocument Object instead of FileStream to write HTML into ConverterProperties cprop = new ConverterProperties(); FontProvider provider = new FontProvider(); provider.AddFont(font_path, PdfEncodings.IDENTITY_H); cprop.SetFontProvider(provider); pdf.AddEventHandler(PdfDocumentEvent.END_PAGE, new WatermarkEvent()); //here we add custom event handler HtmlConverter.ConvertToPdf(new FileStream(html_path, FileMode.Open), pdf, cprop); }
public static void LoadContent(ContentManager content) { FontProvider.AddFont("Mono14", content.Load <SpriteFont>(@"fonts/mono14")); FontProvider.AddFont("Mono8", content.Load <SpriteFont>(@"fonts/mono8")); FontProvider.AddFont("Mono21", content.Load <SpriteFont>(@"fonts/mono21")); Titlescreen.TitleTexture = content.Load <Texture2D>(@"textures/titlescreen"); new TileMap <Map <TileCode>, TileCode>(8, 8, 0, FontProvider.GetFont("Mono8"), content.Load <Texture2D>(@"textures/spritesheets/tilesheet"), 3); BulletInformationProvider.LoadBulletData(content); AnimationDictionaryProvider.Content = content; }
protected void ManipulatePdf(String dest) { String timesRomanFont = StandardFonts.TIMES_ROMAN; String arabicFont = FONTS_FOLDER + "NotoNaskhArabic-Regular.ttf"; String devanagariFont = FONTS_FOLDER + "NotoSansDevanagari-Regular.ttf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(DEST)); Document doc = new Document(pdfDoc); FontProvider provider = new FontProvider(); provider.AddFont(timesRomanFont); provider.AddFont(arabicFont); provider.AddFont(devanagariFont); // Adding fonts to the font provider doc.SetFontProvider(provider); Paragraph paragraph = new Paragraph(TEXT); // Setting font family to the particular element will trigger iText's font selection mechanism: // font for the element will be picked up from the provider's fonts paragraph.SetFontFamily(timesRomanFont); IDictionary <String, Color> fontColorMap = new Dictionary <String, Color>(); fontColorMap.Add("NotoNaskhArabic", ColorConstants.YELLOW); fontColorMap.Add("NotoSansDevanagari", ColorConstants.GREEN); fontColorMap.Add("Times-Roman", ColorConstants.BLUE); // Set custom renderer, which will change the color of text written within specific font paragraph.SetNextRenderer(new CustomParagraphRenderer(paragraph, fontColorMap)); doc.Add(paragraph); doc.Close(); }
public virtual void SetFontAsText() { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream())); pdfDoc.AddNewPage(); Document doc = new Document(pdfDoc); Text txt = new Text("text"); txt.SetProperty(Property.POSITION, LayoutPosition.ABSOLUTE); txt.SetProperty(Property.TOP, 5f); FontProvider fp = new FontProvider(); fp.AddFont("Helvetica"); txt.SetProperty(Property.FONT_PROVIDER, fp); txt.SetFont("Helvetica"); doc.Add(new Paragraph().Add(txt)); doc.Close(); }
public void createDoc() { PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdf); FontProvider provider = new FontProvider(); provider.AddFont(font_path, PdfEncodings.IDENTITY_H); PdfFont font = PdfFontFactory.CreateFont(font_path, PdfEncodings.IDENTITY_H, true); font.SetSubset(false); doc.SetFont(font); Paragraph p = new Paragraph($"\uD83D\uDE06 This text has an emoji, look! -> {encodeCodePoint(0x1F600)} "); doc.Add(p); doc.Close(); }
public static void LoadContent(ContentManager Content) { FontProvider.AddFont("Pericles8", Content.Load <SpriteFont>(@"fonts/pericles8")); FontProvider.AddFont("Pericles9", Content.Load <SpriteFont>(@"fonts/pericles9")); FontProvider.AddFont("Pericles14", Content.Load <SpriteFont>(@"fonts/pericles14")); FontProvider.AddFont("Pericles21", Content.Load <SpriteFont>(@"fonts/pericles21")); FontProvider.AddFont("Mono14", Content.Load <SpriteFont>(@"fonts/mono14")); FontProvider.AddFont("Mono21", Content.Load <SpriteFont>(@"fonts/mono21")); TitleScreenManager.LoadContent(Content.Load <Texture2D>(@"textures/misc/TitleScreen")); VariableProvider.WhiteTexture = Content.Load <Texture2D>(@"textures/misc/white"); AnimationDictionaryProvider.LoadAnimationStrips(Content); MugShotProvider.DummyMugShotAngry = Content.Load <Texture2D>(@"textures/misc/mugshots/dummyangry"); MugShotProvider.DummyMugShotNormal = Content.Load <Texture2D>(@"textures/misc/mugshots/dummynormal"); DialogManager.Initialize(); }
public virtual void LatinAndNotdefGroup() { String outFileName = destinationFolder + "latinAndNotdefGroup.pdf"; String cmpFileName = sourceFolder + "cmp_latinAndNotdefGroup.pdf"; FontProvider sel = new FontProvider(); NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "Puritan2.otf")); String s = "Hello мир!"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create))); Document doc = new Document(pdfDoc); doc.SetFontProvider(sel); doc.SetFont("Puritan"); Text text = new Text(s).SetBackgroundColor(ColorConstants.LIGHT_GRAY); Paragraph paragraph = new Paragraph(text); doc.Add(paragraph); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
private void LoadContent() { var content = Editor.Content; _spriteBatch = Editor.spriteBatch; VariableProvider.SpriteBatch = _spriteBatch; TileMap = new TileMap <Map <TileCode>, TileCode>(8, 8, 0, content.Load <SpriteFont>(@"fonts/mono8"), content.Load <Texture2D>(@"textures/spritesheets/tilesheet"), Layers); AnimationDictionaryProvider.Content = content; _player = Factory.CreatePlayer(); _player.Position = new Vector2(float.MaxValue, float.MaxValue); VariableProvider.CurrentPlayer = _player; EntityManager.SetPlayer(); _renderTarget = new RenderTarget2D(GraphicsDevice, 320, 240, false, GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); GameInitializer.Initialize(); _coordList = VariableProvider.CoordList; EngineState.GameState = EngineStates.Editor; BulletInformationProvider.LoadBulletData(content); FontProvider.AddFont("Mono8", content.Load <SpriteFont>("fonts/mono8")); }
/// <summary> /// Convierte texto html de entrada en un archivo pdf. /// </summary> /// <param name="html">Html a convertir en pdf.</param> /// <param name="orientation">Orientación.</param> /// <param name="fontData">Byte content of the font program file.</param> /// <returns>Datos binarios del pdf.</returns> public byte[] GetPdfFormHtml(string html, string orientation = "PORTRAIT", byte[] fontData = null) { QRCodeTagWorkerFactory = new QRCodeTagWorkerFactory(); ConverterProperties properties = new ConverterProperties(); properties.SetTagWorkerFactory(QRCodeTagWorkerFactory); properties.SetCssApplierFactory(new QRCodeTagCssApplierFactory()); if (fontData != null) { FontProvider fontProvider = new FontProvider(); fontProvider.AddFont(fontData, PdfEncodings.IDENTITY_H); properties.SetFontProvider(fontProvider); } byte[] result = null; using (var ms = new MemoryStream()) { using (var pdfDocument = new PdfDocument(new PdfWriter(ms))) { if (orientation.ToUpper() == "LANDSCAPE") { pdfDocument.SetDefaultPageSize(PageSize.A4.Rotate()); } HtmlConverter.ConvertToPdf(html, pdfDocument, properties); result = ms.ToArray(); } } return(result); }