embedding ttf fonts

View: New views
2 Messages — Rating Filter:   Alert me  

embedding ttf fonts

by Jason Berk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey guys,

I've read the chapter on using fonts repeatedly and I'm still really
confused.

I have three TTF fonts that are custom (they contain logos).  Obviously,
I need to embed these into the PDF.  I also need to be able to get their
"BaseFont" so I can position them absolutely.

I seem to be registering my fonts correctly:

logger.info("registering required fonts:");
                String[] fonts = new String[]{"CREDITCARD.ttf",
"OCRAEXT.ttf", "PURDUE.ttf", "SCORECARD.ttf"};
                for(String font:fonts){
                        logger.info("fonts/" + font);
                        FontFactory.register("fonts/"+font);
                }
                for (Iterator i =
FontFactory.getRegisteredFonts().iterator(); i.hasNext(); ) {
            System.out.println((String) i.next());
        }

Gives me this:

main 16:43:06,714 INFO Driver (<init>:18) - registering required fonts:
main 16:43:06,714 INFO Driver (<init>:21) - fonts/CREDITCARD.ttf
main 16:43:06,761 INFO Driver (<init>:21) - fonts/OCRAEXT.ttf
main 16:43:06,761 INFO Driver (<init>:21) - fonts/PURDUE.ttf
main 16:43:06,761 INFO Driver (<init>:21) - fonts/SCORECARD.ttf
times-italic
helvetica-bold
courier-boldoblique
ocraextended                  <--- mine
helvetica-boldoblique
helvetica
creditcard                    <--- mine
courier-bold
courier-oblique
zapfdingbats
scorecard                     <--- mine
times-roman
symbol
purdue                        <--- mine
helvetica-oblique
times-bold
courier
times-bolditalic
ocr a extended

now that it's registered I need to do something like this:

BaseFont myFont = BaseFont.createFont([what goes here?],
BaseFont.CP1250, true);
PdfTemplate logo = PdfTemplate.createTemplate(..some writer.., 115f,
72f);
logo.beginText();
logo.moveText(1, 20);
logo.setFontAndSize(pefcuFont, 14);
logo.setColorFill(PEFCU_LOGO_RED);
logo.showText("A");
logo.endText();

logo.beginText();
logo.moveText(1, 20);
logo.setFontAndSize(pefcuFont, 14);
logo.setColorFill(PEFCU_LOGO_GRAY);
logo.showText("B");
logo.endText();

help!

Jason
The PEN is now mightier than the PIN. Simply use your PEN
instead of your PIN and sign for your PEFCU Visa Check Card
purchases. Earn bonus points redeemable for gift and travel
awards. Combine PEFCU Visa check card and credit card points
for even more rewards.


***This is a transmission from Purdue Employees Federal Credit
Union (PEFCU) and is intended solely for its authorized
recipient(s), and may contain information that is confidential
and or legally privileged.  If you are not an addressee, or the
employee or agent responsible for delivering it to an addressee,
you are hereby notified that any use, dissemination,
distribution, publication or copying of the information
contained
in this email is strictly prohibited. If you have received this
transmission in error, please notify us by telephoning (765)
497-3328 or returning the email. You are then instructed to
delete the information from your computer.  Thank you for your
cooperation.***


------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-questions@...
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Re: embedding ttf fonts

by Paulo Soares-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

[what goes here?] = "creditcard"

Careful with the encoding, you're using cp1250 and if you really require
cp1252 the results will be different. Other option is to get BaseFont
directly and not use FontFactory. Failing all this please post the font, the
code and your expectations.

Paulo

----- Original Message -----
From: "Jason Berk" <jberk@...>
To: "Post all your questions about iText here"
<itext-questions@...>
Sent: Friday, June 26, 2009 10:28 PM
Subject: [iText-questions] embedding ttf fonts


Hey guys,

I've read the chapter on using fonts repeatedly and I'm still really
confused.

I have three TTF fonts that are custom (they contain logos).  Obviously,
I need to embed these into the PDF.  I also need to be able to get their
"BaseFont" so I can position them absolutely.

I seem to be registering my fonts correctly:

logger.info("registering required fonts:");
String[] fonts = new String[]{"CREDITCARD.ttf",
"OCRAEXT.ttf", "PURDUE.ttf", "SCORECARD.ttf"};
for(String font:fonts){
logger.info("fonts/" + font);
FontFactory.register("fonts/"+font);
}
for (Iterator i =
FontFactory.getRegisteredFonts().iterator(); i.hasNext(); ) {
            System.out.println((String) i.next());
        }

Gives me this:

main 16:43:06,714 INFO Driver (<init>:18) - registering required fonts:
main 16:43:06,714 INFO Driver (<init>:21) - fonts/CREDITCARD.ttf
main 16:43:06,761 INFO Driver (<init>:21) - fonts/OCRAEXT.ttf
main 16:43:06,761 INFO Driver (<init>:21) - fonts/PURDUE.ttf
main 16:43:06,761 INFO Driver (<init>:21) - fonts/SCORECARD.ttf
times-italic
helvetica-bold
courier-boldoblique
ocraextended                  <--- mine
helvetica-boldoblique
helvetica
creditcard                    <--- mine
courier-bold
courier-oblique
zapfdingbats
scorecard                     <--- mine
times-roman
symbol
purdue                        <--- mine
helvetica-oblique
times-bold
courier
times-bolditalic
ocr a extended

now that it's registered I need to do something like this:

BaseFont myFont = BaseFont.createFont([what goes here?],
BaseFont.CP1250, true);
PdfTemplate logo = PdfTemplate.createTemplate(..some writer.., 115f,
72f);
logo.beginText();
logo.moveText(1, 20);
logo.setFontAndSize(pefcuFont, 14);
logo.setColorFill(PEFCU_LOGO_RED);
logo.showText("A");
logo.endText();

logo.beginText();
logo.moveText(1, 20);
logo.setFontAndSize(pefcuFont, 14);
logo.setColorFill(PEFCU_LOGO_GRAY);
logo.showText("B");
logo.endText();

help!


------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-questions@...
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/