You can only use the font in the same document with PdfStamper.

Paulo

----- Original Message ----- 
From: <[EMAIL PROTECTED]>
To: <[email protected]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, June 01, 2006 8:46 PM
Subject: [iText-questions] drawing with embedded font


>I would think that if you had a pdf and you added a Text Field to it in 
>Acrobat
> then specified the font to use in this field as *not* one of the base 14 
> fonts,
> it would embed the entire font not a subset.  Also, I get that kerning
> information is not saved for text on a page as it is rendered as specific
> characters at specific positions but if the font were to be used in a form
> field, wouldn't the kerning information need to be included in the file 
> since
> the user could type anything into the field?  Here's the problem I'm 
> having.
> I've been able to extract the font used in the text field and (I think) 
> make a
> BaseFont using BaseFont.createFont(PRIndirectReference).  However, when I 
> try
> to use PdfContentByte.showText(String, BaseFont) I get a 
> NullPointerException.
> Here is some example code, can anyone give me any ideas on what I could be 
> doing
> wrong?  Thanks.
>
> PdfReader reader = null;
> try {
>  reader = new PdfReader(path to pdf file);
> }
> catch (IOException iox) { }
>
> PdfDictionary catalog = reader.getCatalog();
> PdfIndirectReference acroform =
> (PdfIndirectReference)catalog.get(PdfName.ACROFORM);
> PdfDictionary object = (PdfDictionary)PdfReader.getPdfObject(acroform);
> PdfDictionary resources = (PdfDictionary)object.get(PdfName.DR);
> PdfDictionary font = (PdfDictionary)resources.get(PdfName.FONT);
> Set keys = font.getKeys();
> Iterator iter = keys.iterator();
> PdfName name = (PdfName)iter.next();
> BaseFont docfont = 
> BaseFont.createFont((PRIndirectReference)font.get(name));
>
> com.lowagie.text.Rectangle pageSize = new com.lowagie.text.Rectangle(100, 
> 100);
> com.lowagie.text.Document document = new 
> com.lowagie.text.Document(pageSize);
>
> try {
>  FileOutputStream fileOutputStream = null;
>  fileOutputStream = new FileOutputStream(new File("c:\\documents and
> settings\\danielb\\desktop\\temp.pdf"));
>
>  PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);
>  document.open();
>
>  PdfContentByte cb = writer.getDirectContent();
>  cb.beginText();
>  cb.setFontAndSize(docfont, 12);
>  cb.showText("test");
>  cb.endText();
>
>  document.close();
> }
>
>
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions 



_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to