VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Pdf.Drawing Namespace / PdfGraphics Class / DrawImage Methods / DrawImage(PdfImageResource) Method
Синтаксис Example Требования Смотрите также
В этом разделе
    DrawImage(PdfImageResource) Метод (PdfGraphics)
    В этом разделе
    Рисует указанный PdfImageResource в текущем местоположении.
    Синтаксис
    Пример

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

    
    ''' <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();
        }
    }
    
    
    

    Требования

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

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