Edit me

Drawing Texts in PDF

Using TTF/OTF fonts with embedding subset

  • Emgedding fonts are required to view and print PDF documents without environtal restrictions. If the pc doesn’t have fonts that are used in PDF, the viewer tries to find font resource in the PDF file, in case the fonts are not embedded in the PDF, the texts cannot be seen correctly.

  • Embedding fonts makes the PDF file bigger, because the size of font file with CJK(Chinese - 30,000~150,000 characters in unicode, Japanese, Korean - 11,000 characters) fonts is few mega bytes or larger. So, we need subset embedding for embedding only used characters in the PDF document.

    lPdfBFont = FontFactory.GetFont(lsFontNameEng, BaseFont.IDENTITY_H, BaseFont.EMBEDDED).BaseFont;
    lPdfBFont.Subset = true;</br>

Drawing Texts in PDF Page

  • Set position and rotation with transformation

    lPdfContent.SetFontAndSize(lPdfBFont, lfFontSize * lfFontAdjustScale);
    iTextSharp.awt.geom.AffineTransform lTransA = new iTextSharp.awt.geom.AffineTransform();

    if (lCD.fRotation == 0F)
    {
    lTransA.Translate(lptfAPos.X + lptfAdjPos.X, lptfAPos.Y - lptfAdjPos.Y);
    }
    else
    {
    lTransA.Translate(lptfAPos.X, lptfAPos.Y);
    lTransA.Rotate(-(lCD.fRotation * Math.PI / 180.0));
    lTransA.Translate(lptfAdjPos.X, -lptfAdjPos.Y);
    }
    lPdfContent.Transform(lTransA);

  • Set Hoizontal/Vertical Flip

    if (lCD.cbFontFlipHorz || lCD.cbFontFlipVert)
    {
    lPdfContent.SaveState();
    if (lCD.cbFontFlipVert)
    lPdfContent.ConcatCTM(1, 0, 0, -1, 0, OrionConfigInfo.UCNV.GetPointFromPixel((float)lSZFCH.CharHeight, lPD.fHeightDPI) / 2F);
    if (lCD.cbFontFlipHorz)
    lPdfContent.ConcatCTM(-1, 0, 0, 1, OrionConfigInfo.UCNV.GetPointFromPixel((float)lSZFCH.CharWidth, lPD.fWidthDPI) * 1F, 0);
    }

  • Place Text

    lPdfContent.SetTextRise(0F);
    lPdfContent.SetLeading(0F);
    lPdfContent.BeginText();

    if (lCD.bFontStyleItalic)
    {
    float lfItalicization = lfFontSize / 50F;
    lPdfContent.SaveState();
    lPdfContent.ConcatCTM(1F, 0F, lfItalicization, 1F, 0F, 0F);
    lPdfContent.ShowText(lSZFCH.CH.ToString());
    lPdfContent.RestoreState();
    }
    else
    {
    lPdfContent.ShowText(lSZFCH.CH.ToString());
    }

    lPdfContent.EndText();

Tags: