VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Pdf.Drawing Namespace / PdfGraphics Class
    Класс PdfGraphics
    В этом разделе
    Инкапсулирует поверхность чертежа PDF.
    Объектная модель
    AffineMatrix PdfDocument PdfTreeNodeBase PdfGraphics
    Синтаксис
    'Declaration
    
    Public NotInheritable Class PdfGraphics
    
    
    public sealed class PdfGraphics
    
    
    public __gc __sealed class PdfGraphics
    
    
    public ref class PdfGraphics sealed
    
    
    Ремарки

    Важно: Все координаты точек должны быть указаны в декартовых координатах (ось X идет слева направо, ось Y идет снизу вверх).

    Важно: Все операции являются векторными операциями, фоновое растровое изображение имеет разрешение 72 dpi.

    Пример

    Вот пример, показывающий, как рисовать графические примитивы на PDF странице:

    
    Public Shared Sub TestPDFGraphics(pdfFileName As String)
        ' create new PDF document
        Dim document As New Vintasoft.Imaging.Pdf.PdfDocument()
        ' add new page
        document.Pages.Add(New System.Drawing.SizeF(1000, 1000))
        ' get graphics object associated with page
        Using graphics As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = document.Pages(0).GetGraphics()
            ' draw primitives
            Dim pen As New Vintasoft.Imaging.Pdf.Drawing.PdfPen(System.Drawing.Color.Red)
            pen.Width = 3
            Dim brush As New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green)
            graphics.DrawLine(pen, 0, 0, 50, 150)
            graphics.DrawCurve(pen, 50, 150, 100, 200, 200, _
                20, 300, 150)
            pen.Color = System.Drawing.Color.Blue
            graphics.DrawEllipse(pen, 400, 400, 200, 300)
            graphics.FillEllipse(brush, 500, 500, 70, 150)
            brush.Color = System.Drawing.Color.FromArgb(127, System.Drawing.Color.Red)
            graphics.FillRectangle(brush, 450, 550, 300, 300)
            pen.Width = 10
            graphics.DrawRectangle(pen, 0, 0, 1000, 1000)
    
            ' draw vector string
            brush.Color = System.Drawing.Color.Green
            Dim font As Vintasoft.Imaging.Drawing.IDrawingFont = Vintasoft.Imaging.Drawing.DrawingFactory.[Default].CreateGenericSansSerifFont(30)
            graphics.DrawString("Vector string", font, brush, New System.Drawing.PointF(100, 500))
            Dim pdfFont As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
            ' draw text string
            graphics.DrawString("Text string", pdfFont, 30, brush, New System.Drawing.PointF(100, 600))
        End Using
    
        ' get graphics object associated with page
        Using graphics As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = document.Pages(0).GetGraphics()
            ' draw rendered page image (500x500 pixels) onto page
            Using img As Vintasoft.Imaging.VintasoftImage = document.Pages(0).Render(500, 500)
                graphics.DrawImage(img, New System.Drawing.RectangleF(600, 0, 300, 300))
            End Using
        End Using
    
        ' save document
        document.SaveChanges(pdfFileName)
    
        ' close document
        document.Dispose()
    End Sub
    
    
    
    public static void TestPDFGraphics(string pdfFileName)
    {
        // create new PDF document
        Vintasoft.Imaging.Pdf.PdfDocument document = 
            new Vintasoft.Imaging.Pdf.PdfDocument();
        // add new page
        document.Pages.Add(new System.Drawing.SizeF(1000, 1000));
        // get graphics object associated with page
        using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics graphics = document.Pages[0].GetGraphics())
        {
            // draw primitives
            Vintasoft.Imaging.Pdf.Drawing.PdfPen pen = 
                new Vintasoft.Imaging.Pdf.Drawing.PdfPen(System.Drawing.Color.Red);
            pen.Width = 3;
            Vintasoft.Imaging.Pdf.Drawing.PdfBrush brush = 
                new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green);
            graphics.DrawLine(pen, 0, 0, 50, 150);
            graphics.DrawCurve(pen, 50, 150, 100, 200, 200, 20, 300, 150);
            pen.Color = System.Drawing.Color.Blue;
            graphics.DrawEllipse(pen, 400, 400, 200, 300);
            graphics.FillEllipse(brush, 500, 500, 70, 150);
            brush.Color = System.Drawing.Color.FromArgb(127, System.Drawing.Color.Red);
            graphics.FillRectangle(brush, 450, 550, 300, 300);
            pen.Width = 10;
            graphics.DrawRectangle(pen, 0, 0, 1000, 1000);
    
            // draw vector string
            brush.Color = System.Drawing.Color.Green;
            Vintasoft.Imaging.Drawing.IDrawingFont font = Vintasoft.Imaging.Drawing.DrawingFactory.Default.CreateGenericSansSerifFont(30);
            graphics.DrawString("Vector string", font, brush, new System.Drawing.PointF(100, 500));
            Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont pdfFont = document.FontManager.GetStandardFont(
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
            // draw text string
            graphics.DrawString("Text string", pdfFont, 30, brush, new System.Drawing.PointF(100, 600));
        }
    
        // get graphics object associated with page
        using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics graphics = document.Pages[0].GetGraphics())
        {
            // draw rendered page image (500x500 pixels) onto page
            using (Vintasoft.Imaging.VintasoftImage img = document.Pages[0].Render(500, 500))
                graphics.DrawImage(img, new System.Drawing.RectangleF(600, 0, 300, 300));
        }
    
        // save document
        document.SaveChanges(pdfFileName);
    
        // close document
        document.Dispose();
    }
    
    

    Иерархия наследования

    System.Object
       Vintasoft.Imaging.Pdf.Drawing.PdfGraphics

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также