Small Caps again

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v7)  /  Re: Small Caps again

DynamicPDF CoreSuite for .NET (v7) Forum

 Dec 07 2012 5:55 AM
I found a post about this for version4 and 5, and the answer was:

"You can also add this text by using a true type, open type, or type1 font which has support to add small caps text. In this case there is no need to adjust the font size every time. Please refer to the fonts on our help documentation."

How exactly do you add small caps text this way?
 Dec 07 2012 7:07 AM
Posted by a ceTe Software moderator
Hello,

Yes, you can add text in small caps style using our DynamicPDF Generator for .NET product. You will need to use a TTF, OTF font which has support for small caps style. You will need to build OpenTypeFont class object using the font file path and set this font object to the page elements. You can refer documentation on OpenTypeFont class here. Below is the sample code for it.

              Document document = new Document();
            Page page = new Page();
            document.Pages.Add(page);
            //Build font object using the font file path which has support for the small cap text.
            OpenTypeFont fontObj = new OpenTypeFont(@"path of the TTF or OTF font file");
            TextArea area = new TextArea("This is to test ", 100, 100, 200, 400);
            area.Font = fontObj;
            page.Elements.Add(area);
            document.Draw(@"C:\MyDocumet.pdf");

Thanks,
ceTe Software Support Team.
 Dec 07 2012 8:16 AM
But where do you tell the font-object to do SmallCaps and not just normal text?

Do we need to create a custom SmallCaps-version of the OpenType-fontfile to get it to work?
 Dec 07 2012 8:51 AM
Posted by a ceTe Software moderator
Hello,

You need not have to build custom small cap version of the OTF or TTF font file. You will need to use a font which supports small caps.  You will have to apply the Font object which is built using font file to the page elements. This will automatically sets the font style to the text. You will need to find some vendor who can provide a font which supports small caps.

Below is the sample code in which we used a small cap font and built OpenTypeFont object and applied to the TextArea page element. Similarly you will need to use small cap font in your application.

              Document document = new Document();
            Page page = new Page();
            document.Pages.Add(page);
            //Below code creates OpenTypeFont object using small cap font.
            OpenTypeFont fontObj = new OpenTypeFont(@"C:\WINDOWS\Fonts\smallcap.ttf");
            TextArea area = new TextArea("This is to test ", 100, 100, 200, 400);
            area.Font = fontObj;
            page.Elements.Add(area);
            document.Draw(@"C:\MyDocumet.pdf");

Thanks,
ceTe Software Support Team.
 Dec 07 2012 9:21 AM
Cannot get it to work unless a custom made font is made. Sent screenshot and fontfile to support@cete.com
 Dec 07 2012 3:59 PM
Posted by a ceTe Software moderator
Hello,

It is not possible to set small caps with regular font that does not support small caps characters. You would need to use font that supports small caps.

As a workaround you could use FormattedTextArea with the regular font and achieve the small caps effect. Please refer to the code below.

            Document document = new Document();
            Page page = new Page();
            document.Pages.Add(page);
          
            //FormattedTextArea workaround to acheive small caps effect using regular font.            
            FormattedTextAreaStyle style = new FormattedTextAreaStyle(FontFamily.Helvetica, 10, false);
            string formattedText = "<p><font pointSize='12'>H</font><font pointSize='8'>ELLO</font> <font pointSize='12'>W</font><font pointSize='8'>ORLD</font></p>";
            FormattedTextArea formattedTextArea = new FormattedTextArea(formattedText, 0, 300, 256, 400, style);

            page.Elements.Add(formattedTextArea);
            document.Draw("test.pdf");

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 4:27 AM.