Draw text string to a PDF page
Posted: Wed Dec 22, 2010 5:02 pm
There can be a situation where is needed to draw a text string directly onto a PDF page and save it then to a stream.
Below is an example concept how this can be done:
Below is an example concept how this can be done:
Code: Select all
private void AddTextString(Stream stream)
{
PdfDocument document = PdfDocumentController.OpenDocument(stream);
using (PdfGraphics g = PdfGraphics.FromPage(document.Pages[0]))
{
PdfFont font = PdfFont.CreateStandardFont(document, StandardFontType.TimesRoman);
PdfBrush brush = new PdfBrush(Color.Black);
// point coordinates should be specified in cartesian
// coordinates (X axis goes from left to right, Y axis goes from bottom to top)
g.DrawString("Test", font, 20, brush, new PointF(10, 20));
}
document.SaveChanges();
PdfDocumentController.CloseDocument(document);
}
...
AddTextString(stream);
imageViewer1.Add(stream);
...