VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.Pdf.Drawing Namespace / PdfGraphics Class / DrawImage Method / DrawImage(PdfImageResource) Method
Vintasoft.Imaging.Pdf.Tree.PdfImageResource to draw.
Example



In This Topic
    DrawImage(PdfImageResource) Method
    In This Topic
    Draws the specified Vintasoft.Imaging.Pdf.Tree.PdfImageResource at the current location.
    Syntax
    'Declaration
     
    Public Overloads Sub DrawImage( _
       ByVal imageResource As PdfImageResource _
    ) 
    public void DrawImage( 
       PdfImageResource imageResource
    )
    public: void DrawImage( 
       PdfImageResource* imageResource
    ) 
    public:
    void DrawImage( 
       PdfImageResource^ imageResource
    ) 

    Parameters

    imageResource
    Vintasoft.Imaging.Pdf.Tree.PdfImageResource to draw.
    Example
    This example 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: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also