The simplest way to do it is to use PdfContentByte.setTextMatrix(). Measure the
width and height (height is possibly the leading) of the text and adapt the
matrix to fit it exactly to the rectangle.
Paulo
> -----Original Message-----
> From: Suheb Ahmad [mailto:khan.su...@gmail.com]
> Sent: Friday, October 09, 2009 12:02 PM
> To: itext-questions@lists.sourceforge.net
> Subject: [iText-questions] Text Scaling in ItextSharp
>
>
> Dear All,
>
> I have some images which were converted into xml files and
> searchable PDF
> files using some OCR engine. But latter on I found that there are some
> spelling mistakes and a few words are missing in the xml file
> and also in
> searchable PDF file.
>
> The PDF file is a searchable PDF (text behind image) file and
> the xml file
> contains all the details of the OCR having the information
> about the region
> coordinate, text, font details and color information.
>
> I am using ItextSharp to create a pdf using the image and xml
> file. I have
> done it but there is a problem with text.
>
> The text added in pdf using chunk does not fit in the
> rectangle some words
> displayed incorrectly like 'Times' is written as 'sTime'. I have tried
> chunk.HorizontalScaling(0.72f) but it resize the text and
> rectangle also so
> problem remain same.
>
> I am using following code:
>
> PdfContentByte cb = writer.DirectContentUnder;
> ColumnText ct = new ColumnText(cb);
>
> FontFactory.RegisterDirectory(@"C:\WINDOWS\fonts");
> FontFactory.RegisterDirectory(@"C:\WINDOWS\fonts\Arial.ttf");
> FontFactory.RegisterDirectory(@"C:\WINDOWS\fonts\Times New
> Roman.ttf");
>
> chunk = new Chunk("New Zealand Trained Nurses' Association",
> FontFactory.GetFont("Times New Roman", "Cp1252",
> BaseFont.EMBEDDED, 20, 0,
> iTextSharp.text.Color.RED));
> chunk.HorizontalScaling(0.72f);
> chunk.SetTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL, 0,
> iTextSharp.text.Color.MAGENTA);
> rect = new iTextSharp.text.Rectangle(184, 1063, 376, 1063);
> ct.SetSimpleColumn(rect.Left, rect.Bottom, rect.Right,
> rect.Top, 0, 0);
> ct.AddText(chunk);
> ct.Go();
>
>
> How can i use the scaling in the text so that text can be fitted in
> rectangle without changing the font size?
>
> Thanks & Regards
> Suheb Ahmad
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
informação confidencial ou legalmente protegida. A incorrecta transmissão desta
mensagem não significa a perca de confidencialidade. Se esta mensagem for
recebida por engano, por favor envie-a de volta para o remetente e apague-a do
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de
usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain
confidential or legally protected information. The incorrect transmission of
this message does not mean the loss of its confidentiality. If this message is
received by mistake, please send it back to the sender and delete it from your
system immediately. It is forbidden to any person who is not the intended
receiver to use, distribute or copy any part of this message.
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/