VintaSoft PDF .NET Plug-in Discussions

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

Board index < VintaSoft Imaging < VintaSoft PDF .NET Plug-in Discussions

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

Draw text string to a PDF page



Draw text string to a PDF page

Post by Yuri »

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


Page 1 from 1: 1