Beispiel #1
0
        public override T1 GetDefaultProperty <T1>(int property)
        {
            try {
                switch (property)
                {
                case Property.FONT: {
                    if (defaultFont == null)
                    {
                        defaultFont = PdfFontFactory.CreateFont();
                    }
                    return((T1)(Object)defaultFont);
                }

                case Property.FONT_PROVIDER: {
                    if (defaultFontProvider == null)
                    {
                        defaultFontProvider = new FontProvider();
                    }
                    return((T1)(Object)defaultFontProvider);
                }

                case Property.SPLIT_CHARACTERS: {
                    if (defaultSplitCharacters == null)
                    {
                        defaultSplitCharacters = new DefaultSplitCharacters();
                    }
                    return((T1)(Object)defaultSplitCharacters);
                }

                case Property.FONT_SIZE: {
                    return((T1)(Object)UnitValue.CreatePointValue(12));
                }

                case Property.TAGGING_HELPER: {
                    return((T1)(Object)InitTaggingHelperIfNeeded());
                }

                case Property.TEXT_RENDERING_MODE: {
                    return((T1)(Object)PdfCanvasConstants.TextRenderingMode.FILL);
                }

                case Property.TEXT_RISE: {
                    return((T1)(Object)0f);
                }

                case Property.SPACING_RATIO: {
                    return((T1)(Object)0.75f);
                }

                default: {
                    return((T1)(Object)null);
                }
                }
            }
            catch (System.IO.IOException exc) {
                throw new Exception(exc.ToString(), exc);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Installs providers that expose resources for Noesis theme.
        /// </summary>
        public static void SetThemeProviders(XamlProvider xamlProvider = null, FontProvider fontProvider = null, TextureProvider textureProvider = null)
        {
            GUI.SetXamlProvider(new EmbeddedXamlProvider(null, null, xamlProvider));
            GUI.SetFontProvider(new EmbeddedFontProvider(null, null, fontProvider));
            GUI.SetTextureProvider(textureProvider);

            GUI.SetFontFallbacks(Theme.FontFallbacks);
            GUI.SetFontDefaultProperties(Theme.DefaultFontSize, Theme.DefaultFontWeight, Theme.DefaultFontStretch, Theme.DefaultFontStyle);
        }
 /// <summary>
 /// Creates new
 /// <see cref="SvgProcessorResult"/>
 /// entity.
 /// </summary>
 /// <param name="namedObjects">
 /// a map of named-objects with their id's as
 /// <see cref="System.String"/>
 /// keys and
 /// the
 /// <see cref="iText.Svg.Renderers.ISvgNodeRenderer"/>
 /// objects as values.
 /// </param>
 /// <param name="root">
 /// a wrapped
 /// <see cref="iText.Svg.Renderers.ISvgNodeRenderer"/>
 /// root renderer.
 /// </param>
 /// <param name="context">
 /// a
 /// <see cref="SvgProcessorContext"/>
 /// instance.
 /// </param>
 public SvgProcessorResult(IDictionary <String, ISvgNodeRenderer> namedObjects, ISvgNodeRenderer root, SvgProcessorContext
                           context)
 {
     this.namedObjects = namedObjects;
     this.root         = root;
     this.fontProvider = context.GetFontProvider();
     this.tempFonts    = context.GetTempFonts();
     this.context      = context;
 }
Beispiel #4
0
        /// <summary>
        /// Creates a new instance of the LcarsButtonBase object
        /// </summary>
        /// <remarks></remarks>
        public LcarsButtonBase() : base()
        {
            // for designer, InitEvents (esp resize) before InitializeComponent()
            InitEvents();

            textSize = Size;
            font     = FontProvider.Lcars(textHeight);
            InitializeComponent();
            base.DoubleBuffered = true;
        }
Beispiel #5
0
        public virtual void RunTest(String testName, FontProvider fontProvider)
        {
            String outPdf  = destinationFolder + testName + ".pdf";
            String cmpPdf  = sourceFolder + "cmp_" + testName + ".pdf";
            String srcHtml = sourceFolder + "genericFontFamilies.html";
            ConverterProperties properties = new ConverterProperties().SetFontProvider(fontProvider);

            HtmlConverter.ConvertToPdf(new FileInfo(srcHtml), new FileInfo(outPdf), properties);
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_"
                                                                             + testName + "_"));
        }
