Draw text string to a PDF page

Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.

Moderator: Alex

Post Reply
Yuri
Posts: 56
Joined: Wed Jul 23, 2008 2:47 pm

Draw text string to a PDF page

Post by Yuri » 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:

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);
...

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests