iTextSharp.text.pdf.PdfAppearance.SetFontAndSize C# (CSharp) Метод

SetFontAndSize() публичный Метод

public SetFontAndSize ( BaseFont bf, float size ) : void
bf BaseFont
size float
Результат void
        public override void SetFontAndSize(BaseFont bf, float size)
        {
            CheckWriter();
            state.size = size;
            if (bf.FontType == BaseFont.FONT_TYPE_DOCUMENT) {
                state.fontDetails = new FontDetails(null, ((DocumentFont)bf).IndirectReference, bf);
            }
            else
                state.fontDetails = writer.AddSimple(bf);
            PdfName psn;
            stdFieldFontNames.TryGetValue(bf.PostscriptFontName, out psn);
            if (psn == null) {
                if (bf.Subset && bf.FontType == BaseFont.FONT_TYPE_TTUNI)
                    psn = state.fontDetails.FontName;
                else {
                    psn = new PdfName(bf.PostscriptFontName);
                    state.fontDetails.Subset = false;
                }
            }
            PageResources prs = PageResources;
            prs.AddFont(psn, state.fontDetails.IndirectReference);
            content.Append(psn.GetBytes()).Append(' ').Append(size).Append(" Tf").Append_i(separator);
        }

Usage Example

Пример #1
0
        public void DrawCheckBoxAppearences(PdfFormField field, string value, float llx, float lly, float urx, float ury)
        {
            BaseFont       font = BaseFont.CreateFont(BaseFont.ZAPFDINGBATS, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
            float          size = (ury - lly);
            PdfContentByte cb   = writer.DirectContent;
            PdfAppearance  tpOn = cb.CreateAppearance(urx - llx, ury - lly);
            PdfAppearance  tp2  = (PdfAppearance)tpOn.Duplicate;

            tp2.SetFontAndSize(font, size);
            tp2.ResetRGBColorFill();
            field.DefaultAppearanceString = tp2;
            tpOn.DrawTextField(0f, 0f, urx - llx, ury - lly);
            tpOn.SaveState();
            tpOn.ResetRGBColorFill();
            tpOn.BeginText();
            tpOn.SetFontAndSize(font, size);
            tpOn.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "4", (urx - llx) / 2, (ury - lly) / 2 - (size * 0.3f), 0);
            tpOn.EndText();
            tpOn.RestoreState();
            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, value, tpOn);
            PdfAppearance tpOff = cb.CreateAppearance(urx - llx, ury - lly);

            tpOff.DrawTextField(0f, 0f, urx - llx, ury - lly);
            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
        }
All Usage Examples Of iTextSharp.text.pdf.PdfAppearance::SetFontAndSize