Beispiel #6
0
        public EmbeddedFontProvider(Assembly assembly, string ns, FontProvider provider)
        {
            _assembly  = assembly;
            _namespace = ns;
            _provider  = provider;

            // Register application font resources
            RegisterFontResources(_assembly, _namespace);

            // Register Theme font resources
            RegisterFontResources(Theme.Assembly, Theme.Namespace);
        }
Beispiel #7
0
 /// <summary>
 /// Instantiates a new
 /// <see cref="ConverterProperties"/>
 /// instance based on another
 /// <see cref="ConverterProperties"/>
 /// instance
 /// (copy constructor).
 /// </summary>
 /// <param name="other">
 /// the other
 /// <see cref="ConverterProperties"/>
 /// instance
 /// </param>
 public ConverterProperties(iText.Html2pdf.ConverterProperties other)
 {
     this.mediaDeviceDescription = other.mediaDeviceDescription;
     this.fontProvider           = other.fontProvider;
     this.tagWorkerFactory       = other.tagWorkerFactory;
     this.cssApplierFactory      = other.cssApplierFactory;
     this.baseUri        = other.baseUri;
     this.createAcroForm = other.createAcroForm;
     this.outlineHandler = other.outlineHandler;
     this.charset        = other.charset;
     this.metaInfo       = other.metaInfo;
 }
Beispiel #8
0
        public LabelTest()
        {
            fontCore = new FakeFontCore("default");
            font     = new Font(fontCore);

            fontProvider = new FontProvider();
            fontProvider.Add("default", font);

            contentLayout = new ContentLayoutEngine(fontProvider);

            context = CommonMocks.RenderContext(contentLayout);
        }
Beispiel #9
0
 public NoesisProviderManager(
     XamlProvider xamlProvider,
     FontProvider fontProvider,
     TextureProvider textureProvider)
 {
     this.provider = new Provider()
     {
         XamlProvider    = xamlProvider,
         TextureProvider = textureProvider,
         FontProvider    = fontProvider
     };
 }
        internal static ConverterProperties InitConverterProperties()
        {
            ConverterProperties converterProperties = new ConverterProperties();

            converterProperties.SetBaseUri(SOURCE_FOLDER);
            FontProvider fontProvider = new FontProvider();

            fontProvider.AddDirectory(RESOURCES);
            fontProvider.AddStandardPdfFonts();
            converterProperties.SetFontProvider(fontProvider);
            return(converterProperties);
        }
Beispiel #11
0
 /// <summary>
 /// Creates a new
 /// <see cref="OcrPdfCreatorProperties"/>
 /// instance
 /// based on another
 /// <see cref="OcrPdfCreatorProperties"/>
 /// instance (copy
 /// constructor).
 /// </summary>
 /// <param name="other">
 /// the other
 /// <see cref="OcrPdfCreatorProperties"/>
 /// instance
 /// </param>
 public OcrPdfCreatorProperties(iText.Pdfocr.OcrPdfCreatorProperties other)
 {
     this.scaleMode         = other.scaleMode;
     this.pageSize          = other.pageSize;
     this.imageLayerName    = other.imageLayerName;
     this.textLayerName     = other.textLayerName;
     this.textColor         = other.textColor;
     this.pdfLang           = other.pdfLang;
     this.title             = other.title;
     this.fontProvider      = other.fontProvider;
     this.defaultFontFamily = other.defaultFontFamily;
 }
Beispiel #12
0
 public SvgDrawContext(ResourceResolver resourceResolver, FontProvider fontProvider)
 {
     if (resourceResolver == null)
     {
         resourceResolver = new ResourceResolver("");
     }
     this.resourceResolver = resourceResolver;
     if (fontProvider == null)
     {
         fontProvider = new BasicFontProvider();
     }
     this.fontProvider = fontProvider;
 }
Beispiel #13
0
 public FF14Service(DiscordSocketClient client,
                    DbService db, EvilMortyBot bot, IDataCache cache,
                    FontProvider fonts)
 {
     Http = new HttpClient();
     Http.AddFakeHeaders();
     _client = client;
     _db     = db;
     _log    = LogManager.GetCurrentClassLogger();
     _imgs   = cache.LocalImages;
     _cache  = cache;
     _fonts  = fonts;
 }
        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());
        }
