VintaSoft Imaging .NET SDK 14.0: Documentation for .NET developer
Vintasoft.Imaging.Pdf.Drawing Namespace / PdfGraphics Class / DrawImage Methods / DrawImage(PdfImageResource) Method
Syntax Example Requirements SeeAlso
In This Topic
    DrawImage(PdfImageResource) Method (PdfGraphics)
    In This Topic
    Draws the specified PdfImageResource at the current location.
    Syntax
    Example

    Here is an example that shows how to draw a new image on a PDF page:

    
    ''' <summary>
    ''' Draws an image on PDF page.
    ''' </summary>
    ''' <param name="pdfFilename">The filename of PDF document.</param>
    ''' <param name="imageFilename">The filename of image.</param>
    Public Shared Sub DrawImageOnPdfPage(pdfFilename As String, imageFilename As String)
        ' open PDF document
        Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
            ' open image
            Using image As New Vintasoft.Imaging.VintasoftImage(imageFilename)
                ' get the first page
                Dim page As Vintasoft.Imaging.Pdf.Tree.PdfPage = document.Pages(0)
                ' get PDF graphics of PDF page
                Using graphics As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = page.GetGraphics()
                    ' create image-resource based on image
                    Dim imageResource As New Vintasoft.Imaging.Pdf.Tree.PdfImageResource(document, image, Vintasoft.Imaging.Pdf.PdfCompression.Auto)
    
                    ' draw image-resource on PDF page
                    graphics.DrawImage(imageResource, New System.Drawing.RectangleF(100, 100, 200, 300))
                End Using
            End Using
    
            ' save changes to a file
            document.SaveChanges()
        End Using
    End Sub
    
    
    
    
    /// <summary>
    /// Draws an image on PDF page.
    /// </summary>
    /// <param name="pdfFilename">The filename of PDF document.</param>
    /// <param name="imageFilename">The filename of image.</param>
    public static void DrawImageOnPdfPage(string pdfFilename, string imageFilename)
    {
        // open PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = 
            new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
        {
            // open image
            using (Vintasoft.Imaging.VintasoftImage image = 
                new Vintasoft.Imaging.VintasoftImage(imageFilename))
            {
                // get the first page
                Vintasoft.Imaging.Pdf.Tree.PdfPage page = document.Pages[0];
                // get PDF graphics of PDF page
                using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics graphics = page.GetGraphics())
                {
                    // create image-resource based on image
                    Vintasoft.Imaging.Pdf.Tree.PdfImageResource imageResource = 
                        new Vintasoft.Imaging.Pdf.Tree.PdfImageResource(
                            document, image, Vintasoft.Imaging.Pdf.PdfCompression.Auto);
    
                    // draw image-resource on PDF page
                    graphics.DrawImage(imageResource, new System.Drawing.RectangleF(100, 100, 200, 300));
                }
            }
    
            // save changes to a file
            document.SaveChanges();
        }
    }
    
    
    

    Requirements

    Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also