Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, July 3, 2008 11:05 AM
New to iTextSharp, having trouble getting a specific, non standard system font to print. I'm writing a web app to generate a PDF file for check printing for our office. I can access my MICR font and write out in the font using this code.
iTextSharp.text.Font micrfont = iTextSharp.text.FontFactory.GetFont("c:\\windows\\fonts\\MCR_____.TTF", 18);
document.Add(new iTextSharp.text.Paragraph(new iTextSharp.text.Chunk("123456789 ", micrfont)));
The problem I face, though, is the lack of positioning options when using the "chunk". What I am trying to do is use the ContentByte to write out to a specific X,Y coordinate on the page...like this.
PdfContentByte cb = writer.DirectContent;
cb.BeginText();
BaseFont mybf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetFontAndSize(mybf, 12);
cb.SetTextMatrix(100, 100);
cb.ShowText("123456789");
So my question is does anyone know how I can set the mybf BaseFont in line 3 of the above code snippet to equal the MICR font from line 1 of the first code snippet?
Thanks in advance.
All replies (1)
Thursday, July 3, 2008 11:17 AM âś…Answered
Got it, this does the ticket.
BaseFont bMicr = BaseFont.CreateFont("c:\\windows\\fonts\\MCR_____.TTF", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(bMicr, 12);
cb.SetFontAndSize(bMicr, 8);
cb.SetTextMatrix(1, 670);
cb.ShowText("123456789");