Beispiel #15
0
        public virtual void NonBreakingHyphenDifferentFonts()
        {
            //TODO: update after fix of DEVSIX-2034
            String       outFileName = destinationFolder + "nonBreakingHyphenDifferentFonts.pdf";
            String       cmpFileName = sourceFolder + "cmp_nonBreakingHyphenDifferentFonts.pdf";
            String       diffPrefix  = "diff01_";
            Document     document    = new Document(new PdfDocument(new PdfWriter(outFileName)));
            FontProvider sel         = new FontProvider();

            sel.GetFontSet().AddFont(StandardFonts.TIMES_ROMAN);
            sel.GetFontSet().AddFont(StandardFonts.COURIER);
            sel.GetFontSet().AddFont(fontsFolder + "Puritan2.otf", PdfEncodings.IDENTITY_H, "Puritan2");
            sel.GetFontSet().AddFont(fontsFolder + "NotoSans-Regular.ttf", PdfEncodings.IDENTITY_H, "NotoSans");
            document.SetFontProvider(sel);
            document.Add(new Paragraph("StandardFonts - non-breaking hyphen \\u2011").SetUnderline().SetTextAlignment(
                             TextAlignment.CENTER));
            document.Add(new Paragraph("for Standard font TIMES_ROMAN: <&#8209;> non-breaking hyphen <\u2011> 2 hyphens<\u2011\u2011>here "
                                       ).SetFont(StandardFonts.TIMES_ROMAN));
            document.Add(new Paragraph("for Standard font COURIER: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here "
                                       ).SetFont(StandardFonts.COURIER));
            document.Add(new Paragraph("for Standard font HELVETICA_BOLD: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here "
                                       ).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD)));
            document.Add(new Paragraph("for Standard font SYMBOL: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here "
                                       ).SetFont(PdfFontFactory.CreateFont(StandardFonts.SYMBOL)));
            document.Add(new Paragraph("Non-Standard fonts - non-breaking hyphen \\u2011").SetUnderline().SetTextAlignment
                             (TextAlignment.CENTER));
            document.Add(new Paragraph("for NotoSans: <&#8209;> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("NotoSans"
                                                                                                                     ));
            document.Add(new Paragraph("for Puritan2: <&#8209;> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("Puritan2"
                                                                                                                     ));
            sel.GetFontSet().AddFont(fontsFolder + "FreeSans.ttf", PdfEncodings.IDENTITY_H, "FreeSans");
            document.Add(new Paragraph("AFTER adding of FreeSans font with non-breaking hyphen \\u2011 support").SetUnderline
                             ().SetTextAlignment(TextAlignment.CENTER));
            document.Add(new Paragraph("for Standard font TIMES_ROMAN: <&#8209;> non-breaking hyphen <\u2011> 2 hyphens<\u2011\u2011>here "
                                       ).SetFont(StandardFonts.TIMES_ROMAN));
            document.Add(new Paragraph("for Standard font COURIER: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here "
                                       ).SetFont(StandardFonts.COURIER));
            document.Add(new Paragraph("for Standard font HELVETICA_BOLD: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here "
                                       ).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD)));
            document.Add(new Paragraph("for Standard font SYMBOL: <&#8209;> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here "
                                       ).SetFont(PdfFontFactory.CreateFont(StandardFonts.SYMBOL)));
            document.Add(new Paragraph("for FreeSans: <&#8209;> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("FreeSans"
                                                                                                                     ));
            document.Add(new Paragraph("for NotoSans: <&#8209;> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("NotoSans"
                                                                                                                     ));
            document.Add(new Paragraph("for Puritan2: <&#8209;> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("Puritan2"
                                                                                                                     ));
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , diffPrefix));
        }
        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);
        }
Beispiel #17
0
        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;
        }
Beispiel #18
0
 /// <summary>Places retrieved text to canvas to a separate layer.</summary>
 /// <param name="imageSize">
 /// size of the image according to the selected
 /// <see cref="ScaleMode"/>
 /// </param>
 /// <param name="pageText">text that was found on this image (or on this page)</param>
 /// <param name="pdfCanvas">canvas to place the text</param>
 /// <param name="multiplier">coefficient to adjust text placing on canvas</param>
 /// <param name="pageMediaBox">page parameters</param>
 private void AddTextToCanvas(Rectangle imageSize, IList <TextInfo> pageText, PdfCanvas pdfCanvas, float multiplier
                              , Rectangle pageMediaBox)
 {
     if (pageText != null && pageText.Count > 0)
     {
         Point imageCoordinates = PdfCreatorUtil.CalculateImageCoordinates(ocrPdfCreatorProperties.GetPageSize(), imageSize
                                                                           );
         foreach (TextInfo item in pageText)
         {
             String        line         = item.GetText();
             IList <float> coordinates  = item.GetBbox();
             float         left         = coordinates[0] * multiplier;
             float         right        = (coordinates[2] + 1) * multiplier - 1;
             float         top          = coordinates[1] * multiplier;
             float         bottom       = (coordinates[3] + 1) * multiplier - 1;
             float         bboxWidthPt  = PdfCreatorUtil.GetPoints(right - left);
             float         bboxHeightPt = PdfCreatorUtil.GetPoints(bottom - top);
             FontProvider  fontProvider = GetOcrPdfCreatorProperties().GetFontProvider();
             String        fontFamily   = GetOcrPdfCreatorProperties().GetDefaultFontFamily();
             if (!String.IsNullOrEmpty(line) && bboxHeightPt > 0 && bboxWidthPt > 0)
             {
                 Document document = new Document(pdfCanvas.GetDocument());
                 document.SetFontProvider(fontProvider);
                 // Scale the text width to fit the OCR bbox
                 float fontSize             = PdfCreatorUtil.CalculateFontSize(document, line, fontFamily, bboxHeightPt, bboxWidthPt);
                 float lineWidth            = PdfCreatorUtil.GetRealLineWidth(document, line, fontFamily, fontSize);
                 float deltaX               = PdfCreatorUtil.GetPoints(left);
                 float deltaY               = imageSize.GetHeight() - PdfCreatorUtil.GetPoints(bottom);
                 iText.Layout.Canvas canvas = new iText.Layout.Canvas(pdfCanvas, pageMediaBox);
                 canvas.SetFontProvider(fontProvider);
                 Text      text      = new Text(line).SetHorizontalScaling(bboxWidthPt / lineWidth);
                 Paragraph paragraph = new Paragraph(text).SetMargin(0).SetMultipliedLeading(1.2f);
                 paragraph.SetFontFamily(fontFamily).SetFontSize(fontSize);
                 paragraph.SetWidth(bboxWidthPt * 1.5f);
                 if (ocrPdfCreatorProperties.GetTextColor() != null)
                 {
                     paragraph.SetFontColor(ocrPdfCreatorProperties.GetTextColor());
                 }
                 else
                 {
                     paragraph.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.INVISIBLE);
                 }
                 canvas.ShowTextAligned(paragraph, deltaX + (float)imageCoordinates.x, deltaY + (float)imageCoordinates.y,
                                        TextAlignment.LEFT);
                 canvas.Close();
             }
         }
     }
 }
Beispiel #19
0
 /// <summary>Resets the context.</summary>
 public virtual void Reset()
 {
     this.pdfDocument = null;
     this.state       = new State();
     this.resourceResolver.ResetCache();
     this.cssContext  = new CssContext();
     this.linkContext = new LinkContext();
     this.formFieldNameResolver.Reset();
     //Reset font provider. PdfFonts shall be reseted.
     this.fontProvider = new BasicFontProvider(this.fontProvider.GetFontSet(), this.fontProvider.GetDefaultFontFamily
                                                   ());
     this.tempFonts = null;
     this.outlineHandler.Reset();
     this.processingInlineSvg = false;
 }
        public LabelWithLocalizationTest()
        {
            fontCore = new FakeFontCore("default");
            font     = new Font(fontCore);

            fontProvider = new FontProvider();
            fontProvider.Add("default", font);

            textRepo = new TextRepository();

            contentLayout = new LocalizedContentLayoutEngine(
                new ContentLayoutEngine(fontProvider), textRepo);

            context = CommonMocks.RenderContext(contentLayout);
        }
Beispiel #21
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            spriteBatch.DrawString(
                FontProvider.GetFont(fontName),
                confirmText + GameVariableProvider.SaveState.PlayerName + "?",
                ShortcutProvider.Vector2Point(menuItems[0].ItemPosition - itemOffset - new Vector2(ShortcutProvider.GetFontCenter(fontName, confirmText + GameVariableProvider.SaveState.PlayerName + "?").X, 0)),
                Color.White,
                0,
                Vector2.Zero,
                1,
                SpriteEffects.None,
                .2f);
        }
 /// <summary>
 /// Instantiates a new
 /// <see cref="ProcessorContext"/>
 /// instance.
 /// </summary>
 /// <param name="converterProperties">
 /// a
 /// <see cref="iText.Html2pdf.ConverterProperties"/>
 /// instance
 /// </param>
 public ProcessorContext(ConverterProperties converterProperties)
 {
     if (converterProperties == null)
     {
         converterProperties = new ConverterProperties();
     }
     state             = new State();
     deviceDescription = converterProperties.GetMediaDeviceDescription();
     if (deviceDescription == null)
     {
         deviceDescription = MediaDeviceDescription.GetDefault();
     }
     fontProvider = converterProperties.GetFontProvider();
     if (fontProvider == null)
     {
         fontProvider = new DefaultFontProvider();
     }
     tagWorkerFactory = converterProperties.GetTagWorkerFactory();
     if (tagWorkerFactory == null)
     {
         tagWorkerFactory = DefaultTagWorkerFactory.GetInstance();
     }
     cssApplierFactory = converterProperties.GetCssApplierFactory();
     if (cssApplierFactory == null)
     {
         cssApplierFactory = DefaultCssApplierFactory.GetInstance();
     }
     baseUri = converterProperties.GetBaseUri();
     if (baseUri == null)
     {
         baseUri = "";
     }
     outlineHandler = converterProperties.GetOutlineHandler();
     if (outlineHandler == null)
     {
         outlineHandler = new OutlineHandler();
     }
     resourceResolver      = new HtmlResourceResolver(baseUri, this, converterProperties.GetResourceRetriever());
     limitOfLayouts        = converterProperties.GetLimitOfLayouts();
     cssContext            = new CssContext();
     linkContext           = new LinkContext();
     createAcroForm        = converterProperties.IsCreateAcroForm();
     formFieldNameResolver = new FormFieldNameResolver();
     radioCheckResolver    = new RadioCheckResolver();
     immediateFlush        = converterProperties.IsImmediateFlush();
     metaInfo            = converterProperties.GetEventCountingMetaInfo();
     processingInlineSvg = false;
 }
Beispiel #23
0
        public void ManipulatePdf(string src, string dest)
        {
            WriterProperties writerProperties = new WriterProperties();

            writerProperties.AddXmpMetadata();

            PdfWriter   pdfWriter = new PdfWriter(dest, writerProperties);
            PdfDocument pdfDoc    = new PdfDocument(pdfWriter);

            pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));

            pdfDoc.SetTagged();
            pdfDoc.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true));

            PdfDocumentInfo pdfMetaData = pdfDoc.GetDocumentInfo();

            pdfMetaData.SetAuthor("Samuel Huylebroeck");
            pdfMetaData.AddCreationDate();
            pdfMetaData.GetProducer();
            pdfMetaData.SetCreator("iText Software");
            pdfMetaData.SetKeywords("example, accessibility");
            pdfMetaData.SetSubject("PDF accessibility");

            // Title is derived from html

            // pdf conversion
            ConverterProperties props        = new ConverterProperties();
            FontProvider        fontProvider = new FontProvider();

            fontProvider.AddStandardPdfFonts();
            fontProvider.AddDirectory(SRC);

            // The noto-nashk font file (.ttf extension) is placed in the resources
            props.SetFontProvider(fontProvider);
            // Base URI is required to resolve the path to source files
            props.SetBaseUri(SRC);

            // Setup custom tagworker factory for better tagging of headers
            DefaultTagWorkerFactory tagWorkerFactory = new AccessibilityTagWorkerFactory();

            props.SetTagWorkerFactory(tagWorkerFactory);

            HtmlConverter.ConvertToPdf(new FileStream(src, FileMode.Open), pdfDoc, props);

            pdfDoc.Close();
        }
        public void CanLoadAllNecessaryFonts()
        {
            var fontProvider = new FontProvider();

            foreach (var fontName in _fontNames)
            {
                Assert.NotNull(fontProvider.GetFontFamily(fontName));
            }
            foreach (var fontName in _fontNames)
            {
                Assert.NotNull(fontProvider.GetFont(fontName, FontSize.FromPixels(23)));
            }
            foreach (var fontName in _fontNames)
            {
                Assert.NotNull(fontProvider.GetFont(fontProvider.GetFontFamily(fontName), FontSize.FromPixels(23)));
            }
        }
Beispiel #25
0
        /// <summary>
        /// Perform OCR using provided path to image (imgPath)
        /// and save result PDF document to "pdfPath".
        /// </summary>
        /// <remarks>
        /// Perform OCR using provided path to image (imgPath)
        /// and save result PDF document to "pdfPath".
        /// (Method is used for compare tool)
        /// </remarks>
        protected internal virtual void DoOcrAndSavePdfToPath(AbstractTesseract4OcrEngine tesseractReader, String
                                                              imgPath, String pdfPath, IList <String> languages, IList <String> fonts, Color color)
        {
            if (languages != null)
            {
                Tesseract4OcrEngineProperties properties = tesseractReader.GetTesseract4OcrEngineProperties();
                properties.SetLanguages(languages);
                tesseractReader.SetTesseract4OcrEngineProperties(properties);
            }
            OcrPdfCreatorProperties properties_1 = new OcrPdfCreatorProperties();

            properties_1.SetPdfLang("en-US");
            properties_1.SetTitle("");
            if (fonts != null && fonts.Count > 0)
            {
                FontProvider fontProvider = new FontProvider();
                foreach (String fontPath in fonts)
                {
                    String name = FONT_PATH_TO_FONT_NAME_MAP.Get(fontPath);
                    fontProvider.GetFontSet().AddFont(fontPath, PdfEncodings.IDENTITY_H, name);
                }
                properties_1.SetFontProvider(fontProvider);
            }
            if (color != null)
            {
                properties_1.SetTextColor(color);
            }
            if (languages != null)
            {
                NUnit.Framework.Assert.AreEqual(languages.Count, tesseractReader.GetTesseract4OcrEngineProperties().GetLanguages
                                                    ().Count);
            }
            OcrPdfCreator ocrPdfCreator = new OcrPdfCreator(tesseractReader, properties_1);

            try {
                using (PdfWriter pdfWriter = GetPdfWriter(pdfPath)) {
                    PdfDocument doc = ocrPdfCreator.CreatePdf(JavaCollectionsUtil.SingletonList <FileInfo>(new FileInfo(imgPath
                                                                                                                        )), pdfWriter);
                    NUnit.Framework.Assert.IsNotNull(doc);
                    doc.Close();
                }
            }
            catch (System.IO.IOException e) {
                LOGGER.Error(e.Message);
            }
        }
        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();
        }
Beispiel #28
0
        void CompilePreviewPagesEx(System.Drawing.Printing.PrintPageEventArgs e)
        {
            Application.DoEvents();
            float             height     = e.MarginBounds.Height / document.PageHeight;
            float             leftMargin = e.MarginBounds.Left;
            float             topMargin  = e.MarginBounds.Top;
            float             yPos       = topMargin;
            Font              printFont  = FontProvider.GetFont(document.Cpi);
            ClassicReportPage page       = document[fromPage];

            for (int rowIndex = 0; rowIndex < document.PageHeight; rowIndex++)
            {
                string rowString = page.ToString(rowIndex);
                rowString = rowString.Replace(' ', 'M');
                foreach (ClassicReportPageItem item in page.GetItems(rowIndex))
                {
                    float xPos = leftMargin;
                    if (item.Offset > 0)
                    {
                        string trailer = rowString.Substring(0, item.Offset - 1);
                        xPos += e.Graphics.MeasureString(trailer, printFont).Width;
                    }
                    FontStyle fontStyle = FontStyle.Regular;
                    if (item.IsBold)
                    {
                        fontStyle |= FontStyle.Bold;
                    }
                    if (item.IsItalic)
                    {
                        fontStyle |= FontStyle.Italic;
                    }
                    if (item.IsUnderline)
                    {
                        fontStyle |= FontStyle.Underline;
                    }
                    Font itemFont = new Font(printFont, fontStyle);
                    e.Graphics.DrawString(item.Value, itemFont, Brushes.Black, xPos, yPos);
                    itemFont.Dispose();
                }
                yPos += height;
            }
            e.HasMorePages = ++fromPage <= toPage;
            printFont.Dispose();
        }
        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());
        }
Beispiel #30
0
        public static void Create(string dest)
        {
            PdfWriter pdfWriter = new PdfWriter(dest);

            PdfDocument pdfDoc = new PdfDocument(pdfWriter);

            // pdf conversion
            ConverterProperties props = new ConverterProperties();
            FontProvider        fp    = new FontProvider();

            fp.AddStandardPdfFonts();
            fp.AddDirectory(@"fonts");//The noto-nashk font file (.ttf extension) is placed in the resources

            props.SetFontProvider(fp);
            props.SetBaseUri(@"fonts");
            //Setup custom tagworker factory for better tagging of headers
            HtmlConverter.ConvertToPdf(@"<h1>Hello</h1><p>world</p>", pdfDoc, props);
            pdfDoc.Close();
        }